14 Replies Latest reply on Jun 6, 2006 6:42 AM by kglad

    Stop dynamic MP3 Streaming

    clyde236
      I've been all over the Net looking for an answer to this one.

      How does one stop a dynamic MP3 from streaming, other than waiting for the complete download?

      I have an MP3 player I am making that should allow users to click on a song, and if they want, skip to a new song.

      It works fine on the desktop and at high speed connections (DSL/Cable) but when simulated at 56K mode, it gets into buffering problems because when the user skips to the new song, the previous one is still streaming, there's no way to stop it. Worse, if the user skips back to the original song, it streams on top of itself! I can watch this taking place in the Test Movie area, so I understand what is happening, just don't know how to prevent it.

      I can't find a way to stop song one from streaming when the user wants to skip to song 2.and vice versa.

      There are several tutorials that suggest using delete sound object and unload movieclip and other things that do not work.

      The only way I found to successfully stop a dynamic MP3 from streaming was to use the this.unloadMovie(). But that removes the entire movie from the stage! Attempting to unload a movie with a soundclip from a different level doesn't stop the streaming.

      Is this an impossible task?

      There are enough requests for a solution, I would think Macromedia would address the problem. There are still a LOT of folks on the Net using 56K modems, and it would be nice to meet their needs, instead of having to restrict a FLASH MP3 player to dsl and broadband users.

      Does anyone have any ideas that actually work?

      Thanks!
        • 1. Re: Stop dynamic MP3 Streaming
          codescodescodes Level 1
          are the songs being loaded dynamically or are they set on the timeline? If they are loaded dynamically, then you can use the Sound.stop() method to stop the streaming sound from playing. If they are set on the timeline, then you can put them into an empty movieclip and unload that empty movie clip when you want to stop the sound. That's the best advice I can give you right now without looking at your fla and seeing how you set everything up.
          • 2. Re: Stop dynamic MP3 Streaming
            kglad Adobe Community Professional & MVP
            i believe you can stop the download by removing the movieclip that contains the sound object. instead of using this.unloadMovie() where this refers to your _level0 movie use:

            • 3. Re: Stop dynamic MP3 Streaming
              kglad Adobe Community Professional & MVP
              p.s. don't test this in the flash test environment. upload the files and check your browser's cache to determine if the downloading has continued to completion.
              • 4. Re: Stop dynamic MP3 Streaming
                Level 7
                "kglad" <webforumsuser@macromedia.com> wrote in message news:e5us8t$9o0$1@forums.macromedia.com...
                > p.s. don't test this in the flash test environment. upload the files and check your browser's cache to determine if the
                > downloading has continued to completion.

                kglad.. streaming mp3s don't go into the cache. (at least not on my XP system)
                tralfaz


                • 5. Re: Stop dynamic MP3 Streaming
                  clyde236 Level 1
                  Here's an idea,

                  Is there any way to dynamically load a streaming MP3 (that is an external MP3, not in the library) to a level other than level0?

                  In my testing of various solutions (which didn't work, but thanks for trying), it appears that FLASH streams into level0 no matter what, unless there is a code to over ride some default.

                  Here's what happened:

                  I tried creating an swf that streamed an MP3 when it starts (i.e. no buttons or anything.). It worked fine by itself, but of course, only closing the file would stop the streaming. I called this movie: sound.swf

                  I then created a loader movie, called PLAY.fla to bring the sound.swf into level1.

                  I made a START button at the root level of PLAY and configured it to perform a loadMovie("sound.swf",1) when pressed, which told Flash to bring the sound.swf into level 1 of the PLAY.fla. So now there are two movies on stage on different levels, PLAY (with it's buttons) in level0 and sound.swf in level1.

                  Then I created a STOP button and set it to perform and unloadMovie(1) on press. As I understand it, this would delete the sound.swf because it was in level1.

                  Then I tested the movie at the 56K simulation and watched the bandwidth profiler.

                  When I pressed the START button, the sound.swf got loaded, streamed the mp3 file and started playing it.

                  When I pressed the STOP button, the sound.swf movie was unloaded, but the bandwidth profiler indictated that the mp3 called by the sound.swf was still stremaing in.

                  So the only thing I can guess is that, no matter what level the streaming mp3 is in, it streams into level0, and only eliminating the level0 movie will get rid of the streaming. But that blows away the movie that holds the other movies, unless there is another way around it.

                  Any thoughts on this?

                  Gosh, why didn't Macromedia simply create a stopStreaming function for dynamically loaded MP3s?




                  • 6. Re: Stop dynamic MP3 Streaming
                    kglad Adobe Community Professional & MVP
                    tralfaz, check your cache now for that mp3 (if listened to it long enough for it to complete its download). the mp3 will start playing before it listed in your cache just like any partial download. when the download is completed it should be listed in your cache.
                    • 7. Re: Stop dynamic MP3 Streaming
                      Level 7
                      "kglad" <webforumsuser@macromedia.com> wrote in message news:e605d6$qpd$1@forums.macromedia.com...
                      > tralfaz, check your cache now for that mp3 (if listened to it long enough for
                      > it to complete its download). the mp3 will start playing before it listed in
                      > your cache just like any partial download. when the download is completed it
                      > should be listed in your cache.

                      Yeah, your are right, as always. I have pulled many mp3s from my cache in the past but for some reason they weren't showing up in
                      my cache as expected in the last few months. I had thought it was the Flash 8 player doing it. Testing it again now they show up
                      just like they used to. I dunno. Never mind. hehehe
                      tralfaz



                      • 8. Re: Stop dynamic MP3 Streaming
                        kglad Adobe Community Professional & MVP
                        thanks for checking tralfaz. hopefully, the op will get back to this thread and find there's no need for a stopStreaming method.
                        • 9. Re: Stop dynamic MP3 Streaming
                          Level 7
                          "kglad" <webforumsuser@macromedia.com> wrote in message news:e60ehp$6su$1@forums.macromedia.com...
                          > thanks for checking tralfaz. hopefully, the op will get back to this thread and find there's no need for a stopStreaming method.

                          I think he is looking at the bandwidth being used up by a downloading mp3 even after you are no longer interested in it. I have
                          looked at this problem once before. Seems that once you start the streaming, if you then decide to play a different song, the first
                          one keeps on downloading anyway, using up bandwidth and making the 2nd song unable to stream smoothly because half the bandwidth is
                          used up on the first song. It's no problem to stop playing it, but the dang streaming keeps going on in the background after you
                          don't want it anymore!
                          tralfaz


                          • 10. Re: Stop dynamic MP3 Streaming
                            kglad Adobe Community Professional & MVP
                            tralfaz, i understand the issue and i explained a solution: i believe you can stop the download.

                            you can't test the fix in the test environment but you can test online. to check if it works you'll fail to see the mp3 in your cache even after waiting long enough (after the streaming starts) for the mp3 to entirely download.

                            you can also test by trying on several (i believe greater than 5) streaming mp3s. i believe flash limits you to 5 simultaneous downloads. so, under normal circumstances you shouldn't be able to stream (even slowly) your 6th selection unless the previous streaming downloads have ceased.
                            • 11. Re: Stop dynamic MP3 Streaming
                              Level 7
                              "kglad" <webforumsuser@macromedia.com> wrote in message news:e61ek2$ha3$1@forums.macromedia.com...
                              > tralfaz, i understand the issue and i explained a solution: i believe you can
                              > stop the download.
                              >
                              > you can't test the fix in the test environment but you can test online. to
                              > check if it works you'll fail to see the mp3 in your cache even after waiting
                              > long enough (after the streaming starts) for the mp3 to entirely download.
                              >
                              > you can also test by trying on several (i believe greater than 5) streaming
                              > mp3s. i believe flash limits you to 5 simultaneous downloads. so, under
                              > normal circumstances you shouldn't be able to stream (even slowly) your 6th
                              > selection unless the previous streaming downloads have ceased.

                              OK.. gotcha. I will test it to see. Sometimes I get lazy about going back to the beginning of threads to get the whole picture.
                              later,
                              tralfaz


                              • 12. Re: Stop dynamic MP3 Streaming
                                clyde236 Level 1
                                Hi All,

                                First, I very much appreciate your help in tackling this problem. The support is great. Thank you ALL for your interest in this matter, and Boo on Macormedia for making it necessary! I still think they dropped the ball on this one. But you all seem to be on top of it. At least, enough of us are chasing it down!

                                I think kgal DID come up with a solution, once I got my coding right!

                                In my first test of kglad's solution, I had a code error that wasn't really a "true" AS error, so that gave me the wrong results.

                                I re-copied and pasted the code and then the "player" worked properly. (Sorry-- kicking myself)

                                Now that the AS was exaclty what kglad suggested, I saved the file as an SWF and HTML page and posted it along with a song to my Web site.

                                Okay so far.

                                Until, of course I remembered that I am on DSL (but I am trying to code for 56K users as well) so my song, at 321K just zipped in too fast for me to stop it getting into the cache.

                                Easy solution, I reconverted the song to a bigger size, 1.15 MB, which is still not enough to choke DSL, but it does slow it down enough that if I stop it, it won't cache.

                                Well, that worked!

                                Next, I alstered the code a little bit to add a start AND stop button, just to make sure of things.

                                It still seems to work, in that the song simply will NOT cache if, as kglad says, you hit the stop button before the song has a chance to comepletely download and then you wait long enough for it to have cached if it was going to.

                                (Why is this getting confusing?)

                                Okay, so I tested it in MSIE because I can use the Internet Tools to look at my cache files. Trying to do this with Firefox either eludes me or can't be done.

                                What I did in MSIE was opened the Internet Tools, clicked on the settings tab for cookies and cache and looked at the files. I saw my web page, my swf, and (if I allowed the song to play all the way) the song.

                                I cleared the cache, reloaded the page, started the download via the PLAY button. Then I stopped it after about a second. Then I waited the minute or so the song takes to play normally and checked the cache. It wasn't there! (hooray!)

                                So does this mean FLash actually did stop the streaming? It seems to indicate that to me and many thanks to kglad!

                                However, knowing i already messed up one attempt to use the code properly, or I may be analysing the situation incorrctly, would anyone care to try the same trick?

                                I hope this won't be considered spamming if I give you a Web link where the test page is:

                                http://www.clydesight.com/streamMP3/Webtest.html

                                I think this is the solution (though I am not sure whay testing it in the FLASH environment doesn't work-- kind of makes the test movie less than all it could be)

                                Thanks to everyone for your interest and support with this problem. I hope the tech folks at Macromedia see this thread and pick up on it so they can improve their product. Then again, they may raise the price! Oops.....

                                Thanks all, please, if you try my Web pager, post a reply here so I can see what you all found too.

                                And again, many thanks to kglad.


                                • 13. Re: Stop dynamic MP3 Streaming
                                  Level 7
                                  > So does this mean FLash actually did stop the streaming? It seems to indicate
                                  > that to me and many thanks to kglad!

                                  yes! I did some testing myself to be sure.. It works fine! Thanks kglad.

                                  My test mp3 is huge.. 17 megs. I have to use giant files because my connection is too fast for a good test on a smaller one.
                                  If you have a fast connection.. you can see here the percentage of the file that is downloaded. Interestingly enough, when you load
                                  the streaming file again after stopping the download in the middle, it resumes where it left off.
                                  http://www.kompanionkare.net/flash/audio/loadmp3c.html


                                  I tried this..
                                  empty cache
                                  create empty clip and load streaming sound per kglads suggestion..

                                  _root.createEmptyMovieClip("mc1", 1);
                                  mc1.s = new Sound();
                                  mc1.s.loadSound("sound1.mp3", true);

                                  Then after 10 megs have downloaded..
                                  mc1.removeMovieClip();

                                  Check cache.. still empty. No 10 megs there.
                                  Start up again with same code..
                                  mc1.s = new Sound();
                                  mc1.s.loadSound("sound1.mp3", true);

                                  The downloaded bytes continues right where it left off at 10 megs.
                                  Cache remains empty even after refresh until all 17 megs are downloaded.

                                  Apparently, deleting the movieclip stops the streaming download but keeps the partial file in a temp file somewhere (but not in the
                                  browser cache). When the same file is steamed again, it continues the download and copies it to the cache only after the entire
                                  file is downloaded.

                                  And that reminds me.. a long time ago there was a solution that someone came up with to download a file of the same name (from a
                                  different folder), but this time a very short version. Doing that canceled out the download of the longer file. I think that's how
                                  it worked.

                                  tralfaz




                                  • 14. Re: Stop dynamic MP3 Streaming
                                    kglad Adobe Community Professional & MVP
                                    you're welcome.