在流式传输模式下,如何阻止MP3文件通过Flash下载

时间:2020-03-05 18:56:40  来源:igfitidea点击:

我有一个Flash播放器,该播放器具有一组通过xml文件加载的歌曲。

在选择一个之前,文件不会开始流式传输。

如果我快速循环浏览这8个文件中的每个文件,则Flash会开始尝试同时下载8个文件中的每个文件。

我想知道是否有一种方法可以清除正在下载的文件。因此,如果有人决定单击许多轨道名称,则不会耗尽带宽。

像mySound.clear或者mySound.stopStreaming ..这样的东西会很棒。

有人遇到过这个问题吗?

问候,

克里斯

解决方案

回答

如果我们执行以下操作:

MySoundObject =未定义;

那应该做。

回答

签出Sound.Close()。

从文档中:"关闭流,导致任何数据下载停止。调用close()方法后,无法从流中读取任何数据。"

这是链接文档中的源代码示例:

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;
        }
    }
}