SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Problem Streaming MP3 with PHP

    Hi guys,

    I have a script called "play.php" that i use to stream mp3 files to our Flash Media Player. It's basically to hide our file location.

    So in the embed tag it will be
    Code:
    flashvars="file=play.php?id=2" rather than 
    flashvars="file=mysongfile.mp3"
    However i have problem with my play.php. Basically when it's still streaming the file somehow the script freezes, i can't click any other links within the page (say i dont like the song and i wanna go to a different page), even clicking the BACK button on the browser is not working. It just waits until the streaming finished then it will go to the next/previous page as soon as the streaming finished (i hope this makes sense)

    I have tried to access the file directly, flashvar="file=mysongfile.mp3", and there's no problem at all, I can click any link in the middle of streaming/downloading the file and it will jump to the next page straight away. Only if i use the play.php file somehow it blocks the page.

    Here's the play.php file:

    Code:
    $file_name = getFileName($_GET["id"]);
    
    header('Content-Type: audio/mpeg');
    header("Content-Transfer-Encoding: binary");
    header('Content-Length: '.filesize($filepath));
    
    $filepath ='/pathto/'.$file_name;
    
    if ($stream = fopen($filepath, 'rb')){
       while(!feof($stream) && connection_status() == 0){
             //reset time limit for big files
             set_time_limit(0);
             print(fread($stream,1024*8));
             flush();
       }
       fclose($stream);
    }
    I have tried using fpassthru as well, but same problem.

    Any help would be appreciated.

  2. #2
    SitePoint Addict dbr's Avatar
    Join Date
    Aug 2006
    Location
    Tucked away in the mountains...
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use .m3u files to play my mp3's http://en.wikipedia.org/wiki/M3U

    I've not done anything with flash, so I don't know how this would work flashvar="file=mysongfile.mp3 replaced with this flashvar="file=mysongfile.m3u

    It might be worth exploring though. I found the m3u files very easy to set up.

    good luck!
    "Three components make an entrepreneur:
    the person, the idea, and the resources to make it happen."
    Anita Roddick ~British entrepreneur
    dbr founder of: ProximityCast.com

  3. #3
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    with m3u then people can still see the file location by opening the m3u file.

  4. #4
    SitePoint Addict dbr's Avatar
    Join Date
    Aug 2006
    Location
    Tucked away in the mountains...
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Understood, Why can't you also:
    flashvars="file=play.php?id=2" rather than
    flashvars="file=mysongfile.m3u"
    "Three components make an entrepreneur:
    the person, the idea, and the resources to make it happen."
    Anita Roddick ~British entrepreneur
    dbr founder of: ProximityCast.com

  5. #5
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that "play.php" file is the whole problem that i've got

    the file is locking the page when it's streaming a file

  6. #6
    Community Advisor silver trophy

    Join Date
    Nov 2006
    Location
    UK
    Posts
    2,559
    Mentioned
    40 Post(s)
    Tagged
    1 Thread(s)
    What happens when you call the php script directly?

    You've sent a header with
    header('Content-Length: '.filesize($filepath));
    but haven't defined $filepath until the next line.

    In the swf, what is your loadSound string?

  7. #7
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi EastCost,

    Ive put the $filepath above it, still doing the same thing...

    When i call the php script directly, it just plays the mp3 using whatever the browser's plugin, in my case it's QuickTime.

    Im using a third party flash player, so i dont know the loadSound setting. Will it be something that might cause the problem?

  8. #8
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want to have a look here:

    http://us.php.net/manual/en/function.header.php#47948

    All the headers for loading an MP3 file, although that's for a force-download..
    - the lid is off the maple syrup again!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •