Jump to content

Recommended Posts

I am trying to get an idea of what I will need to do to accomplish a streaming music player. It looks like the only way to really hide the source mp3 (I know people can find workarounds, but at least so they can't just view the source and see it) is to use a flash player.

 

What I would like to do is have a streaming music player that randomly selects mp3 files on my server and also allows the user to skip ahead to the next song. All of this would have to be done without reloading the page. It seems like I will need to have php code to interact with my database to figure out which song to play, some javascript to update the player and the flash player itself. I don't understand how you would get the next song to play, since you would need to query a database on the server with a new file name (I would guess). Maybe I would need to use Ajax to do it? I'm just not exactly sure how to get all of these components working together. A good example of what I'm trying to accomplish is the site last.fm. I'm hoping someone can maybe point me in the right direction.

 

The key for me is to be able to hide the source mp3 file (as best I can). If that can be done without flash, that would be even better.

one way to do so, is to create a somewhat ticket like system.. and how you expect to PLAY these mp3s without flash is beyond me (unless you plan to use bgsound but thats quite lame) here is a basic interface you'd be wanting to create:

 

step 1.

request song list

 

step 2.

send song list back to the mp3 player (or interface you create to work without flash)

 

step 3.

when a user chooses to PLAY a song, request a KEY from generateKey.php or whatever. in generateKey.php give a random key and store the key inside a session var for this user. like this:

<?php
// generate $random key
session_start();
$_SESSION[$random] = "path/to/the/mp3/file";
?>

 

step 4.

THEN send the key back to play.php and inside play.php return the CONTENT of the song:

<?php
  session_start();
  if (isset($_SESSION[$_GET['key']])) {
    $file = $_SESSION[$_GET['key']];
    header("Content-Length: ".filesize($file));
    header("Content-Type: audio/mpeg");
    readfile($file);
    unset($_SESSION[$_GE['key']]);
  }
?>

 

step 5.

use the content returned to play the file..

 

 

following the above 5 steps will only show the user play.php generateKey.php and a key which will never be used more than once.. everything else is masked from the end user :)

Thank you for your help, I really appreciate it. I think I understand most of the process. About the last step, it seems like this code would give the user a prompt to save the mp3 file. This might be more of a flash forums question, but I was wondering if you knew how would you use this to interact with a flv file instead of it popping up a save file box?

the last step is to be used in the flash file.. or bgsound tag lol you could PROBABLY do all of this with AJAX and (googled, although coulda figured it out :))

 

<OBJECT ID="Player" height="0" width="0" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"> <PARAM name="autoStart" value="True"> <PARAM name="URL" value="play.php?key={THE KEY}"> </OBJECT> 

I have been trying to get this code to work using php and a flash player as you suggested. I have a flash player that accepts files like this:

 

<object> ....(flash stuff)....
<embed src="player.swf?file=1000.mp3">
</embed>
</object>

 

This block of code works just fine, but the main problem is I need to hide the file itself, so the user cannot view the source and see 1000.mp3. I tried this:

 

<object> ....(flash stuff)....
<embed src="player.swf?file=getfile.php?id=1000">
</embed>
</object>

 

But this does not seem to work. In getfile.php I have tried the header functions for mp3, then readfile(1000.mp3), but it is not working the same as the first block of code.

 

For example, in the getfile.php, I have tried:

 

  header("Content-Length: ".filesize($file));
    header("Content-Type: audio/mpeg");
    readfile($file);

and

 $filesize = filesize($file);
    header("Expires: Thu, 01 Jan 1970 00:00:00 GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    header("Pragma: public");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: {$filesize}");
    header("Content-Disposition: inline; filename=\"{$file}\";");

    // MP3 header
    header("Content-Type: audio/mpeg");

    @readfile($file); 

 

Any suggestions/help would be appreciated!

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.