So I've got a fairly standard video player, using code adapted from
Brimelow et al, but the problem I'm runnign into is that the first
time the page loads, it plays the video just fine, but the scrubber
doesnt work. Once I reload the page, it loads fine and the scrubber
kicks in. Has anyone else encountered this? Some of the code is
below...

thx,

.matt






-------------------------

public function VideoModule(myR,vD) {
                        trace("Video Module Loaded");
                        //
                        myRoot = myR;
                        myVideo = vD;
                        _videoStarted = false;
                        //
                        displayHours = true;
                        //
                        _videobg = new Sprite();
                        _videobg.name = "bg";
                        _videobg.graphics.lineStyle();
                        _videobg.graphics.beginFill(0xFFFFFF);
                        _videobg.graphics.drawRect(0,0,10,10);
                        _videobg.graphics.endFill();
                        _videobg.visible = false;
                        addChild(_videobg);
                        //
                        _video = new Video(80,60);

                        //
                        _playbackTime = new Timedisplay();
                        _playbackTime.visible = false;
                        _duration = 0;
                        //
                        //ADD THE PLAY/PAUSE BTN
                        _pausebtn = new Pausebtn();
                        _pausebtn.name = "pausebtn_mc";

                        _pausebtn.mouseEnabled = true;
                        _pausebtn.useHandCursor = true;
                        _pausebtn.buttonMode = true;
                        _pausebtn.visible = false;
                        addChild(_pausebtn);
                        //
                        var connection:NetConnection = new NetConnection();
                        connection.connect(null);
                        _stream = new NetStream(connection);
                        _stream.bufferTime = 1;
                        _stream.play(vD);
                        
                        var client:Object = new Object();
                        client.onMetaData = onMetaData;
                        _stream.client = client;
                        _video.attachNetStream(_stream);
                        _video.x = 0;
                        _video.y = 0;
                        _video.visible = false;
                        addChild(_video);
                        addChild(_playbackTime);
                        //
                        
                        //this timer restarts the video after it has been 
paused by the resizer
                        resTimer = new Timer(700,1);
                        resTimer.addEventListener("timer", restartVideo);
                        //activate Listeners
                        addListeners();
                        
                }
                public function addListeners():void {

                        
_stream.addEventListener(NetStatusEvent.NET_STATUS,onStatus);
                        //_stream.addEventListener(NetStatusEvent.NET_STATUS,
onNetStatusEvent, false, 0, true);
                        addEventListener(Event.ENTER_FRAME,onEnterFrame);
                        
_pausebtn.addEventListener(MouseEvent.MOUSE_DOWN,pausePlay);
                        myRoot.stage.addEventListener( Event.RESIZE, 
videoResizer );

                }
                //
                private function onMetaData(data:Object):void {
                        _duration = data.duration;
                }
                

                
                
                
                private function onEnterFrame(event:Event):void {
                        if (_duration > 0 && _stream.time > 0) {
                                var nowSecs:Number = Math.floor(_stream.time);
                                var totalSecs:Number = Math.round(_duration);

                                /*if (nowSecs > totalSecs-.2) {
                                        _stream.seek(0);
                                        _stream.pause();
                                        _pausebtn.gotoAndStop(2);
                                        _playbackTime.txt.text = "00:00:00";
                                }*/

                                _playbackTime.txt.text = 
videoTimeConvert(nowSecs);// + " / " +
videoTimeConvert(totalSecs);


                        }
                }
                private function onStatus(event:NetStatusEvent):void {
                        if (_video.videoWidth > 0 && _video.width != 
_video.videoWidth) {

                                //SCALE AND POSITION THE VIDEO ELEMENTS

                                _video.width = _video.videoWidth;
                                _video.height = _video.videoHeight;
                                //_video.x = Math.round( (800-_video.width)/2 );
                                //_video.y = Math.round( (600-_video.height)/2 
);
                                //
                                _videobg.y = _video.y-10;
                                _videobg.x = _video.x-10;
                                _videobg.width = _video.width+20;
                                _videobg.height = _video.height+42;
                                _videobg.visible = true;
                                //
                                _playbackTime.y = _video.y+_video.height+8;
                                _playbackTime.x = _video.x+_video.width;
                                _video.visible = true;
                                _playbackTime.visible = true;
                                //
                                _pausebtn.y = _video.y+_video.height+13;
                                _pausebtn.x = _video.x;
                                _pausebtn.visible = true;
                                //
                                _scrubber = new
VideoScrubber(_stream,_duration,_video.width-(9+3+_playbackTime.width)
);
                                _scrubber.name = "scrubber_mc";
                                _scrubber.y = _video.y+_video.height+13;
                                _scrubber.x = _video.x+9;
                                //
                                addChild(_scrubber);
                                //
                                videoResizer(null);
                                _videoStarted = true;
                        }
                        if (event.info.code == "NetStream.Play.Stop") {
                                _stream.seek(0);
                                _stream.pause();
                                _pausebtn.gotoAndStop(2);
                        }
                }
                //
                private function pausePlay(e:MouseEvent) {
                        _stream.togglePause();
                        if (_pausebtn.currentFrame == 1) {
                                _pausebtn.gotoAndStop(2);
                        } else {
                                _pausebtn.gotoAndStop(1);
                        }
                }
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to