Jump to content
Search Community

VideoLoader dispose() bug?

patrick.welborn test
Moderator Tag

Recommended Posts

After having experimented with several VideoLoader load and unload techniques outlined in the forum I am still stuck on a troublesome video playback problem.

 

When the following actions are taking, I get 'phantom' video playback.

1. set active = true to instantiate loaders

2. Loader onComplete displays video

3. set active = false to dispose loaders

4. again set active = true to re-instantiate loaders

5. Loader onComplete does not display video, but video's audio plays back.

6. again set active = false and loaders do not dispose

 

I have been held up on this for sooooo many hours. Suggestions?

 

package com.lightpail.view.component.region
{
import com.greensock.*;
import com.greensock.events.*;
import com.greensock.loading.*;
import com.greensock.loading.core.*;
import com.greensock.loading.data.*;
import com.greensock.loading.display.*;

import flash.display.Loader;
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.DisplayObject; 
import flash.events.DataEvent;
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.media.SoundMixer;
import flash.media.SoundTransform;
import flash.media.Video;

public class GlobalPresence extends MovieClip 
{ 
	public static const NAME:String = "GlobalPresence";
	public static const SWF_SUB_LOADER:String = "SWFSubLoader";

	private var _active:Boolean = new Boolean();

	public function GlobalPresence():void 
	{ 
		LoaderMax.activate([imageLoader, VideoLoader]);

	}

	public function get active():Boolean
	{
		return _active;
	}

	public function set active(value:Boolean):void
	{
		switch(value){
			case true:
				this.visible = true;
				this.alpha = 1;
				var globalPresenceBackground:ImageLoader = new ImageLoader("assets/image/global_presence_background.png", 
					new ImageLoaderVars()
					.name("global_presence_background")
					.onComplete(globalPresenceBackgroundComplete)
					.x(0)
					.y(0)
					.width(1280) 
					.height(720) 
					.requireWithRoot(this.root)
				); 

				globalPresenceBackground.load(); 

				break;
			case false:
				this.visible = false; 
				this.alpha = 0; 
				for(var i:int = this.numChildren; i>0; i--){
					var mediaAsset:* = this.getChildAt(i-1);
					if(mediaAsset.toString() == "[object ContentDisplay]"){
						switch(mediaAsset.rawContent.toString()){
							case "[object Video]":
								trace(NAME + mediaAsset.rawContent.toString());
								mediaAsset.loader.pauseVideo();
								mediaAsset.loader.dispose(true, true);

								break;
							case "[object Bitmap]":
								trace(NAME + mediaAsset.rawContent.toString());
								this.removeChildAt(i-1);

								break;
						}
					}
				} 

				break;

			_active = value;
		}
	}

	private function progressUpdate(event:LoaderEvent)
	{
		dispatchEvent(new DataEvent(SWF_SUB_LOADER, true, false, event.target.progress));
	}

	private function globalPresenceBackgroundComplete(event:LoaderEvent)
	{
		addChildAt(event.target.content, 0);

		var globalPresenceVideo:VideoLoader = new VideoLoader("assets/video/global_presence.flv",  
			new VideoLoaderVars() 
			.autoPlay(true)
			.alpha(1)
			.width(1280)
			.height(480)
			.name("global_presence_video")
			.onComplete(globalPresenceVideoComplete)
			.requireWithRoot(this.root)
			.scaleX(1.07)
			.scaleY(1.07)
			.volume(1)
			.x(-67)
			.y(111)
		);
		globalPresenceVideo.load();
	}

	private function globalPresenceVideoComplete(event:LoaderEvent):void
	{
		addChildAt(event.target.content, 1);
		event.target.content.loader.gotoVideoTime(0, true);
	}

}
}

Link to comment
Share on other sites

I noticed a few things:

 

1) You're not disposing the loader correctly - you called mediaAsset.loader.dispose(true, true) but I think you meant mediaAsset.dispose(true, true). The loader's dispose() method only accepts one parameter whereas the ContentDisplay's dispose() method accepts 2. Your code should actually generate runtime errors because of the mismatched number of arguments.

 

2) I would strongly suggest making this change:

 

BAD:

if (mediaAsset.toString() == "[object ContentDisplay]") {
switch (mediaAsset.rawContent.toString()) {
	case "[object Video]" :
		mediaAsset.loader.pauseVideo();
		mediaAsset.loader.dispose(true, true);
		break;
	case "[object Bitmap]" :
		this.removeChildAt(i-1);
		break;
}
}

 

GOOD:

if (mediaAsset is ContentDisplay) {
if (mediaAsset.loader is VideoLoader) {
	mediaAsset.loader.pauseVideo();
	mediaAsset.loader.dispose(true);
} else if (mediaAsset.loader is ImageLoader) {
	this.removeChild(mediaAsset);
}
}

 

If you make the above fixes and the video still isn't showing, try adding a trace() to the globalPresenceVideoComplete() method to see if it's getting called at all. If it is, you must have a problem with how you're adding the content to the stage. You're adding it at index 1 always, so if there's something on top of that, it would explain why you're not seeing the video. If you still need help, please post a sample FLA (and support files) that demonstrates the problem so that I can publish it on my end and see what's going on.

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...