Showing posts with label ActionScript. Show all posts
Showing posts with label ActionScript. Show all posts

Tuesday, April 5, 2011

How to use FlashPlayer 10.2 and 10.3 feature with Flash CS5

I want to use the new features introduced by FlashPlayer 10.2 and 10.3. More specifically, stage video and acoustic echo cancellation. Since adobe does not offer the update for Flash CS5, I have to find the other way to do it.

What I did is follow the instruction specified in the link. In this case, I set up FlashPlayer 10.3.

However there are two missing things:
  • FlashPlayer10_3.xml: In the player node, change the version from "10" to "12". This works as "-swf-version=12" on Flex Compiler.
  • Publish Settings: In the flash tab, change the "Hardware Acceleration" from "None" to "Level 2 - GPU".

The first enables to use new features, and the second enables to use stage video.

Saturday, January 29, 2011

How to make an audio activity level meter per NetStream?

The NetStream class do not have any method to get audio activity level. It seems Microphone class has acitivityLevel. It means, players can not get the audio level from the NetStream class, but a publisher can make the audio level from the Microphone class. So it is a solution. The publisher make and send it to players. And they show audio levels on their video screens.

Add highlighted code to the MyNetConnection.

        public function onConnect(event:NetStatusEvent):void { 
            client = new MyNetConnectionClient();
            setupPingTimer();
        }

Then create MyNetConnectionClient. This is a publisher side code.

package my.project.flash {
 
    public class MyNetConnectionClient {

        private var camera:Camera;
        private var microphone:Microphone;
        private var nsPublish:NetStream;
    
        public function MyNetConnectionClient(netConnection:NetConnection) {
            camera = Camera.getCamera();
            microphone = Microphone.getMicrophone();   
            nsPublish = new NetStream(netConnection);
            nsPublish.publish("myPublishStreamId");
            nsPublish.attachCamera(camera);
            nsPublish.attachAudio(microphone);
            microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, nsPublishSampleAudioFrame);
        }
  
        public function nsPublishSampleAudioFrame(event:SampleDataEvent):void {
            var metaData:Object = new Object();
            metaData.audioActivityLevel = microphone.activityLevel;
            nsPublish.send("setAudioActivityLevel", metaData);
        }
    }
}

Then the player side client code. "setAudioActivityLevel" should be the method on a NetStream.client. So you can have audio activity level per stream.

var stream:Stream = new NetStream();
    stream.client = new MyNetStreamClient();
    stream.play("myPublishStreamId");

package my.project.flash {
    public class MyNetStreamClient {
        public function setAudioActivityLevel(param:Object):void {
            doSomethingToShowAutioActivityLevel(param.audioActivityLevel);
        }
    }
}


Hmmm, I changed a lot from my source code, and I do not check it. So I'm not sure it works or not. However, I hope this will give you some hints.

Thursday, January 27, 2011

How to find the network disconnection at a flash client?

Issue

When the flush client only playing (not publishing) video streams, the network disconnection is not detected. When client send nothing to the server, neither NetConnection or NetStream does not receive any NetStatusEvent.

Solution

It's easy. Just issue some message from client to server.

package my.project.flash {
 
    public class MyNetConnection extends NetConnection {

        public function MyNetConnection(){
            super();
        }

        public override function connect(command:String, ... args):void {
            super.connect(command);
            addEventListener(NetStatusEvent.NET_STATUS, onStatus);
        }

        public function onStatus(event:NetStatusEvent):void {
            if (event.info.code == "NetConnection.Connect.Success"){
                onConnect(event);
            } else {
                onDisconnect(event);
            }
        }

        public function onConnect(event:NetStatusEvent):void { 
            setupPingTimer();
        }
  
        public function onDisconnect(event:NetStatusEvent):void {
            // doSomethingOnDisconnect();
        }

        public function setupPingTimer():void {
            var pingTimer:Timer = new Timer(1000);
            pingTimer.addEventListener(TimerEvent.TIMER, sendPing);
            pingTimer.start();
        }
    
        public function sendPing(event:TimerEvent):void {
            call("ping", null); // (no response)
        }
    }
}