FLV在flash播放器口吃

时间:2013-05-24 22:33:28

标签: flash video actionscript streaming flv

我的FLV在VLC,Windows Media Player和Adobe Media Player中流畅播放。

如果我将相同的电影加载到闪存中,无论是通过流媒体,嵌入,使用软件渲染还是硬件渲染......它都会无法控制地断断续续。这是我的代码:

package
{
    import flash.display.Sprite;
    import flash.events.AsyncErrorEvent;
    import flash.events.NetStatusEvent;
    import flash.events.StageVideoAvailabilityEvent;
    import flash.media.StageVideo;
    import flash.media.StageVideoAvailability;
    import flash.media.Video;
    import flash.net.NetConnection;
    import flash.net.NetStream;

    [SWF(width='760',height='500')]
    public class VideoPlayer extends Sprite
    {
        [Embed(source = "_example.flv", mimeType = "application/octet-stream")]
        private var VideoBytes:Class;

        private var _netStream:NetStream;

        public function VideoPlayer()
        {
            var nc:NetConnection = new NetConnection();
            nc.addEventListener(NetStatusEvent.NET_STATUS , onStreamStatus);
            nc.connect(null);
            _netStream = new NetStream(nc);
            _netStream.addEventListener(NetStatusEvent.NET_STATUS, onStreamStatus);
            _netStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
            _netStream.client = this;

            //playNormally();
            //playEmbedded();
            playHardwareAccelerated();
        }

        private function playEmbedded():void
        {
            var video:Video = new Video(stage.stageWidth, stage.stageHeight);
            video.attachNetStream(_netStream);
            addChild(video);

            _netStream.play(null);
            _netStream.appendBytes(new VideoBytes());
        }

        private function playNormally():void
        {
            var video:Video = new Video(stage.stageWidth, stage.stageHeight);
            video.attachNetStream(_netStream);
            addChild(video);

            _netStream.play("_example.flv");    
        }

        private function playHardwareAccelerated():void
        {
            if( !stage.stageVideos.length ) stage.addEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY, onStageVideoState);
            else onStageVideoState(null);
        }
        private function onStageVideoState(e:StageVideoAvailabilityEvent):void{ 
            if(e == null || e.availability == StageVideoAvailability.AVAILABLE){
                var stageVideo:StageVideo = stage.stageVideos[1];
                stageVideo.attachNetStream(_netStream);
                _netStream.play("_scene.flv");  
            }
            else trace("StageVideo Unavailable");
        }

        public function asyncErrorHandler(event:AsyncErrorEvent):void { trace(event.text); }
        public function onStreamStatus(e:NetStatusEvent):void { trace(e.info.code); }
        public function onMetaData( info:Object ) : void { trace("onMetaData:"); traceObject(info, 1); }
        public function onCuePoint( info:Object ) : void { trace("onCuePoint:"); traceObject(info, 1); }
        public function onXMPData( info:Object ) : void { trace("onXMPData:"); traceObject(info, 1); }
        public function onLastSecond( info:Object ) : void { trace("onLastSecond:"); traceObject(info, 1); }

        public function traceObject(obj:Object, indent:uint = 0):void 
        { 
            var indentString:String = ""; 
            for(var i:uint = 0; i < indent; i++) indentString += "\t";

            if(obj == null) trace(indentString + " null");
            else{
                var isEmpty:Boolean = true;
                for(var prop:String in obj){
                    var val:* = obj[prop];
                    isEmpty = false;
                    if(typeof(val) == "object"){ 
                        trace(indentString + " " + prop + ": [Object]"); 
                        traceObject(val, indent + 1); 
                    } 
                    else trace(indentString + " " + prop + ": " + val);
                }
                if( isEmpty ) trace(indentString + " empty");
            }
        }

    }
}

here's my FLV

我对此怎么办感到茫然......而答案可能就是闪光灯FLV渲染器不能很好地平滑地显示我的flv,不像我尝试过的其他FLV播放器。但是,这对我的项目来说是一个大问题,我必须找到解决方案。

谢谢!

0 个答案:

没有答案