Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Can I make a dynamic video player stop just by exiting the frame and entering a new one?

Community Beginner ,
Nov 22, 2014 Nov 22, 2014

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();

  }

}

TOPICS
ActionScript
342
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 23, 2014 Nov 23, 2014

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 23, 2014 Nov 23, 2014
LATEST

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines