0

我正在使用下面的代码从 .xml 文件中加载一些数据。我正在预加载所有数据(音频路径、视频路径,包括来自 xml 的视频。

当一切都加载完成后,我正在使用以下代码在 FLVPlayback 2.5 上的第 2 帧中加载视频:

videoPlayer.source = videofile;

问题是视频显示白屏 3-4 秒,然后开始播放。在其他一些电脑上,加载结束时它可以正常播放。

我的代码:

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);
    }
}
4

1 回答 1

1

与其将组件直接添加到舞台,不如尝试使用 ActionScript 创建和添加它。

通过这样做,您可以在需要显示 FLVPlayback 实例之前对其进行实例化,而不必等到您点击时间轴上的第 2 帧。

我不能保证它会解决您的问题,但值得一试。

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);
于 2012-11-22T19:34:45.423 回答