Skip to main content
April 22, 2010
Question

play 2 rtmp videos at the same time problem

  • April 22, 2010
  • 1 reply
  • 1958 views

Hi!

My swf is playing one video in using NetConnection, NetStream and Video object. If I want to stream one more video simultaneously in the same swf I have a few problems. It works when I create more NetConnection, NetStream and Video objects but is that necessary? The code rapidly becomes complex to handle.

Is there an easier way like perhaps share the NetConnection, or something (same FMS server)?

Question 2

The two videos on the stage are suppose to have different size, placement etc. Still the last one created inherit the properties of the first video display. It also starts playing for an annoying couple of seconds before the first one. How can I avoid that (inherit and delay)?

Thanks for any feedback.

G

var ns1:NetStream;
var ns2:NetStream;

var nc1:NetConnection = new NetConnection();
var nc2:NetConnection = new NetConnection();

nc1.connect("rtmp://my.fms/vod");
nc2.connect("rtmp://my.fms/vod");

var meta1:Object = new Object();
var meta2:Object = new Object();

var cuep1:Object = new Object();
var cuep2:Object = new Object();

var vid1:Video = new Video(550,310);
var vid2:Video = new Video(100,80);

addChild(vid1);
addChild(vid2);

vid2.x = 170;
vid2.y = 320;

nc1.addEventListener(NetStatusEvent.NET_STATUS, onStatusEvent1);
nc2.addEventListener(NetStatusEvent.NET_STATUS, onStatusEvent2);

function onStatusEvent1(stat:Object):void {
     switch (stat.info.code) {
          case ("NetConnection.Connect.Success") :
               ns1 = new NetStream(nc1);
               ns1.client = meta1;
               vid1.attachNetStream(ns1);
               ns1.play("sample");
               break;
     }
}
function onStatusEvent2(stat:Object):void {
     switch (stat.info.code) {
          case ("NetConnection.Connect.Success") :
               ns2 = new NetStream(nc2);
               ns2.client = meta2;
               vid2.attachNetStream(ns2);
               ns2.play("Legend");
               break;
     }
}
meta1.onMetaData =  metadataHandler;
cuep1.onCuePoint = cuepointHandler;

meta2.onMetaData =  metadataHandler;
cuep2.onCuePoint = cuepointHandler;

function metadataHandler(metadataObj:Object):void {
     //trace("Clip duration:  "+metadataObj.duration);
}
function cuepointHandler(cuepointObj:Object):void {
     //trace("CuePoints:  "+cuepointObj);
}
nc1.addEventListener(AsyncErrorEvent.ASYNC_ERROR, dummyFunc);
nc2.addEventListener(AsyncErrorEvent.ASYNC_ERROR, dummyFunc);
function dummyFunc(dummy:AsyncErrorEvent) {
     //trace("AsyncError dummyevent fired: "+dummy);
}

    This topic has been closed for replies.

    1 reply

    Participating Frequently
    April 22, 2010

    I tried your code and it seem to work fine for me, not any issues which you mentioned.

    You can share NetConnection across different NetStreams but you will have to create "n" number of NetStreams if you want to play that "n" streams simultaneously.And of course "n" number of video objects to display it.

    April 22, 2010

    Thanks, but could you please check again. And check the part:

    var vid1:Video = new Video(550,310);
    var vid2:Video = new Video(100,80);

    vid2 is suppose to be smaller but no matter what the stay the same size as the first one initialized. In this case vid2. Are you experiencing the same?

    Thanks

    G

    Participating Frequently
    April 22, 2010

    In my case, i see videos of different size as expected, second one is much smaller then first one. Also both seem to start at almost same time. Only thing i can say is i am using CS4 (and you must be using CS3 - i am saying based on your older posts) - but really that should not make difference - provided there is no such bug in CS3