声音流停止装 [英] sound stream stops loading

查看:108
本文介绍了声音流停止装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一点点的声音流脚本在这里,但有时如果你当前的前preSS发挥下一首曲目已加载完成的下轨不comeplete加载

 包装机{
    进口对象类型:flash.events.Event;
    进口flash.display.Sprite;
    进口的flash.external.ExternalInterface;
    进口flash.media.Sound;
    进口flash.media.SoundChannel;
    进口flash.net.URLRequest;

    进口player.Loader_bar;

    公共类流扩展Sprite {
        私人VAR _Sound = NULL;
        私人VAR _Channel = NULL;

        私人VAR isLoading = FALSE;

        私人VAR _Loader_bar = NULL;
        公共变种loader_color = NULL;
        公共变种loader_width = 0;
        公共变种loader_height = 0;

        私人变种I = 0;

        公共职能流(){
            this._Loader_bar =新Loader_bar();
            的addChild(this._Loader_bar);
        }

        公共职能cnstr(){
            this._Loader_bar.color = this.loader_color;
            this._Loader_bar.w = this.loader_width;
            this._Loader_bar.h = this.loader_height;
            this._Loader_bar.cnstr();
        }

        公共职能发挥(URL){
            this.stop();
            this.close();

            this._Sound =新的声音();
            this.isLoading = TRUE;

            this.addEventListener(Event.ENTER_FRAME,listener_bytesLoaded);
            this._Sound.addEventListener(引发Event.COMPLETE,listener_loadedComplete);

            this._Sound.load(新的URLRequest(URL));
            this._Channel = this._Sound.play();
        }

        公共功能停止(){
            如果(this._Channel){
                this._Channel.stop();
            }
        }

        私有函数关闭(){
            如果(this.isLoading){
                this._Sound.close();
            }
        }

        私有函数listener_loadedComplete(事件){
            this.close();

            this.isLoading = FALSE;

            this.removeEventListener(Event.ENTER_FRAME,listener_bytesLoaded);
        }

        私有函数listener_bytesLoaded(事件){
            VAR浮= this._Sound.bytesLoaded / this._Sound.bytesTotal;
            this._Loader_bar.progress(浮动);

            VAR数据= {
                我:this.i,
                浮动:浮动,
                加载:this._Sound.bytesLoaded,
                总:this._Sound.bytesTotal
                };
            ExternalInterface.call('swf2js','tst_progress',数据);
            this.i ++;
        }
    }
}
 

解决方案

关闭():无效 关闭该流,从而导致所有数据的下载停止了。

试试这个:

创建这样一个布尔值 hasLoaded ,将其设置为false。当声音成功加载其设置为true。

然后,当你播放声音,你可以测试 hasLoaded 播放()的功能。如果您有一个名为播放()您previous声音加载之前, hasLoaded 将是错误的,在这种情况下,您拨打的 this._Sound.close( )之前创建和加载新的声音。之所以进行测试,而不是仅仅调用关闭()是这样,如果你已经暂停流,你不必重新装入再次播放。

增加:

关于负载不能正常申报,你有你的进步的逻辑设置不正确。试试这个:

1)进口flash.events.ProgressEvent

2)对于监听器,代替this.addEventListener(Event.ENTER_FRAME,listener_bytesLoaded);在你的play()方法与this._Sound.addEventListener(使用ProgressEvent.PROGRESS,listener_bytesLoaded);

3)更改listener_bytesLoaded()方法如下:

 私有函数listener_bytesLoaded(事件:ProgressEvent)
{
    VAR百分比= event.bytesLoaded / event.bytesTotal;
    this._Loader_bar.progress(百分比);

    VAR数据= {
            我:this.i,
            飘:个百分点,
            加载:event.bytesLoaded,
            总:event.bytesTotal
            };

        ExternalInterface.call('swf2js','tst_progress',数据);
        this.i ++;
    }
 

4)改变this.removeEventListener(Event.ENTER_FRAME,listener_bytesLoaded); 在listener_loadedComplete()方法来this._Sound.removeEventListener(使用ProgressEvent.PROGRESS,listener_bytesLoaded);然后将其移出的方法,并把它里面的条件在close()方法。

请注意 - 我其实没有编译这一点,但我认为它好到哪里去。希望有所帮助。 :)

I have a little sound stream script here, but sometimes if you press play to the next track before the current has done loading the next track doesn't comeplete loading

package player {
    import flash.events.Event;
    import flash.display.Sprite;
    import flash.external.ExternalInterface;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.net.URLRequest;

    import player.Loader_bar;

    public class Stream extends Sprite {
        private var _Sound = null;
        private var _Channel = null;

        private var isLoading = false;

        private var _Loader_bar = null;
        public var loader_color = null;
        public var loader_width = 0;
        public var loader_height = 0;

        private var i = 0;

        public function Stream(){
            this._Loader_bar = new Loader_bar();
            addChild(this._Loader_bar);
        }

        public function cnstr(){
            this._Loader_bar.color = this.loader_color;
            this._Loader_bar.w = this.loader_width;
            this._Loader_bar.h = this.loader_height;
            this._Loader_bar.cnstr();
        }

        public function play(url){
            this.stop();
            this.close();

            this._Sound = new Sound();
            this.isLoading = true;

            this.addEventListener(Event.ENTER_FRAME, listener_bytesLoaded);
            this._Sound.addEventListener(Event.COMPLETE, listener_loadedComplete);

            this._Sound.load(new URLRequest(url));
            this._Channel = this._Sound.play();
        }

        public function stop(){
            if(this._Channel){
                this._Channel.stop();
            }
        }

        private function close(){
            if(this.isLoading){
                this._Sound.close();
            }
        }

        private function listener_loadedComplete(event){
            this.close();

            this.isLoading = false;

            this.removeEventListener(Event.ENTER_FRAME, listener_bytesLoaded);
        }

        private function listener_bytesLoaded(event){
            var float = this._Sound.bytesLoaded / this._Sound.bytesTotal;
            this._Loader_bar.progress(float);

            var data = {
                i : this.i,
                float : float,
                loaded : this._Sound.bytesLoaded,
                total : this._Sound.bytesTotal
                };
            ExternalInterface.call('swf2js', 'tst_progress', data);
            this.i++;
        }
    }
}

解决方案

close():void Closes the stream, causing any download of data to cease.

try this:

create a boolean like hasLoaded, set it to false. When the sound successfully loads set it to true.

Then when you play a sound you can test for hasLoaded in your play() function. If you have called play() before your previous sound has loaded, hasLoaded will be false, in which case you call this._Sound.close() before creating and loading the new sound. The reason for testing instead of just calling close() is so if you have paused the stream you don't have to reload it to play it again.

ADDITION:

Concerning the load not reporting properly, you have your progress logic set up incorrectly. Try this:

1) import flash.events.ProgressEvent

2) For the listener, replace this.addEventListener(Event.ENTER_FRAME, listener_bytesLoaded); in your play() method with this._Sound.addEventListener(ProgressEvent.PROGRESS, listener_bytesLoaded);

3) Change your listener_bytesLoaded() method to the following:

private function listener_bytesLoaded(event:ProgressEvent)
{
    var percent = event.bytesLoaded / event.bytesTotal;
    this._Loader_bar.progress(percent);

    var data = {
            i : this.i,
            float : percent,
            loaded : event.bytesLoaded,
            total : event.bytesTotal
            };

        ExternalInterface.call('swf2js', 'tst_progress', data);
        this.i++;
    }

4) Change this.removeEventListener(Event.ENTER_FRAME, listener_bytesLoaded); in your listener_loadedComplete() method to this._Sound.removeEventListener(ProgressEvent.PROGRESS, listener_bytesLoaded); and then move it out of that method and place it inside the conditional in the close() method.

NOTE - I didn't actually compile this but I think its good to go. Hope that helps. :)

这篇关于声音流停止装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆