我正忙于一个项目,两个视频必须互相播放。 与以下网站中的http://kindnessday.sg/home#/kindness/home一样 由于文件大,我无法将视频嵌入到swf中。它会变得太大。因此,必须通过'webstream链接加载视频。但是第一个视频在第二个视频之前播放并导致视频未同步。
有没有办法同时播放两个视频?
var stream = 'http://mydomain/clip1.mp4'
var stream1 = 'https://mydomain/clip2.mp4'
var http_stream:URLStream = null
var http_stream1:URLStream = null
var video:Video = new Video() // the video is used only to ensure that stream is playing
var video1:Video = new Video() // the video is used only to ensure that stream is playing
addChild(video1)
addChild(video)
var nc:NetConnection = new NetConnection()
nc.connect(null)
var ns:NetStream = new NetStream(nc)
ns.client = new Object()
ns.client.onMetaData = function(e){}
ns.play(null)
var ns1:NetStream = new NetStream(nc)
ns1.client = new Object()
ns1.client.onMetaData = function(e){}
ns1.play(null)
video.attachNetStream(ns)
video1.attachNetStream(ns1)
http_stream = new URLStream();
http_stream.addEventListener(ProgressEvent.PROGRESS, on_Progress)
http_stream.load(new URLRequest(stream))
http_stream1 = new URLStream();
//http_stream1.addEventListener(ProgressEvent.PROGRESS, on_Progress1)
http_stream1.load(new URLRequest(stream1))
function on_Progress(e:ProgressEvent):void {
var b:ByteArray = new ByteArray()
http_stream.readBytes(b, 0, http_stream.bytesAvailable)
ns.appendBytes(b)
var b1:ByteArray = new ByteArray()
http_stream1.readBytes(b1, 0, http_stream1.bytesAvailable)
ns1.appendBytes(b1)
if (ns.appendBytes(b)==ns1.appendBytes(b1)){
ns.play(stream);
ns1.play(stream1);
}
}
答案 0 :(得分:0)
为什么不检查 how much of each video has loaded ,当你有足够的金额(你决定)时,你可以运行一些功能来播放两个网络流...
StreamReader
还有关于progressEvent函数的加载(URLloader或URLstream ???)..
var min_amount : int = 500000; //for 500 kb minimum
var check_if_ready : Boolean = true;
仅当两个视频都加载了x个字节时才会播放。因此,你可以确定没有一个在另一个之前开始)
为了更好地进行同步控制,您应该使用if ( check_if_ready == true )
{
if( myA_NetStream.bytesLoaded >= min_amount && myB_NetStream.bytesLoaded >= min_amount )
{
myA_NetStream.play(); myB_NetStream.play();
//reset since not needed on further progressEvents during this load
check_if_ready = false;
}
}
}
方法处理Flash / AS3中的字节,因为这样您就可以逐帧控制两个NetStream的播放。