The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 13 of 13

Thread: Stop MP3 from Cache'ing streaming sound using loadsound

  1. #1

    Stop MP3 from Cache'ing streaming sound using loadsound

    hello,

    I created a streaming mp3 player, the Click here for player

    I have used the loadsound command with the streaming option set to true, so it streams sound etc. But the problem is that it cache's the mp3 file it is streaming onto the user's internet cache folder.

    Is there a way to prevent mp3 files from being cached (have I murdered the English language today using the word cache? ) Something like what the Real Player does, it streams the files but never cache's them. <gasp>

    Slan,
    Abhay

  2. #2
    flash always caches the loaded mp3 and swf files.. but you can try to import the mp3 files in a swf files. and load them as an mp3 file.

  3. #3
    Quote Originally Posted by e.s.x.s
    flash always caches the loaded mp3 and swf files.. but you can try to import the mp3 files in a swf files. and load them as an mp3 file.
    Sorry, but am a bit confused here.

    You mean I should make a separate fla, import the mp3 and then export the swf file. Now in my main player file I should import the swf and then stream it?


    Ummm.. is that right? How would it be done?

    Slan,
    Gopaldass

  4. #4
    yes u r right gopaldass, u should make a swf with the way you understood and load this file (dynamically) into your main player swf.u can use loadMovieNum or loadMovie..

  5. #5
    another trick, although the files are still cached, is to change the file extension to something like .txt flash will still read the files fine but windows will give an error when trying to open the file without changing the extension back. Doesn't work so well for OS's that actually check file headers, but it does offer at least one layer of protection.
    A while back I tried using this trick, storing the mp3 is a folder different from the folder the movie was in, then using php to generate a random name, after that it would copy the mp3 from the other folder and give it that name, flash would play the file, then when finished call another php script that would create a blank text file with the same random name, then load the file into flash, thus overwriting the cached file. My only problem was some lag in the proccess and if the user left the site before the file finished playing.

  6. #6
    Quote Originally Posted by e.s.x.s
    yes u r right gopaldass, u should make a swf with the way you understood and load this file (dynamically) into your main player swf.u can use loadMovieNum or loadMovie..
    Please correct me if i am wrong...
    Now the user has swf file instead of mp3 in the temporary internet folder, but still user can save swf from the temp folder and play it without visiting the site. Is it not it defeats the purpose?

  7. #7
    ys u r right a3shafan! but you can change the swf extension to what you want.

  8. #8
    If you can use PHP on your server then you can prevent MP3 files streamed through Flash from caching on the users HD.

    Here's an example of how to use it...


    Code:
    var noCache:Sound = new Sound(); 
    noCache.loadSound("stream.php?file=my_music.mp3", true);

    ...and here's the actual PHP file...


    PHP Code:
    <?php 
    ob_start
    ();
    header("Expires: Mon, 20 Dec 1977 00:00:00 GMT");
    header("Last-Modified: " gmdate("D, d M Y H:i:s") . " 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("Content-Type: audio/mpeg");
    @
    readfile($_GET["file"]);
    ob_end_flush();
    ?>

    Hope that helps

  9. #9
    Hi Guys,

    I am developing a system that uses mp3 snippets, and I also need to ensure that the mp3s always load fresh (i.e. not from cache). I decided to give Nutrox's solution a go, and it worked perfectly! That is, until version 9,0,124,0 of flash came out - since then my movie only works in firefox/chrome and not safari/ie6/ie7 and I wondered if anyone has any ideas about how the code might be altered to get it to work. One clue I have found that *might* be useful is that since loading sounds in this way, I cannot getBytesTotal() or getBytesLoaded() -- I think this might be because they are measuring the php file and not the mp3 files themselves.

    Thanks!!

  10. #10
    mySound.loadSound("http://my.domain.com/myMP3.mp3?" + random(9999999999), true);

    This adds a random number to the end of your URL as a GET variable, which tricks your browser into downloading a fresh version of your file every time. I've seen this done with the Date() object as well.

  11. #11
    Quote Originally Posted by Nutrox View Post
    If you can use PHP on your server then you can prevent MP3 files streamed through Flash from caching on the users HD.

    Here's an example of how to use it...


    Code:
    var noCache:Sound = new Sound(); 
    noCache.loadSound("stream.php?file=my_music.mp3", true);

    ...and here's the actual PHP file...


    PHP Code:
    <?php 
    ob_start
    ();
    header("Expires: Mon, 20 Dec 1977 00:00:00 GMT");
    header("Last-Modified: " gmdate("D, d M Y H:i:s") . " 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("Content-Type: audio/mpeg");
    @
    readfile($_GET["file"]);
    ob_end_flush();
    ?>

    Hope that helps
    Hi,

    This has really helped me over the past couple of years but now I have come across a server which does not support .PHP files and only supports .aspx files. I really need to make sure that my mp3s and XMLs are not storing into the users temp folders so any help on how to convert this code to .aspx or another solution would be greatly appreciated.

    Many Thanks

  12. #12

    Cross Browser???

    Quote Originally Posted by fireflier View Post
    Hi Guys,

    I am developing a system that uses mp3 snippets, and I also need to ensure that the mp3s always load fresh (i.e. not from cache). I decided to give Nutrox's solution a go, and it worked perfectly! That is, until version 9,0,124,0 of flash came out - since then my movie only works in firefox/chrome and not safari/ie6/ie7 and I wondered if anyone has any ideas about how the code might be altered to get it to work. One clue I have found that *might* be useful is that since loading sounds in this way, I cannot getBytesTotal() or getBytesLoaded() -- I think this might be because they are measuring the php file and not the mp3 files themselves.

    Thanks!!
    I'd love to see an update on this. Has anyone found a way to get this working on all browser again?
    Thanks in advance!

    Yours,
    Andra

  13. #13
    BadaBUMP!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012