I have problem with receive netstream sound volume changing
<![CDATA[
import mx.events.FlexEvent;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.media.Camera;
import flash.media.Microphone;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.SoundTransform;
private const SERVER:String = 'rtmfp://p2p.rtmfp.net/';
private const DEVKEY:String = 'my dev key';
private const REG:String = 'scripts/reg.php';
private const GETID:String = 'scripts/getid.php';
private var netConnection:NetConnection;
private var netStreamPublish:NetStream;
private var streamRcv:NetStream;
private var videoRcv:Video;
private var PeerId:String;
private var newVolume:Number = 0;
private function connect():void
{
netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);
netConnection.connect(SERVER + DEVKEY);
}
private function netConnectionHandler(event:NetStatusEvent):void
{
trace('netConnection:', event.info.code);
switch(event.info.code)
{
case "NetConnection.Connect.Success":
PublicherConnect();
break;
}
}
private function InsertID():void {
PeerId = netConnection.nearID;
var loader:URLLoader = new URLLoader();
try {
loader.load(new URLRequest(REG+'?insert='+PeerId));
}
GetID();
}
private function GetID():void {
var loader2:URLLoader = new URLLoader();
loader2.load(new URLRequest(GETID));
loader2.addEventListener(Event.COMPLETE, function(e:Event):void {
var farid:String = e.target.data;
if (farid.length) {
initRcvStream(farid);
}
});
}
private function PublicherConnect():void
{
netStreamPublish = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
netStreamPublish.addEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);
var camera:Camera = Camera.getCamera();
myCameraDisplay.attachCamera(camera);
netStreamPublish.attachCamera(camera);
var mic:Microphone = Microphone.getMicrophone();
mic.gain = myVolume.value;
netStreamPublish.attachAudio(mic);
netStreamPublish.publish('media');
var client:Object = new Object;
client.onPeerConnect = function(c:NetStream):Boolean {
netStreamPublish.send(c.farID);
initRcvStream(c.farID);
return true;
};
netStreamPublish.client = client;
InsertID();
}
private function micVolumeChanged(e:Event):void
{
var mic:Microphone = Microphone.getMicrophone();
mic.gain = e.target.value;
}
private function initRcvStream(peerID:String):void {
streamRcv = new NetStream(netConnection, peerID);
streamRcv.play('media');
var rcvSndTransform:SoundTransform = new SoundTransform();
rcvSndTransform.volume = newVolume;
streamRcv.soundTransform = rcvSndTransform;
videoRcv = new Video;
videoRcv.attachNetStream(streamRcv);
rcvVideoDisplay.addChild(videoRcv);
}
private function speakerVolumeChanged(e:Event):void
{
newVolume = e.target.value;
rcvVideoDisplay.volume = newVolume;
streamRcv.soundTransform = new SoundTransform(newVolume);
}
]]>
<mx:VideoDisplay id="rcvVideoDisplay" x="20" y="50" width="300" height="250" volume=".9" />
<mx:VideoDisplay id="myCameraDisplay" x="370" y="50" width="300" height="250"/>
<mx:HSlider id="rcvVolume" change="speakerVolumeChanged(event)" minimum="0" maximum="1" showDataTip="false" snapInterval=".01" x="45" y="250" value=".9"/>
<mx:HSlider id="myVolume" change="micVolumeChanged(event)" minimum="0" maximum="1" showDataTip="false" snapInterval=".01" x="395" y="250" value=".9" />
And this does't work. Who can help me, please? Update: posted full code. I use FlashDevelop 4.6.4, Flex4, SDK 4.6, flashPlayer 11.1. I mean if streamRcv soundTransform volume greater than 0, sound is "on", but doesn't change with silder "rcvVolume". If streamRcv soundTransform volume equal to 0, at first, video have no sound, but if drag slider, sound volume controlled normally.
On Flex, to play a video stream we can use a
VideoPlayer
or aVideoDisplay
components or aVideo
object withNetStream
.This an minimal working example of how to use theses elements with a live stream and how to adjust their sound volume :
I hope that helps you to resolve your problem.