简体   繁体   English

具有FLVPlayback的AS3视频播放

[英]AS3 Video Playback with FLVPlayback

I am using the code below to load some data from an .xml file. 我正在使用下面的代码从.xml文件加载一些数据。 I am preloading all data (Audio Paths, Video Paths including a video from xml. 我正在预加载所有数据(音频路径,视频路径,包括来自xml的视频。

When everything is loaded complete i am loading the video in Frame 2 on FLVPlayback 2.5 with this code: 一切加载完成后,我将使用以下代码在FLVPlayback 2.5的第2帧中加载视频:

videoPlayer.source = videofile;

The problem is that the video shows a white screen for 3-4 seconds and then starts play. 问题是视频显示白色屏幕3-4秒钟,然后开始播放。 At some other pc's it plays normaly when the loading ends. 在其他PC上,加载结束时,它正常播放。

My Code: 我的代码:

import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.media.SoundChannel;


stop();
//******************************************************
// XML Loader
//******************************************************
var myLoader:URLLoader = new URLLoader();
//myLoader.load(new URLRequest("myxml.php"));
myLoader.load(new URLRequest("myxml.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);

function processXML(e:Event):void{

    var myXml:XML = new XML(e.target.data);
    parseXML(myXml); 
}


//******************************************************
// Extract XML value and fill up variables
//******************************************************
var thename:XML;
var soundpath:XML;
var theage:XML;
var theplace:XML;
var everyday:XML;
var youwill:XML;
var pic1:XML;
var pic2:XML;
var pic3:XML;
var videofile:XML;

var assetsList:Array;
//-----------------------------
var sound:Sound;
var soundChannel:SoundChannel;

//-----------------------------

function parseXML(xml:XML):void{

    thename = xml.paths.thename[0];
    soundpath = xml.paths.soundpath[0];
    theage = xml.paths.theage[0];
    theplace = xml.paths.theplace[0];
    everyday = xml.paths.everyday[0];
    youwill = xml.paths.youwill[0];
    pic1 = xml.paths.pic1[0];
    pic2 = xml.paths.pic2[0];
    pic3 = xml.paths.pic3[0];
    videofile = xml.paths.videofile[0];

    txtThename.text = thename;
    txtSoundpath.text = soundpath;
    txtTheage.text = theage;
    txtTheplace.text = theplace;
    txtEveryday.text = everyday;
    txtYouwill.text = youwill;
    txtPic1.text = pic1;
    txtPic2.text = pic2;
    txtPic3.text = pic3;
    txtVideofile.text = videofile;

    assetsList = [soundpath,theage,theplace,everyday,youwill,pic1,pic2,pic3,videofile];
    preloadAssets();
}
//******************************************************
// preloaded assets
//******************************************************
var assetsLoader:URLLoader 
var assetsCtr:Number=0;

function preloadAssets():void{

    assetsLoader = new URLLoader ();
    var urlRequest:URLRequest = new URLRequest(assetsList[assetsCtr]); 
    assetsLoader.load(urlRequest);

    assetsLoader.addEventListener(Event.COMPLETE, assetLoadedHanlder);
    assetsLoader.addEventListener(ProgressEvent.PROGRESS, assetProgressHandler);

}

function assetProgressHandler(evt:ProgressEvent):void{
    var bl:uint = evt.bytesLoaded;
    var bt:uint = evt.bytesTotal;
    var perEachAssets = 1/assetsList.length;

    var assetsBlLoaded = ((bl / bt)*perEachAssets)+((assetsCtr)/assetsList.length*100)/100;
    var _percentLoaded = Math.floor(assetsBlLoaded*100);

    progBar.setProgress(_percentLoaded,100)
    //trace("_percentLoaded:",_percentLoaded)

}
function assetLoadedHanlder(evt:Event):void{

    assetsCtr+=1;
    if(assetsCtr<assetsList.length){
        //trace("preloading:"+assetsList[assetsCtr])
        var urlRequest:URLRequest = new URLRequest(assetsList[assetsCtr]); 
        assetsLoader.load(urlRequest);

    }else{
        //trace("done!")
        assetsLoader.removeEventListener(Event.COMPLETE, assetLoadedHanlder);
        assetsLoader.removeEventListener(ProgressEvent.PROGRESS, assetProgressHandler);
        gotoAndStop(2);
    }
}

Rather than adding the component directly to the stage you might want to try creating and adding it with ActionScript. 与其直接将组件添加到舞台,不如尝试使用ActionScript创建和添加组件。

By doing this you can instantiate the FLVPlayback instance before you need to show it, rather than having to wait until you hit frame 2 on your timeline. 这样,您可以在需要显示它之前实例化FLVPlayback实例,而不必等到在时间轴上点击第2帧。

I can't guarantee it will fix your problem but it's worth a go. 我不能保证它能解决您的问题,但是值得一试。

var _videoFLV:FLVPlayback;
_videoFLV = new FLVPlayback();
_videoFLV.fullScreenTakeOver = false;
_videoFLV.autoPlay = false;
_videoFLV.autoRewind = true;
_videoFLV.isLive = false;
_videoFLV.skin = null;      
_videoFLV.bufferTime = .1;
_videoFLV.width = 320;
_videoFLV.height = 240;
_videoFLV.source = videofile;
_videoFLV.stop();
_videoFLV.x = 240;
_videoFLV.y = 240;
addChild(_videoFLV);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM