Jump to content
GreenSock

Esseti

LoaderMax and StageVideo

Recommended Posts

Hi.

I've been trying to replace the default way of loading video in my website by NetConnections and NetStreams with LoaderMax, and it works great, but I also want to use StageVideo if the user can run it.

 

Could anyone write a quick tutorial on how to use LoaderMax just to load the data (becase now it also automatically creates a sprite and displays the video with the new Video(); class, which is CPU heavy), and attach it to my StageVideo object? I know that there is a myVideoLoader.netStream property, but when I attach it with myStageVideo.attachNetStream(myVideoLoader.netStream); it doesn't work.

 

Thanks.

Link to comment
Share on other sites

VideoLoader doesn't directly support StageVideo yet and I don't have time right now to try to wire together an example for you that leverages the raw NetStream object, but I'm not aware of any reasons why it wouldn't work (if anyone else knows otherwise, please chime in). I think you need to make sure that the actual player/device supports StageVideo at runtime - maybe you're testing where it's not supported? And of course make sure you're publishing to a version of the Flash Player that supports it.

Link to comment
Share on other sites

It does support it, because it was working when I was loading the video with standard NetConnection and NetStream.

 

I've made a small example of what is going on.

import com.greensock.loading.LoaderMax;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.VideoLoader;
import com.junkbyte.console.Cc;
import flash.events.StageVideoAvailabilityEvent;
import flash.media.StageVideoAvailability;
import flash.media.StageVideo;
import flash.net.NetStream;
stage.align = StageAlign.TOP_LEFT;
Cc.startOnStage(this, "");
var stageVideo:StageVideo;
var videoLoader:VideoLoader;
stage.addEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY, checkVideoMode);
function checkVideoMode(e:StageVideoAvailabilityEvent):void {
e.target.removeEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY, checkVideoMode);
var sv:Boolean = e.availability == StageVideoAvailability.AVAILABLE;
if (sv) {
 Cc.log("STAGE_VIDEO");
 setStageVideo();
} else {
 Cc.log("VIDEO");
 setVideo();
}
}
function setStageVideo():void {
videoLoader = new VideoLoader("video/trailer.mp4", {container:this, width:1280, height:720});
videoLoader.load();
videoLoader.content.x = 300;
var v:Vector.<StageVideo> = stage.stageVideos;
stageVideo = v[0];
stageVideo.viewPort = new Rectangle(0, 0, 1280, 720);
stageVideo.attachNetStream(videoLoader.netStream);
}
function setVideo():void {
videoLoader = new VideoLoader("video/trailer.mp4", {container:this, width:1280, height:720});
videoLoader.load();
}

Source files - http://malylink.pdg.pl/misc/example.rar

#WARNING: you must run this in a browser, because StageVideo will never work in Flash IDE.

 

When you run this in the browser, it will detect that it can handle StageVideo, and will run the setStageVideo(), and the code there for StageVideo works, if the NetStream is setup by the old method. But by passing the videoLoader.netStream to the stageVideo.attachNetStream(); it doesn't work. When you run this, there will be video playing, but in Video() mode from the VideoLoader class., not from the code that I've written below the videoLoader. I've offsetted the videoLoader.x by 300px, so that you could see if there is video loaded to the stageVideo object.

Link to comment
Share on other sites

Ah yes, apparently StageVideo won't work if the NetStream also gets attached to a regular Video. I just uploaded a new version of VideoLoader that allows you to define a "stageVideo" property. If you do, it'll attachNetStream() to the StageVideo rather than the regular Video object. Please let me know if that works well for you (I tested it in your example file and it seemed to work great).

Link to comment
Share on other sites

AWESOME it works!

Here's the code for future reference.

 

import com.greensock.loading.VideoLoader;
import flash.events.StageVideoAvailabilityEvent;
import flash.media.StageVideoAvailability;
import flash.media.StageVideo;
stage.align = StageAlign.TOP_LEFT;
var stageVideo:StageVideo;
var videoLoader:VideoLoader;
stage.addEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY, checkVideoMode);
function checkVideoMode(e:StageVideoAvailabilityEvent):void {
e.target.removeEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY, checkVideoMode);
var sv:Boolean = e.availability == StageVideoAvailability.AVAILABLE;
if (sv) {
 setStageVideo();
} else {
 setVideo();
}
}
function setStageVideo():void {
var v:Vector.<StageVideo> = stage.stageVideos;
stageVideo = v[0];
stageVideo.viewPort = new Rectangle(0, 0, 1280, 720);
videoLoader = new VideoLoader("video/trailer.mp4", {container:this, width:1280, height:720});
videoLoader.stageVideo = stageVideo;
videoLoader.load();
}
function setVideo():void {
videoLoader = new VideoLoader("video/trailer.mp4", {container:this, width:1280, height:720});
videoLoader.load();
}

And remember, thatn StageVideo won't work in Flash IDE Debug, and you have to set wmode="direct" in your html template.

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