Forum Multiplayer NetConnection Inside Connection

Discussion and help relating to the PlayerIO Multiplayer API.

NetConnection Inside Connection

Postby AK712 » April 1st, 2017, 10:27 pm

So I have been trying to get a video to be embedded in my game within a room. It works when it initially starts the game, but the moment it goes inside a room, it just breaks the game. The video won't play and all multiplayer aspects stop. I'm attempting to use NetConnection and NetStream, and I'm guessing that the playerio.Connection just won't allow it. How would I get this to work? Here's a bit of the code:

Code: Select all
import flash.media.Video
import flash.net.NetConnection
import flash.net.NetStream

...
public var connectz:NetConnection = new NetConnection()
public var streamz:NetStream
public var metaData:Object = new Object()
public var theVideo:Video = new Video(800,600)

function MainGame(){
stop()
PlayerIO.connect(stage,"testgame-blahblahblah","public","GuestUser","",null,handleConnect,handleError);
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyIsDown)
stage.addEventListener(KeyboardEvent.KEY_UP,keyIsUp)
stage.addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown)
stage.scaleMode = StageScaleMode.NO_SCALE
stage.align = StageAlign.TOP_LEFT
}

private function handleConnect(pclient:playerio.Client):void
{
pclient.multiplayer.developmentServer = "127.0.0.1:8184";
pclient.multiplayer.createJoinRoom("TestRoom","TestRoom",true,{},{},handleJoin,handleError);
}

private function handleJoin(connection2:playerio.Connection):void
{
gotoAndStop("game")
pioConn = connection2
connectz.connect(null)
streamz = new NetStream(connectz)
streamz.client = metaData
theVideo.attachNetStream(streamz)
streamz.play("BGM.mp4")
addChild(theVideo)

...
Last edited by AK712 on July 1st, 2017, 4:47 pm, edited 1 time in total.
User avatar
AK712
 
Posts: 34
Joined: May 2nd, 2012, 12:43 am

Re: NetConnection Inside Connection

Postby Henrik » April 3rd, 2017, 1:58 am

I'm pretty sure you won't be able to receive messages until the success callback for CreateJoinRoom has finished executing, and the way you've structured your code, you are essentially waiting for the video to finish playing before letting it finish.

You should do the least amount of work possible in the success callback, just setting up your message event handlers essentially, and let it finish. Then you have to signal your game to start the video playback on a different thread, I don't know exactly what the best solution for that would be, move to a frame that triggers it perhaps?
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: NetConnection Inside Connection

Postby AK712 » July 1st, 2017, 4:46 pm

So I've tried what you suggested. I instead made a button to start the video. If the mouse is in the coordinates of the button, it sends a message to the server, which then sends back "startVideo" with "1" as the message parameter. Here's the code on the client:

Code: Select all
pioConn.addMessageHandler("startVideo", function(m:Message, d:int)
         {
             connectz.connect(null)
            streamz = new NetStream(connectz)
            streamz.client = metaSniffer
            theVideo.attachNetStream(streamz)
            trace("1")
            streamz.play("BGM.flv")
            trace("2")
            addChildAt(theVideo,0)
         })


trace("1") shows up; trace("2") does not. The video does not play. I'm rather confused as to why this doesn't work, since the exact same code works if I just put it inside a normal function. You'll also notice I tried making it a .flv instead, but that didn't change anything.
User avatar
AK712
 
Posts: 34
Joined: May 2nd, 2012, 12:43 am

Re: NetConnection Inside Connection

Postby Henrik » July 2nd, 2017, 4:18 am

Well, if the video doesn't play, you're probably getting an exception, which explains why you're not reaching the trace 2 statement, so try/catch the play statement and see what happens?
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm


Return to Multiplayer



cron