我正在使用Adobe AIR AS3创建一个Android应用程序。我的程序工作正常,当我只有1个XML数据时,视频可以播放。但是当我有2个或更多数据时,我无法播放视频,即使图像加载得很好。我的节目中有什么错过的吗?这是我的整个AS3脚本和我的xml数据。
import flash.events.MouseEvent;
import flash.media.Video;
import flash.display.MovieClip;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.NetStatusEvent;
import flash.events.AsyncErrorEvent;
import flash.ui.Mouse;
import flash.media.SoundTransform;
import flash.geom.Rectangle;
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
stage.displayState=StageDisplayState.FULL_SCREEN;
FilterShortcuts.init();
stop();
var mainBtn:MovieClip = btnMain;
var helpBtn:MovieClip = btnHelp;
var exitBtn:MovieClip = btnExit;
var mainPage:MovieClip = mcMainMenu;
var logoIcon:MovieClip = mcIcon;
var contentPage:MovieClip = mcContent;
var videoBox:MovieClip = mcContent.mcVideoArea;
var playBtn:MovieClip = mcContent.btnPlay;
var pauseBtn:MovieClip = mcContent.btnPause;
var timelineSlider:MovieClip = mcContent.mcTimelineSlider;
var timelineBuffer:MovieClip = mcContent.mcTimelineSlider.mcTimelineBuffer;
var timelineProgress:MovieClip = mcContent.mcTimelineSlider.mcTimelineProgress;
var timelineBtn:MovieClip = mcContent.mcTimelineSlider.btnTimeline;
var volumeSlider:MovieClip = mcContent.mcVolumeSlider;
var volumeBtn:MovieClip = mcContent.mcVolumeSlider.btnVolume;
var volumeActive:MovieClip = mcContent.mcVolumeSlider.mcVolumeActive;
var helpPage:MovieClip = mcHelpPage;
var backBtn:MovieClip = mcHelpPage.btnCancel;
var exitPage:MovieClip = mcExitPage;
var yesBtn:MovieClip = mcExitPage.btnYes;
var noBtn:MovieClip = mcExitPage.btnNo;
mainPage.visible=true;
logoIcon.visible=true;
contentPage.visible=false;
mainBtn.visible=false;
helpPage.visible=false;
exitPage.visible=false;
var currentVideo:String;
var videoWidth:Number=1280;
var videoHeight:Number=720;
var duration:Number;
var video:Video=new Video(videoWidth, videoHeight);
video.x=-640;
video.y=-360;
videoBox.addChild(video);
var nc:NetConnection=new NetConnection();
nc.connect(null);
var ns:NetStream=new NetStream(nc);
video.attachNetStream(ns);
var newMeta:Object=new Object();
newMeta.onMetaData=onMetaData;
ns.client=newMeta;
ns.bufferTime=5;
var videoSound=SoundTransform;
var volumeBounds:Rectangle;
videoSound=new SoundTransform();
videoSound.volume=.5;
ns.soundTransform=videoSound;
var videoInterval=setInterval(videoStatus, 100);
var amountLoaded:Number;
var scrubInterval;
var mcContainer:MovieClip;
var xmlPath:String="list.xml";
var xml:XML;
var loader=new URLLoader();
var currentThumb:Number=0;
var i:Number=0;
var videoThumbLoader:Loader;
var videoItemName:String;
var columns:Number=6;
var xCount:Number;
var yCount:Number;
mainBtn.addEventListener(MouseEvent.CLICK, gotoMain);
helpBtn.addEventListener(MouseEvent.CLICK, gotoHelp);
exitBtn.addEventListener(MouseEvent.CLICK, gotoExit);
backBtn.addEventListener(MouseEvent.CLICK, goBack);
yesBtn.addEventListener(MouseEvent.CLICK, exitApp);
noBtn.addEventListener(MouseEvent.CLICK, goBack);
ns.addEventListener(NetStatusEvent.NET_STATUS, myStatusHandler);
playBtn.addEventListener(MouseEvent.CLICK,playBtnClick);
pauseBtn.addEventListener(MouseEvent.CLICK,pauseBtnClick);
volumeBtn.addEventListener(MouseEvent.MOUSE_DOWN,volumeScrubberDown);
timelineBtn.addEventListener(MouseEvent.MOUSE_DOWN, videoScrubberDown);
loader.load(new URLRequest(xmlPath));
loader.addEventListener(Event.COMPLETE,xmlLoaded);
function gotoMain(e:MouseEvent):void{
mainPage.visible=true;
logoIcon.visible=true;
contentPage.visible=false;
mainBtn.visible=false;
flash.media.SoundMixer.stopAll();
}
function gotoHelp(e:MouseEvent):void{
helpPage.visible=true;
ns.pause();
}
function goBack(e:MouseEvent):void{
helpPage.visible=false;
exitPage.visible=false;
ns.resume();
}
function gotoExit(e:MouseEvent):void{
helpPage.visible=false;
exitPage.visible=true;
ns.pause();
}
function exitApp(e:MouseEvent):void{
NativeApplication.nativeApplication.exit();
}
function myStatusHandler(e:NetStatusEvent):void{
//trace(e.info.code);
switch(e.info.code){
case "NetStream.Buffer.Full":
ns.bufferTime=10;
break;
case "NetStream.Buffer.Empty":
ns.bufferTime=10;
break;
case "NetStream.Play.Start":
ns.bufferTime=10;
break;
case "NetStream.Seek.Notify":
ns.bufferTime=10;
break;
case "NetStream.Seek.InvalidTime":
ns.bufferTime=10;
break;
case "NetStream.Play.Stop":
ns.pause();
ns.seek(1);
break;
}
}
function onMetaData(newMeta:Object):void{
//trace("Metadata:duration="+newMeta.duration+" width="+newMeta.width+" height="+newMeta.height+" framerate"+newMeta.framerate);
duration=newMeta.duration;
}
function playBtnClick(e:MouseEvent):void{
ns.resume();
}
function pauseBtnClick(e:MouseEvent):void{
ns.pause();
}
function volumeScrubberDown(e:MouseEvent):void{
volumeBounds=new Rectangle(0,0,169,0);
volumeBtn.startDrag(false,volumeBounds);
stage.addEventListener(MouseEvent.MOUSE_UP,volumeBtnUp);
stage.addEventListener(MouseEvent.MOUSE_MOVE,volumeBtnMove);
}
function volumeBtnUp(e:MouseEvent):void{
volumeBtn.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, volumeBtnUp);
stage.removeEventListener(MouseEvent.MOUSE_MOVE, volumeBtnMove);
}
function volumeBtnMove(e:MouseEvent):void{
volumeActive.width=volumeBtn.x;
videoSound.volume=(volumeBtn.x)/50;
ns.soundTransform=videoSound;
}
function videoStatus():void{
amountLoaded=ns.bytesLoaded/ns.bytesTotal;
timelineBuffer.width=amountLoaded*900;
timelineBtn.x=ns.time/duration*900;
timelineProgress.width=timelineBtn.x;
}
function videoScrubberDown(e:MouseEvent):void{
var bounds:Rectangle=new Rectangle(0,0,900,0);
clearInterval(videoInterval);
scrubInterval=setInterval(scrubTimeline,10);
timelineBtn.startDrag(false,bounds);
stage.addEventListener(MouseEvent.MOUSE_UP,stopScrubbingVideo);
}
function scrubTimeline():void{
ns.seek(Math.floor((timelineBtn.x/900)*duration));
}
function stopScrubbingVideo(e:MouseEvent):void{
stage.removeEventListener(MouseEvent.MOUSE_UP,stopScrubbingVideo);
clearInterval(scrubInterval);
videoInterval=setInterval(videoStatus,100);
timelineBtn.stopDrag();
}
function xmlLoaded(e:Event):void{
if((e.target as URLLoader)!=null){
xml = new XML(loader.data);
loader.removeEventListener(Event.COMPLETE, xmlLoaded);
makeVideoThumb();
//trace(xml);
}
}
function makeVideoThumb():void{
xCount=0;
yCount=0;
mcContainer=new MovieClip();
mcContainer.x=-600; //set the container x position
mcContainer.y=-255; //set the container y position
mainPage.addChild(mcContainer);
if(i>0){
i=0;
}
for each(var videoNode:XML in xml.content){
var videoItem:mc_thumbContainer=new mc_thumbContainer();
videoItem.txtVideoTitle.text=videoNode.@title;
videoItem.txtVideoCountry.text=videoNode.@country;
videoItem.x=(videoItem.width+30)*xCount;
videoItem.y=(videoItem.height+30)*yCount;
videoItem.name=""+i;
videoItem.addEventListener(MouseEvent.CLICK, videoItemClick);
var videoThumbURL=videoNode.@cover;
videoThumbLoader=new Loader();
videoThumbLoader.load(new URLRequest(videoThumbURL));
videoThumbLoader.x=6;
videoThumbLoader.y=5;
videoItem.addChild(videoThumbLoader);
videoThumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, videoThumbLoaded);
mcContainer.addChild(videoItem);
i++;
if(xCount+1<columns){
xCount++;
}else{
xCount=0;
yCount++;
}
}
}
function videoThumbLoaded(e:Event):void{
videoThumbLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, videoThumbLoaded);
}
function videoItemClick(e:MouseEvent):void{
videoItemName=e.target.name;
currentVideo=xml.content.@video;
mainPage.visible=false;
logoIcon.visible=false;
contentPage.visible=true;
mainBtn.visible=true;
video.width=videoWidth;
video.height=videoHeight;
ns.play(currentVideo);
}
这是xml
<?xml version="1.0"?>
<list>
<content id="1" title="story" country="England" cover="http://localhost:280/list//content/cover/6a778-cover-72.jpg" video="http://localhost:280/list//content/video/e27f9-video.mp4"/>
<content id="2" title="story-2" country="England" cover="http://localhost:280/list//content/cover/2e383-cover-72.jpg" video="http://localhost:280/list//content/video/cce76-video.mp4"/>
</list>