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

Actionscript 3 livestream client unpublish / publish

New Here ,
Apr 25, 2014 Apr 25, 2014

I am creating a 1-to-many webcam chat application. The publisher part is all done and working. But the viewers part has some really weird quirks. I have tried all kinds of fixes, but nothing seems to work. The problem is in IE only and not in other browsers. There it is working properly. The problem is as follows. When someone is publishing a webcam, a viewer can watch the webcam. When the publisher decides to stop publishing, the NetStream is closed by NetStream.close() on the publishers part. The viewer gets a notification by the NetStatusEvent of NetStream.Play.Stop and NetStream.Play.UnpublishNotify. After the buffer has become empty. Nothing can't be viewed anymore, except the last frame. This is as expected. However, when the publisher decides to start publishing again, the viewer gets a notification of NetStream.Play.Start and NetStream.Play.PublishNotify. In Chrome and Firefox, the viewer can view the livestream again. However in IE the notifications are received, but the viewer still sees the last frame and doesn't see the stream anymore. Does anyone know whatthis could be?

package {
   
import flash.system.Security;
   
import flash.external.ExternalInterface;
   
import flash.display.Sprite;
   
import flash.media.Video;
   
import flash.media.SoundTransform;
   
import flash.events.*;
   
import flash.utils.Timer;
   
import flash.net.*;
   
import flash.display.StageAlign;
   
import flash.display.StageScaleMode;
   
import flash.display.StageQuality;

   
public class View extends Sprite {

       
private var nc:NetConnection = null;
       
private var ns:NetStream = null;
       
private var video:Video = null;
       
private var sound:SoundTransform = null;
       
private var user:Object = null;
       
private var videoWidth:Number = 500; // change width of fla (properties)
       
private var videoHeight:Number = 375; // change height of fla (properties)
       
private var soundVolume:Number = 0.5;

       
public function View():void {
            flash
.system.Security.allowDomain("*");
            stage
.scaleMode = StageScaleMode.NO_BORDER; // NO_SCALE
            stage
.align = StageAlign.TOP_LEFT;
            stage
.quality = StageQuality.BEST;

            user
= this.loaderInfo.parameters;

            setVideo
();
            setSound
();
            connectServer
();
            setCallbacks
();
       
}

       
private function setCallbacks() {
           
var jsReady:Boolean = false;
           
var timer:Timer = null;
           
if (ExternalInterface.available) {
                jsReady
= getJsReady();
               
if (jsReady) {
                    setExternalCallbacks
();
               
}  else {
                    timer
= new Timer(250);
                    timer
.addEventListener(TimerEvent.TIMER,jsReadyTimerEvent);
                    timer
.start();
               
}
           
}
       
}

       
private function jsReadyTimerEvent(event:TimerEvent😞void {
           
var jsReady:Boolean = getJsReady();
           
if (jsReady) {
               
Timer(event.target).stop();
                setExternalCallbacks
();
           
}
       
}

       
private function getJsReady():Boolean {
           
var jsReady:Boolean = ExternalInterface.call("View.jsReady");
           
return jsReady;
       
}

       
private function setExternalCallbacks():void {

           
//ExternalInterface.addCallback("stopViewing",stopViewing);
           
ExternalInterface.addCallback("startViewing",startViewing);
           
ExternalInterface.addCallback("setVolume",setVolume);
           
ExternalInterface.addCallback("getVolume",getVolume);
           
ExternalInterface.call("View.swfReady");           

       
}


       
public function setVideo():void {
            video
= new Video(videoWidth,videoHeight);
            video
.smoothing = true;
            video
.deblocking = 1;
            video
.x = 0;
            video
.y = 0;
            addChild
(video);
       
}

       
public function setSound():void {
            sound
= new SoundTransform(soundVolume);
       
}

       
public function setVolume(vol:Number😞void {
           
if (ns == null) {
               
return;
           
}
           
if (ns.soundTransform == null) {
               
return;
           
}
            sound
= ns.soundTransform;
            sound
.volume = (vol / 100);
            ns
.soundTransform = sound;
       
}

       
public function getVolume():Number {
           
if (sound == null) {
               
return 0;
           
}
           
return Math.round(sound.volume * 100);
       
}
       
/*
        public function stopViewing():Boolean {
            playing = false;
            if (ns === null){
                return false;
            };
            ns.close();
            return true;
        }
        */

       
public function startViewing():void {
           
if (ns != null) {
                video
.attachNetStream(ns);
                ns
.soundTransform = sound;
                ns
.play(user.username + "_public");

           
}
       
}

       
public function connectServer():void {
           
ExternalInterface.call("View.serverState","CONNECTING");
           
if (nc == null) {
                nc
= new NetConnection();
                nc
.addEventListener(NetStatusEvent.NET_STATUS,netStatusEvent);
           
}
            nc
.connect("rtmp://*****:80/public");
       
}

       
public function disconnectServer():void {
           
if (nc != null) {
               
try {
                    nc
.close();
               
} catch(e:Error) {

               
}
           
}
       
}

       
public function reconnectServer():void {
           
var timer:Timer = new Timer(5000,1); // repeat count = 1
            timer
.addEventListener(TimerEvent.TIMER,function(ev:TimerEvent😞void{
                connectServer
();
           
});
            timer
.start();
       
}

       
public function setBufferTime(time:Number😞void{
           
if (ns != null){
                ns
.bufferTime = time;
           
};
       
}      

       
private function netStatusEvent(infoObject:NetStatusEvent😞void {
           
var code:String = infoObject.info.code

           
ExternalInterface.call("View.debug",code);

           
if (code == "NetConnection.Connect.Success") {
               
ExternalInterface.call("View.serverState","OK");
                connectNetStream
();
           
} else if (code == "NetConnection.Connect.Rejected" || code == "NetConnection.Connect.Closed" || code == "NetConnection.Connect.Failed" || code == "NetConnection.Connect.AppShutdown" || code == "NetConnection.Connect.InvalidApp") {
               
ExternalInterface.call("View.serverState","RECONNECTING");
                reconnectServer
();             
           
} else if (code == "NetStream.Play.StreamNotFound" || code == "NetStream.Play.FileStructureInvalid" || code == "NetStream.Play.NoSupportedTrackFound" || code == "NetStream.Play.Failed" || code == "NetStream.Failed") {
               
ExternalInterface.call("View.viewState","FAILED");
           
} else if (code == "NetStream.Play.Stop") {
               
ExternalInterface.call("View.viewState","STOPPED");
           
} else if (code == "NetStream.Play.Start") {
               
ExternalInterface.call("View.viewState","STARTED");
           
} else if (code == "NetStream.Play.PublishNotify") {
               
ExternalInterface.call("View.viewState","PUBLISHING");
           
} else if (code == "NetStream.Play.UnpublishNotify") {
               
ExternalInterface.call("View.viewState","NOTPUBLISHING");
           
} else if (code == "NetStream.Buffer.Full") {
                setBufferTime
(1);
           
} else if (code == "NetStream.Buffer.Empty") {
                setBufferTime
(2);
           
}
       
}

       
private function connectNetStream() {
           
if (ns == null) {
               
if (nc != null) {
                    ns
= new NetStream(nc);
                    ns
.addEventListener(NetStatusEvent.NET_STATUS,netStatusEvent);
                    setBufferTime
(2);
                    startViewing
();
               
}
           
}
       
}

   
}
}

TOPICS
ActionScript
542
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
no replies

Have something to add?

Join the conversation