Jump to content
Search Community

Sound fails when preloading multiple videos with VideoLoader

burvs test
Moderator Tag

Recommended Posts

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

Link to comment
Share on other sites

the Flash Player has a sound channel limit of 32. weird that you are getting cut off at 30. do you have other sounds playing that aren't from flvs?

 

 

SoundChannel — A SoundChannel object, which you use to control the sound. This method returns null if you have no sound card or if you run out of available sound channels. The maximum number of sound channels available at once is 32.

http://help.adobe.com/en_US/FlashPlatfo ... html#play()

 

perhaps unloading flvs after they are played might help.

Link to comment
Share on other sites

Hi Carl,

 

Aha that would make a great deal of sense. It does cut off at around 32 I think.

 

I did discover today that if I first preload all my videos using Videoloader, and then once they are loaded, loop through them and call close() on each netStream, I can then call load on them again when they are required, and because they are cached they will then play instantly with the audio intact.

 

So yes, too many concurrent sound channels makes sense. I had thought that perhaps there were some kind of upper limit on netstreams.

 

In my case I've decided not to preload my videos at all. I can live with the tiny buffering delay I get when trying to load them. It's barely noticeable.

Link to comment
Share on other sites

  • 2 weeks later...

Thank you for this post. I was banging my head against the wall trying to figure out why, after a certain point, sounds stopped working. I'd rather not change the way I load and manage assets (I don't want to unload & reload videos as I need them to play instantly upon request). Is the Sound Channel limitation only active sound channels? Is there a way, perhaps, to free up the video sound channels unless the video is actively playing?

Link to comment
Share on other sites

I may have found a fix!!!

 

I can't say whether or not there are side-effects, but I haven't found any yet. After loading all my assets (videos & sounds), I call

SoundMixer.stopAll();

. This seems to free up the sound channels that were being held by the videos.

So far, this doesn't seem to keep the video sound from playing when the video is playing.

 

Please let me know if this fix works for you, or if you find any side-effects.

 

Greensock, I'm not sure if the SoundChannel being held by video is a side-effect of Flash's native netStream stuff or something specific to VideoLoader, but it seems like this fix is the sort of thing that should be integrated into the LoaderMax library at some point.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...