actionscript 3 - flex4 - NetStream.soundtransform.volume doesn't change -
i have problem 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 does't work. can me, please? update: posted full code. use flashdevelop 4.6.4, flex4, sdk 4.6, flashplayer 11.1. mean if streamrcv soundtransform volume greater 0, sound "on", doesn't change silder "rcvvolume". if streamrcv soundtransform volume equal 0, @ first, video have no sound, if drag slider, sound volume controlled normally.
on flex, play video stream can use videoplayer
or videodisplay
components or video
object netstream
.
this minimal working example of how use theses elements live stream , how adjust sound volume :
<?xml version="1.0" encoding="utf-8"?> <s:application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="890" height="371" minwidth="955" minheight="600" creationcomplete="init(event)"> <fx:script> <![cdata[ import mx.events.flexevent import flash.events.asyncerrorevent import flash.events.netstatusevent import flash.events.mouseevent import flash.events.event import spark.components.mediaclasses.dynamicstreamingvideoitem import spark.components.mediaclasses.dynamicstreamingvideosource private const server:string = 'rtmp://localhost/live' private const stream:string = 'test' private var nc:netconnection private var ns:netstream private var video:video private var video_item:dynamicstreamingvideoitem private var video_source:dynamicstreamingvideosource private var volume:number = 0.5 private function btn_start_clickhandler(e:mouseevent):void { video_item = new dynamicstreamingvideoitem() video_item.streamname = stream // videoplayer , videodisplay components have use // dynamicstreamingvideosource object source video_source = new dynamicstreamingvideosource() video_source.host = server video_source.streamitems = new <dynamicstreamingvideoitem>[video_item] video_source.streamtype = 'live' video_player.source = video_source // disabled videodisplay component start playing // live stream videoplayer component //video_display.source = video_source nc = new netconnection() nc.addeventlistener(asyncerrorevent.async_error, function(e:asyncerrorevent):void{}) nc.addeventlistener( netstatusevent.net_status, function(e:netstatusevent):void{ if(e.info.code == 'netconnection.connect.success'){ ns = new netstream(nc) ns.addeventlistener(asyncerrorevent.async_error, function(e:asyncerrorevent):void{}) ns.addeventlistener(netstatusevent.net_status, function(e:netstatusevent):void{}) video = new video(240, 180) // disabled video object start playing // live stream videoplayer component //video.attachnetstream(ns) video.smoothing = true uic.addchild(video) ns.play(stream) ns.soundtransform = new soundtransform(volume) // can use soundtransform adjust sound volume : // var sound_transform:soundtransform = new soundtransform() // sound_transform.volume = volume // ns.soundtransform = sound_transform } } ) nc.connect(server) } private function init(e:flexevent):void { // can hide videoplayer component controls panel //video_player.playercontrols.visible = false // init volume video_player.volume = video_display.volume = volume } private function volume_slider_changehandler(e:event):void { volume = e.target.value video_display.volume = video_player.volume = volume ns.soundtransform = new soundtransform(volume) } private function player_type_clickhandler(e:mouseevent):void { // here have use component.stop() , component.source = '' avoid errors video_player.stop() video_display.stop() video_player.source = '' video_display.source = '' video.attachnetstream(null) switch (radiobutton(e.target).value){ case 'video_player': video_player.source = video_source break case 'video_display': video_display.source = video_source break case 'video': video.attachnetstream(ns) break } } ]]> </fx:script> <s:videoplayer id="video_player" x="46" y="100" width="240" height="180"/> <s:videodisplay id="video_display" x="322" y="100" width="240" height="180" autodisplayfirstframe="true" autoplay="true" enabled="true" volume="0.5"/> <s:button id="btn_start" x="48" y="38" width="89" height="35" label="start" click="btn_start_clickhandler(event)"/> <mx:uicomponent id="uic" x="597" y="100" width="240" height="180"/> <s:hslider id="volume_slider" x="302" y="49" width="94" height="16" change="volume_slider_changehandler(event)" maximum="1" minimum="0" stepsize="0.1" value="0.5"/> <s:label x="245" y="51" text="volume"/> <s:radiobutton x="122" y="303" label="videoplayer" click="player_type_clickhandler(event)" enabled="true" groupname="player_type" selected="true" value="video_player"/> <s:radiobutton x="400" y="303" label="videodisplay" click="player_type_clickhandler(event)" groupname="player_type" value="video_display"/> <s:radiobutton x="686" y="303" label="video" click="player_type_clickhandler(event)" groupname="player_type" value="video"/> </s:application>
i hope helps resolve problem.
Comments
Post a Comment