Skip to main content
Inspiring
January 3, 2012
Answered

NetStream.resume() has no effect

  • January 3, 2012
  • 1 reply
  • 2370 views

Hi everyone,

I'm developing a videos slideshow in AS3. Here my Video.as class that handles connection&stream of each player :

package com.dm.player

{

    import flash.display.Sprite;

    import flash.media.SoundTransform;

    import flash.net.NetConnection;

    import flash.net.NetStream;

    import flash.events.Event;

    import flash.events.NetStatusEvent;

    import flash.events.SecurityErrorEvent;

    public class Video extends Sprite

    {

        private var config : Object;

        private var connection : NetConnection;

        private var stream : NetStream;

        private var video : flash.media.Video;

        private var addedToStage : Boolean = false;

        public function Video(config : Object)

        {

            this.config = config;

            this.addEventListener(Event.ADDED_TO_STAGE, this.onAddedToStage);

        }

        private function onAddedToStage(event : Event) : void

        {

            if (this.addedToStage)

            {

                return;

            }

            this.addedToStage = true;

            this.video = new flash.media.Video();

            this.connection = new NetConnection();

            this.addChild(this.video);

        }

        private function onStreamNetStatus(event : NetStatusEvent) : void

        {

            switch (event.info.code)

            {

                case 'NetStream.Buffer.Flush':

                    if (this.paused)

                    {

                        this.paused = false;

                        this.stream.play();

                    }

                    break;

                case 'NetStream.Buffer.Full':

                    this.paused = true;

                    this.stream.pause();

                    break;

                case 'NetStream.Play.Stop':

                    this.paused = false;

                    this.connection.close();

                    this.stream.close();

                    this.video.attachNetStream(null);

                    break;

            }

        }

        public function cue(streamURL : String) : void

        {

            this.connection.connect(null);

            this.stream = new NetStream(this.connection);

            this.stream.addEventListener(NetStatusEvent.NET_STATUS, this.onStreamNetStatus);

            this.stream.client = this;

            // mute sound

            var newSoundTransform : SoundTransform = this.stream.soundTransform;

            newSoundTransform.volume = 0;

            this.stream.soundTransform = newSoundTransform;

            this.stream.receiveAudio(false);

            this.video.attachNetStream(this.stream);

            this.video.width = this.config.width;

            this.video.height = this.config.height;

            this.stream.play(streamURL);

        }

        public function onMetaData(info : Object) : void {}

    }

}

Sometimes this.stream.resume() has no effect on videos. The slideshow stops on a video and nothing happens : no event.info.code from onStreamNetStatus.

Any ideas ?

Thanks for your help.

Yvan

This topic has been closed for replies.
Correct answer ymichel

what's your url and what needs to be done to see the problem?


I finally solved the problem by adding this.stream.seek(0) when I pause() the stream.

1 reply

kglad
Community Expert
Community Expert
January 3, 2012

i don't see where you're even using this.stream.resume()

ymichelAuthor
Inspiring
January 3, 2012

Indeed, you're right.

In the NetStream.Buffer.Flush case in the NET_STATUS handler, it's "this.stream.resume()" instead "this.stream.play()".

kglad
Community Expert
Community Expert
January 3, 2012

what's trace(event.info.code,event.info.code.length,this.paused) show when you expect your resume() method to execute?