Recent

Author Topic: Playing an xspf file  (Read 535 times)

BLL

  • Sr. Member
  • ****
  • Posts: 276
Playing an xspf file
« on: November 10, 2019, 03:03:56 pm »
Hi,
I want to play an xspf file from within my program. I am using a RasPi 3 and double-clicking on the file in filemanager opens it in VLC.

How can I do this please?

My experiments so far have simply opened the (text) file, rather than playing it!

Thanks

Brian
« Last Edit: November 10, 2019, 03:07:23 pm by BLL »

Pixy

  • New Member
  • *
  • Posts: 47
Re: Playing an xspf file
« Reply #1 on: November 10, 2019, 04:05:21 pm »
You could use a library if one exists for that purpose. For example, there is Lizzy for java http://lizzy.sourceforge.net/ which supports the XSPF format. You could take a look at the source code and see how this format should be handled or even convert the code for lazarus. Here is one for C++ http://libspiff.sourceforge.net/ .

Edit: From what I read XSPF is basically an XML http://www.xspf.org/xspf-v1.html . You could load that text that you see in a stringlist and then use regular expressions to copy the songs' locations, put them in a list and play them.
« Last Edit: November 10, 2019, 04:15:13 pm by Pixy »

lucamar

  • Hero Member
  • *****
  • Posts: 2122
Re: Playing an xspf file
« Reply #2 on: November 10, 2019, 04:29:53 pm »
Or, if you're content with letting the system open the file with whatever is the preferred player (as the file manager does), you can use the function OpenDocument() (in unit LCLIntf).
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: Playing an xspf file
« Reply #3 on: November 10, 2019, 07:10:41 pm »
Hi all
I am very new to this streaming lark and am not sure how best to proceed. I have found an apparently better method of getting music via streaming:
media-ice.musicradio.com/ClassicFMMP3.m3u

Thisdownloads this m3u file and dbl-clicking it opens VLC and plays the file. What I don't understand is how to do this from within my program. Will this OpenCommand do it and if so, how does one do it please?

I am lost at the moment!

Brian

lucamar

  • Hero Member
  • *****
  • Posts: 2122
Re: Playing an xspf file
« Reply #4 on: November 10, 2019, 08:11:49 pm »
To do the same as double-clicking in the file manager, just use OpenDocument; for example like this:

Code: Pascal  [Select]
  1. { Remember to add LCLIntf to your uses clause!
  2. Then, when you want to open the file, just do: }
  3. if not OpenDocument('somepath/somefile.m3u') then
  4.   ShowMessage('problems opening somefile.m3u');

Assuming the file is there that will try to launch whatever application is configured to open such files passing to it the file name you gave it. The actual code used depends, of course, on the target OS but the function call itself is cross-platform.

Note that if you pass to it an URL it¡ll probably try to open a browser, so you should download the playlist normally and then call OpenDocument() with its local file name.
« Last Edit: November 10, 2019, 08:14:36 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: Playing an xspf file
« Reply #5 on: November 10, 2019, 08:45:01 pm »
Hi
Thanks for the help.
I am getting somewhere, but not as far as I want!
I am managing to download the .m3u file, but OpenDocument is failing.

If I double-click on the .m3u file, it opens in VLC and plays. If I then shut VLC, OpenDocument then works and plays the file!
Here is the code I have so far:
Code: Pascal  [Select]
  1. procedure TMainForm.PlayMusic;
  2. var
  3.   info, info1: String;
  4. begin
  5.  info := 'sudo -u pi chromium-browser --start-maximized media-ice.musicradio.com/ClassicFMMP3.m3u';
  6.  runcommand('/bin/sh', ['-c', info], info1);
  7.  OpenDocument('/home/pi/Downloads/ClassicFMMP3.m3u');
  8. end;  
  9.  

Now, I am lost!

Brian

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: Playing an xspf file
« Reply #6 on: November 10, 2019, 08:56:22 pm »
More progress - removed the -c and it works!

Now, a question: The VLC window now opens over my program window. Can I get it to start minimised and if so, how please?

Brian

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: Playing an xspf file
« Reply #7 on: November 10, 2019, 10:06:52 pm »
More progress but still  not working properly!
If I use this to start vlc minimized:
info := 'cvlc /home/pi/Downloads/ClassicFMMP3.m3u';
 runcommand('/bin/sh', ['-c', info], info1);   

Without the -c, it doesn't start vlc and with it, it stalls my program until I exit vlc!

How can I get it to start vlc minimized and Not stall my program?

God, I'm fed up with this hassle!!

Brian

lucamar

  • Hero Member
  • *****
  • Posts: 2122
Re: Playing an xspf file
« Reply #8 on: November 11, 2019, 08:05:45 am »
If you need more control you'll have to use a TProcess to launch VLC. Something like this very basic example:

Code: Pascal  [Select]
  1. {Assumes you added a TProcess component to your form}
  2. procedure TForm1.PlayList(AListname: String);
  3. var
  4.   Status: Integer;
  5. begin
  6.   Process.Executable := FindDefaultExecutablePath('cvlc');
  7.   Process.Options := [poNoConsole]; {For Windows}
  8.   Process.Parameters.Clear; {To be on the sure side}
  9.   Process.Parameters.Add(AListname);
  10.   if Process.Running then
  11.     Process.Terminate(Status);
  12.   Process.Execute;
  13. end;

You can find more info on the wiki-page: Executing External Programs
« Last Edit: November 11, 2019, 08:08:23 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: Playing an xspf file
« Reply #9 on: November 11, 2019, 11:13:54 am »
Hi
Thanks again - it now works fine.

One thing I wonder about: the.m3u file, at the moment, I download it every time. Is this necessary as long as a file of that name is already there?

Brian

lucamar

  • Hero Member
  • *****
  • Posts: 2122
Re: Playing an xspf file
« Reply #10 on: November 11, 2019, 01:56:02 pm »
Not; as long as the file is valid (i.e. the URLs inside it don't change) you don't need to download it every time.

Of course, if the file changes in the server you should download it again.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: Playing an xspf file
« Reply #11 on: November 12, 2019, 11:59:05 am »
Hi Lucamar

Thanks for that and all your help.

I've learned a lot.

Brian

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: Playing an xspf file
« Reply #12 on: November 14, 2019, 05:59:15 pm »
Hi
I  now have another request for help with TProcess, which I still find confusing.

I need to issue a command from within lazarus, which at the console is sudo ./gps

How can I do that with TProcess please? It keeps saying it can't fi nd the executable 'sudo'!

Thanks again

Brian

lucamar

  • Hero Member
  • *****
  • Posts: 2122
Re: Playing an xspf file
« Reply #13 on: November 14, 2019, 06:12:31 pm »
TProcess doesn't search in PATH but rather expects a fully-qualified name for the executable. To search for it use FindDefaultExecutablePath(), as in:
Code: Pascal  [Select]
  1.   Process.Executable := FindDefaultExecutablePath('sudo');
  2.   if Process.Executable = '' then
  3.     ShowMessage('Can''t find "sudo"')
  4.   else begin
  5.     {Rest of Process-related code}
  6.   end;

Note that by default sudo has to run in a console to get the password but you can avoid that by calling it with either -A or -S parameter, depending on how you want to pass it (man sudo for more info).
« Last Edit: November 14, 2019, 06:21:58 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.2/2.0.4  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.