Jump to content
GreenSock

failure13

Not quite sure about video...

Recommended Posts

I got this code here...And i feel kinda konfused, coz my logic is running through all of this functions (which are a lot in complete videoplayer code), but with loaderMax video loader, it seem that at least 50% of this code could done with just few lines...

I really used to netStream so much, and it's hard to switch for something new, simple, and a bit different...

// url to video file

var strSource:Object = ("system/intro/Moscow.mp4");
// net connection object for net stream
var ncConnection:NetConnection;
// net stream object
var nsStream:NetStream;
// flag for flv has been loaded
var bolLoaded:Boolean = false;

// start intro video loading
initVideoPlayer();

// sets up the player
function initVideoPlayer():void {
// create a new net connection
ncConnection = new NetConnection();
ncConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
ncConnection.connect(null);
// create a new netstream with the net connection
nsStream = new NetStream(ncConnection);
nsStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nsStream.client = this;
nsStream.bufferTime = 8;
// attach net stream to video object on the stage
introVideo.vidDisplay.attachNetStream(nsStream);
// set the smoothing value from the constant
introVideo.vidDisplay.smoothing = true;
// check if video loaded
if(!bolLoaded) {
	// load stream
	nsStream.play(strSource);
	bolLoaded = true;
}
else {
	// start playing intro video
	playIntro();
}
}

// play video
function playIntro():void {
if(bolLoaded) {
	// play
	nsStream.resume();
	// call resize function
	MovieClip(parent).onResize(null);
}
}

 

How would it be right, and most efficent to rewrite such a simplifyed piece for loaderMax?

 

And also i'm interested, if loaderMax have smoothing on or off by default?

And if it doesn't have, then how to force it?

Link to comment
Share on other sites

Well, it looks like you're only showing part of the code and that you've got a Video object on the stage somewhere to which you're trying to attach the NetStream, but VideoLoader simplifies all of that for you by creating its own Video object in a ContentDisplay object that it can place on the stage for you - you just define a "container" and it'll drop it in there (see the docs for specifics). However, this should get you close (assuming you want to keep the same function names and general functionality):

 

var video:VideoLoader;

function initVideoPlayer():void {
if (video == null) {
	video = new VideoLoader("system/intro/Moscow.mp4", {bufferTime:8, container:this});
	video.load();
} else {
    playIntro();
}
}

function playIntro():void {
if(video != null) {
	video.playVideo();
	MovieClip(parent).onResize(null);
}
}

Link to comment
Share on other sites

Thank you!

You get it right, i've got an object on stage with my previous code, so this is kinda great help to know that LoaderMax creates container with it's built in code so easily!

 

So i come to this kind of code now, for a simple intro video:

// create video loader & specify it's parameters
var introVideo:VideoLoader = new VideoLoader("system/intro/Moscow.mp4", {
bufferTime: 8,
container: this,
width: stage.stageWidth,
height: stage.stageHeight,
centerRegistration: true,
onComplete: playIntro,
onError: videoOver
});
// load video
introVideo.load();
// add event listener for video complete
introVideo.addEventListener(VideoLoader.VIDEO_COMPLETE, videoOver);

function playIntro(e:LoaderEvent):void {
// call resize function
MovieClip(parent).onResize(null);
}

function videoOver(e:LoaderEvent):void {
// load presentation
MovieClip(parent).gotoAndPlay("start");
// remove video complete listener
introVideo.removeEventListener(VideoLoader.VIDEO_COMPLETE, videoOver);
// unload & remove video loader
introVideo.unload();
introVideo.dispose(true);
}

 

And i got a few questions:

1. videoOver function is dedicated to go on "start frame", and completely unload everything that was created above, did i manage to unload everything right way? Do i need also to remove listeners attached to introVideo, or they will be removed automatically with .unload and .dsipose?

2. I have onError specified, which according to documentation, should fire whenever any error will happen, include I/O, did i get it right? (it's really cool feature then, if it's ultimate error reference!))

3. So, video and image smoothing is on by defaul, rightt?

4. I've read on some tutorial this:

Automatically adjust buffer. We can set the bufferTime initially and then if it empties during playback, VideoLoader can automatically analyze the speed at which the file has been loading and adjust the bufferTime accordingly to ensure that playback doesn't stop/start/stop/start on slow connections.

What it is, and how exactly to use it? Sounds tasty! But how much efficent this method is?

5. This function here MovieClip(parent).onResize(null); calls for my global resize function, which looks like this:

stage.addEventListener(Event.RESIZE, onResize);


function onResize(event:Event):void {
// get current stage size
stageW = stage.stageWidth;
stageH = stage.stageHeight;
// center intro
if (intro != null) {
	intro.x = stageW * 0.5;
	intro.y = stageH * 0.5;
	// resize intro video if it exist
	if (intro.video != null) {
   	 resizeMe(intro.introVideo.content, stageW, stageH);
	}
}
}[/quote]
+ famous contrain resize function...
[quote]
// proportional resize helper function
function resizeMe(mc:MovieClip, maxW:Number, maxH:Number=0):void {
maxH = maxH == 0 ? maxW : maxH;
mc.width = maxW;
mc.height = maxH;
mc.scaleX < mc.scaleY ? mc.scaleY = mc.scaleX : mc.scaleX = mc.scaleY;
}

So whenever resize occurs, of course i got:

TypeError: Error #1034: Error type Coercion: can not convert com.greensock.loading::VideoLoader@2f063101 in flash.display.MovieClip.

Of course, coz this is Loader, not movieclip....

Which is the easyest and most efficent way to get past this error?

 

I was thinking to try different scaleMode properties inside VideoLoader itself and just write:

intro.introVideo.content.width = stageW;
intro.introVideo.content.height = stageH;

But there are no mode, which would keep pixel proportion, like resizeMe function do...

So any advice here would be appreciated! :)

Link to comment
Share on other sites

1. videoOver function is dedicated to go on "start frame", and completely unload everything that was created above, did i manage to unload everything right way? Do i need also to remove listeners attached to introVideo, or they will be removed automatically with .unload and .dsipose?

Yes, all you need to do is call dispose(true). That unloads it too. If you manually add any event listeners to the VideoLoader, you do need to remove those yourself. It looks like you did that.

 

 

2. I have onError specified, which according to documentation, should fire whenever any error will happen, include I/O, did i get it right? (it's really cool feature then, if it's ultimate error reference!))

Yes, all errors will go to the onError handler. It is indeed meant to be a convenient way to centralize all error handling/notification.

 

3. So, video and image smoothing is on by defaul, rightt?

Yes.

 

4. I've read on some tutorial this:

 

Automatically adjust buffer. ...

What it is, and how exactly to use it? Sounds tasty! But how much efficent this method is?

You don't have to do anything special for this - it is enabled by default. As far as efficiency, it's extremely efficient. The small chunk of logic that does the adjusting only runs if/when the buffer empties. It then changes the bufferTime and that's it. Almost no CPU load.

 

5. This function here MovieClip(parent).onResize(null); calls for my global resize function, which looks like this...

 

You could simply change the data type of your mc variable to DisplayObject, like:

function resizeMe(mc:DisplayObject, maxW:Number, maxH:Number=0):void {
   ...
}

 

But also keep in mind that VideoLoader already has that kind of functionality built-in, so that you can tell it an area to fit the video into and it'll scale it proportionally inside that area (or fill it and crop the overflow). That's what the scaleMode is for. Read the docs for the ContentDisplay object. And if you want to set the fit area after you create the VideoLoader, you can simply use the "fitWidth" and "fitHeight" properties of the ContentDisplay and it'll automatically adjust everything dynamically for you.

 

I hope that helps!

Link to comment
Share on other sites

4. You mean, if i'll get rid of this bufferTime: 8,inside my VideoLoader - it will automatically do all the buffer thing to reduce stutter or too early start of video? O_O

WOW! I mean, WOW!!!!

5. I suppose you meant like this?

add scaleMode: "proportionalInside"

function onResize(event:Event):void {

// get current stage size

stageW = stage.stageWidth;

stageH = stage.stageHeight;

// center intro

if (intro != null) {

intro.x = stageW * 0.5;

intro.y = stageH * 0.5;

// resize intro video if it exist

if (intro.video != null) {

intro.introVideo.content.fitWidth = stageW;

intro.introVideo.content.fitHeight = stageH;

}

}

}

This seem to work...And seem to work more than good!

Hell, where have loaderMax been, when i was writing such a functions?! :D

 

//////////////////////////////// STAGE RESIZE ///////////////////////////////////

 

function onResize(event:Event):void {

if ((stage.stageWidth / stage.stageHeight) <= 1.40 ) {

/////////////////// REACTION ON 4 / 3 TYPE DISPLAYS ///////////////////

 

if ((videoW / videoH) >= 1.41 ) {

// size up video display for 16 / 9 type videos

vidDisplay.width = stage.stageWidth;

vidDisplay.height = (stage.stageHeight) - ((stage.stageHeight / (videoW / videoH)) * 0.5);

}

 

if ((videoW / videoH) <= 1.40 ) {

// size up video display for 4 / 3 type videos

vidDisplay.width = stage.stageWidth;

vidDisplay.height = (stage.stageHeight) - (stage.stageHeight - (stage.stageWidth / (videoW / videoH)));

}

}

if ( 1.41 <= (stage.stageWidth / stage.stageHeight)) {

/////////////////// REACTION ON 16 / 9 TYPE DISPLAYS ///////////////////

 

if ((videoW / videoH) >= 1.41) {

// size up video display for 16 / 9 type videos

vidDisplay.width = stage.stageWidth;

vidDisplay.height = (stage.stageHeight) - (stage.stageHeight - (stage.stageWidth / (videoW / videoH)));

}

 

if ((videoW / videoH) <= 1.40) {

// size up video display for 4 / 3 type videos

vidDisplay.width = (stage.stageWidth) - (stage.stageWidth - (stage.stageWidth / (videoW / videoH)));

vidDisplay.height = stage.stageHeight;

}

}

videoPostition();

}

This was really hard and creative back in a day...But i guess now i can throw it in garbage, coz your function for sure is much more efficent! :D

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