How to stop a mp3 file from being downloaded by flash when in streaming mode

I have a flash player that has a set of songs loaded via an xml file.

The files dont start getting stream until you pick one.

If I quickly cycle through each of the 8 files, then flash starts trying to download each of the 8 files at the same time.

I'm wondering if there is a way to clear the file that is being downloaded. So that bandwidth is not eaten up if someone decides to click on lots of track names.

Something like mySound.clear would be great, or mySound.stopStreaming..

Has anyone had this problem before?

Regards,

Chris

Answers


Check out Sound.Close().

From the docs: "Closes the stream, causing any download of data to cease. No data may be read from the stream after the close() method is called."

This is the source code example from the linked docs:

package {
    import flash.display.Sprite;
    import flash.net.URLRequest;
    import flash.media.Sound;    
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.events.MouseEvent;
    import flash.errors.IOError;
    import flash.events.IOErrorEvent;

    public class Sound_closeExample extends Sprite {
        private var snd:Sound = new Sound();
        private var button:TextField = new TextField();
        private var req:URLRequest = new URLRequest("http://av.adobe.com/podcast/csbu_dev_podcast_epi_2.mp3");

        public function Sound_closeExample() {
            button.x = 10;
            button.y = 10;
            button.text = "START";
            button.border = true;
            button.background = true;
            button.selectable = false;
            button.autoSize = TextFieldAutoSize.LEFT;

            button.addEventListener(MouseEvent.CLICK, clickHandler);

            this.addChild(button);
        }

        private function clickHandler(e:MouseEvent):void {

            if(button.text == "START") {

                snd.load(req);
                snd.play();        

                snd.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);

                button.text = "STOP";
            }
            else if(button.text == "STOP") {

                try {
                    snd.close();
                    button.text = "Wait for loaded stream to finish.";
                }
                catch (error:IOError) {
                    button.text = "Couldn't close stream " + error.message;    
                }
            }
        }

        private function errorHandler(event:IOErrorEvent):void {
                button.text = "Couldn't load the file " + event.text;
        }
    }
}

Need Your Help

Handlebar doesn't render a collection field correctly

collections meteor render handlebars.js

I'm having problem trying to use a collection field named created in a template. Is that a reserved word, or something?

How do I install the D programming language into C:\Program Files?

windows installation d

The prompt says that if I install the software into a directory with spaces:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.