tags:

views:

56

answers:

4

Essentially I have been trying to think of a PHP-based solution to do the following:

The player needs a link ie:

"http://yourdomain.com/xspf_player.swf?playlist_url=http://yourdomain.com/yourplaylistlist.xspf">

I could easily put the XSPF information in a PHP file and replace the artist name / song name with variables that retrieve the data from the database. The thing I can't wrap my head around is how I'm going to feed it to the player and make it a link if it needs to be .xspf format...

Any ideas other ideas?

I've only thought of making a txt file every time it to play a song... But then that brings the problem that if there's a lot of users using it there would be so much unnecessary writing to the hard drive.

The XSPF format is something like this: http://xspf.org/quickstart/

I hope I have explained this well, if there's anything else you would like me to explain please let me know.

In short, even disregarding the fact that I'm using a database is:

How could I get information from variables into the player if it needs a link to an .xspf file in order to work?

A: 

You can create an .xspf file with whatever format its done with, save it in a directory reachable by the webserver and use the link to that page to feed the player.

kemp
+2  A: 

If I understand you correctly, all you need to do is set the content type of the PHP file to be something else.

<?php
header("Content-type: application/xspf+xml");
// (this second header line may not be needed):
header('Content-Disposition: attachment; filename="foo.xspf"'); 

echo $xspf_file_contents;
?>

Then you can create the PHP file in whatever way you want. It won't (shouldn't) matter to the player that the extension is "php" instead of "xspf".

konforce
A: 

The thing is XSPF player only correctly parses files that have a certain format. If that format is in a text file with extension .xspf or it's a php file with extension .php does not matter.

What ultimately matters is whether the request to the server gives a response in a certain format.

Check out http://www.trbailey.net/xspf/ for an example.

Niels Bom
+1  A: 
  • Make a PHP script that outputs proper XSPF. Validate the output.
  • try pointing the player to the PHP script (http://yourdomain.com/xspf_player.swf?playlist_url=http://yourdomain.com/yourscript.php)
  • if this works, you're done
  • if it doesn't, capture the output to a file, rename to *.xspf and feed to the player again
  • if this time it works rename the PHP script to .xspf and force the server to interpret it as PHP:

(configuration for Apache - put it in the .htaccess file)

<FilesMatch "^myscript\.xspf$">
    SetHandler application/x-httpd-php5
</FilesMatch>

Depending on your server, you may have to change x-httpd-php5 to x-httpd-php

djn
This was a really good alternate answer, thanks!
Tek