Copy link to clipboard
Copied
Ok so I have a flash presentation with a video clip which I am playing dynamically using a URL netStream. The problem is not getting it to play but rather getting it to stop playing. If I click the stop button, it stops, But if I just navigate to a new frame, the video disappears but I can still hear the audio. (the only reason it disappears is because i used "video.visible = false" on all other frames other than the one I need it to play on. Additionally, If I navigate to a new frame while the video is playing, I cannot stop it or restart if I return back to the frame that the video is located on. Its like all my video control buttons are rendered useless if I leave the frame while it is playing. Do I need some sort of eventlistener or custom function? I hope I explained that well enough.
Here is my code if anyone has any suggestions.
Thanks!
//video code
var video:Video = new Video(480,204);
video.y = stage.stageHeight / 2 - 278 / 2;
video.x = stage.stageWidth / 2 - 290 / 2;
addChild(video);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, onStatusEvent);
function onStatusEvent(stat:Object):void
{
trace(stat.info.code);
}
var meta:Object = new Object();
meta.onMetaData = function(meta:Object){
trace(meta.duration);
};
ns.client = meta;
video.attachNetStream(ns);
btn_playvid.addEventListener(MouseEvent.CLICK, playFunction);
function playFunction(evt:MouseEvent):void
{
ns.play("assets/movie.mp4");
}
btn_stopvid.addEventListener(MouseEvent.CLICK, stopFunction);
function stopFunction(evt:MouseEvent):void
{
ns.pause();
}
}
Copy link to clipboard
Copied
You need to call your stopFunction if you leave the frame as the video will continue to play. When you come back to this frame, you're creating a new video instance and NetStream, etc... If you place your video at a random x,y you should see that you have multiple video instances. You need to separate your init code from your control code.
Copy link to clipboard
Copied
ok so, for every button that takes me to a different part of the presentation I added a "ns.pause();" to the button function. This makes the video stop, however, if i return to the frame containing the video, I am unable to press play and restart it. Do I need to do something with the netStream on this frame?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now