I get a problem with my stream when I try to load multiple flvs at the same time. Everything works fine if I only load a couple of flvs but when I try to load more than 4 it seems like they get mixed up. OK, I know this is probably not the best explanation but I'm not sure how to describe it better.
In my Flash file I have 2 video controls layered on top of each other and I'm loading an flv into each of them and when these are finished I load another set of flvs (se my code snippets for more info).
If you know how I can do this better please let me know. And last I can just say that my AS code works when I run it in Flash player, which makes me think it has something to do with how I load the streams in my C# code and how the F in box control handles the streams.
Here's my relevant code:
ActionScript:
Code: Select all
var videosPath:String = "http://FLV/";
var videos:Array = new Array("0001MNS01.flv", "0000MNL03.flv", "0003MNI01.flv", "0003MNL01.flv", "0003MNO01.flv", "0000MNL03.flv", "0002MNS01.flv");
var markings:Array = new Array("0001TNS01.flv", "", "", "", "", "", "0002TNS01.flv");
var duration:Number = 0;
var timePlayed:Number = 0;
var ratio:Number = 0;
var id:Number = 0;
var ready:Boolean = true;
if (videos.length > 0) {
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
videoPlayer.attachVideo(ns);
var nc2:NetConnection = new NetConnection();
nc2.connect(null);
var ns2:NetStream = new NetStream(nc2);
markingsVideoPlayer.attachVideo(ns2);
if (videos[currentVideo] != ""){
ns.play(videosPath + videos[currentVideo]);
}
if (markings[currentVideo] != ""){
ns2.play(videosPath + markings[currentVideo]);
}
ns.onMetaData = function(evt:Object):Void {
duration = evt.duration;
id = setInterval(function ():Void {
track._width = (ns.time*ratio)+(timePlayed*ratio)+1;
}, 50);
ready = true;
}
ns.onStatus = function(evt:Object):Void {
if (ready && this.time>0 && this.time>=(duration-0.5)) {
ready = false;
clearInterval(id);
timePlayed += duration;
trace("timePlayed: "+timePlayed);
currentVideo++;
if (currentVideo<videos.length) {
ns.play(videosPath + videos[currentVideo]);
if (markings[currentVideo] != ""){
ns2.play(videosPath + markings[currentVideo]);
}else{
ns2.close();
markingsVideoPlayer.clear();
}
} else {
delete this.onStatus;
play(); //Move to next scene
}
}
}
} else {
play(); //Move to next scene
}
C#:
Code: Select all
private void OnLoadExternalResourceByFullPath(object sender, String URL, System.IO.Stream Stream, ref bool Handled)
{
string tempString = Application.StartupPath + "\\VideoData\\" + URL.Substring(11);
System.IO.FileStream FLVStream = System.IO.File.OpenRead(tempString);
const int size = 64 * 1024;
byte[] buffer = new byte[size];
int ReadBytes;
while ((ReadBytes = FLVStream.Read(buffer, 0, size)) > 0)
{
try
{
Stream.Write(buffer, 0, size);
}
catch (System.IO.IOException e)
{
MessageBox.Show(e.ToString());
break;
}
}
Stream.Close();
Handled = true;
}