This is a strange one, and I'm running out of ideas for a solution.
I've got 67 small flvs (between 60k - 150k each) and I'm trying to preload them all in one go so that I can then play them instantly as required.
The below appears to work absolutely fine, correctly loading them all, and cycling through playing each one on the click of a button. EXCEPT that the very first one, and all of the ones above about number 30, are not playing their audio.
I know the audio is correctly in place on all the latter videos, as if I reduce the number of videos and just load the latter bunch, the audio works fine. Equally if I only load the first 30, then the audio of the very first one plays fine.
I've tried splitting the loading into two different queues, each with it's own LoaderMax instance, and loading one queue after the other has finished, but the same thing happens.
It's as if there is some maximum number of NetStreams Flash can handle before the audio starts screwing up on some of them.
Am I expecting too much to want to preload so many flvs (even though they are all pretty small)?
Any ideas of what I could try next? Or any other approaches to my problem that might work?
Many thanks!
package {
import com.greensock.events.LoaderEvent;
import com.greensock.loading.LoaderMax;
import com.greensock.loading.VideoLoader;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.media.SoundTransform;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
[sWF(backgroundColor = "#999999", frameRate = "40", width = "400", height = "300")]
public class VidTest extends Sprite {
private var _button : Sprite;
private var _vidHolder : Sprite;
private var _currentVid : int = 1;
private var _myVidLoader : VideoLoader;
private var _queue : LoaderMax;
public function VidTest() {
drawButton();
_vidHolder = new Sprite();
addChild(_vidHolder);
_vidHolder.x = 50;
_vidHolder.y = 50;
_queue = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});
for (var i : int = 1; i <= 67; i++) {
_queue.append(new VideoLoader("vid" + i + ".flv", {name:"vid" + i, autoPlay:false, volume:1}));
}
// start loading the LoaderMax queue
_queue.load();
}
private function completeHandler(event : LoaderEvent) : void {
trace('completeHandler: ');
addChild(_button);
_currentVid = 1;
onClickButton(null);
}
private function onClickButton(event : MouseEvent) : void {
trace('onClickButton: ' + (onClickButton));
if (_myVidLoader) _myVidLoader.pauseVideo();
_myVidLoader = LoaderMax.getLoader("vid" + _currentVid);
trace('_currentVid: ' + (_currentVid));
while (_vidHolder.numChildren) {
_vidHolder.removeChildAt(0);
}
_vidHolder.addChild(_myVidLoader.content);
_myVidLoader.volume = 1;
_myVidLoader.gotoVideoTime(0);
_myVidLoader.playVideo();
if (_currentVid < 67) {
_currentVid++;
} else {
_currentVid = 1;
}
}
private function progressHandler(event : LoaderEvent) : void {
trace("progress: " + event.target.progress);
}
private function errorHandler(event : LoaderEvent) : void {
trace("error occured with " + event.target + ": " + event.text);
}
private function drawButton() : void {
_button = new Sprite();
_button.graphics.beginFill(0xff9900);
_button.graphics.drawCircle(0, 0, 50);
_button.addEventListener(MouseEvent.CLICK, onClickButton);
_button.x = 10;
_button.y = 10;
}
}
}