Unable to stream audio using red5 & actionscript

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Unable to stream audio using red5 & actionscript

ak_001
I am trying to stream audio using actionscript and red5.
This is code which I am using to connect broadcasts room and publish live audio stream:

//Action script code to connect mic to
 private var mic:Microphone;
 private var broadcastScope:NetConnection;
 private function connectBroadcastStream():void
 {
 broadcastScope = new NetConnection();
 broadcastScope.addEventListener(NetStatusEvent.NET_STATUS, connectStreamHandler);  
 broadcastScope.connect("rtmp://localhost:1935/ChatRooms/broadcasts");
 }
 private function connectStreamHandler(event:NetStatusEvent):void
 {
 switch(event.info.code)
 {
 case "NetConnection.Connect.Success" :
 startAudioBtnEnabled = true;
 mic= Microphone.getMicrophone();
 mic.gain = 60;
 mic.rate = 11;
 mic.setSilenceLevel(0, 1000);
 mic.setLoopBack(false);
 mic.addEventListener(StatusEvent.STATUS, micStatusHandler);
 mic.addEventListener(ActivityEvent.ACTIVITY,micActivityListener);
   break;
 case "NetConnection.Connect.Failed" :
   ncRoomScope = null;
   Alert.show("Could not connect.");
   break;
 case "NetConnection.Connect.Closed" :
   break;
 case "NetConnection.Connect.InvalidApp" :
   ncRoomScope = null;
   Alert.show("An error occured.");
   break;
 case "NetConnection.Connect.AppShutDown" :    
   break;
 case "NetConnection.Connect.Rejected" :
   break;
 default:
   break;
 }
private function startAudioStreaming():void
 {
 if(mic !=null)
 {
 var ns:NetStream = new NetStream(broadcastScope);
 //ExternalInterface.call("console.log", ns);
 ns.attachAudio(mic);
 ns.publish("mic_stream","live");
 }else
 {
        Alert.show("Microphone seems to be unavailable");
 }
 }

 This is code which I am using to play live stream:

//Action script code to play stream
private function playAudioStreaming():void
 {
 broadcastScope = new NetConnection();
 broadcastScope.addEventListener(NetStatusEvent.NET_STATUS, playAudioStreamHandler);  
 broadcastScope.connect("rtmp://localhost:1935/ChatRooms/broadcasts");
 }
 private function playAudioStreamHandler(event:NetStatusEvent):void
{
        switch(event.info.code)
 {
 case "NetConnection.Connect.Success" :
 var ns:NetStream = new NetStream(broadcastScope);
 ns.play("mic_stream");
   break;
 case "NetConnection.Connect.Failed" :
   ncRoomScope = null;
   Alert.show("Could not connect.");
   break;
 case "NetConnection.Connect.Closed" :
   break;
 case "NetConnection.Connect.InvalidApp" :
   ncRoomScope = null;
   Alert.show("An error occured.");
   break;
 case "NetConnection.Connect.AppShutDown" :    
   break;
 case "NetConnection.Connect.Rejected" :
   break;
 default:
   break;
 }
}


 When I am trying to publish audio stream, I get a permission dialog for using microphone. Before allowing it, my audio stream is unpublished. I have attached logs in console. I tried debugging this code but was unable to find the reason. Please help.

--

---
You received this message because you are subscribed to the Google Groups "red5" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

logs.txt (25K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Unable to stream audio using red5 & actionscript

Rajdeep Rath
That is a flash thing. You should not start publishing before you got the microphone. You can check out the web for examples. There are different ways to acquire a microphone prior to calling publish .

Publish once after you have a valid microphone object and permissions . You can also use the tool to verify the flow.


Regards
Rajdeep Rath

On Jul 18, 2017 1:11 PM, "Anuja Kothekar" <[hidden email]> wrote:
I am trying to stream audio using actionscript and red5.
This is code which I am using to connect broadcasts room and publish live audio stream:

//Action script code to connect mic to
 private var mic:Microphone;
 private var broadcastScope:NetConnection;
 private function connectBroadcastStream():void
 {
 broadcastScope = new NetConnection();
 broadcastScope.addEventListener(NetStatusEvent.NET_STATUS, connectStreamHandler);  
 broadcastScope.connect("rtmp://localhost:1935/ChatRooms/broadcasts");
 }
 private function connectStreamHandler(event:NetStatusEvent):void
 {
 switch(event.info.code)
 {
 case "NetConnection.Connect.Success" :
 startAudioBtnEnabled = true;
 mic= Microphone.getMicrophone();
 mic.gain = 60;
 mic.rate = 11;
 mic.setSilenceLevel(0, 1000);
 mic.setLoopBack(false);
 mic.addEventListener(StatusEvent.STATUS, micStatusHandler);
 mic.addEventListener(ActivityEvent.ACTIVITY,micActivityListener);
   break;
 case "NetConnection.Connect.Failed" :
   ncRoomScope = null;
   Alert.show("Could not connect.");
   break;
 case "NetConnection.Connect.Closed" :
   break;
 case "NetConnection.Connect.InvalidApp" :
   ncRoomScope = null;
   Alert.show("An error occured.");
   break;
 case "NetConnection.Connect.AppShutDown" :    
   break;
 case "NetConnection.Connect.Rejected" :
   break;
 default:
   break;
 }
private function startAudioStreaming():void
 {
 if(mic !=null)
 {
 var ns:NetStream = new NetStream(broadcastScope);
 //ExternalInterface.call("console.log", ns);
 ns.attachAudio(mic);
 ns.publish("mic_stream","live");
 }else
 {
        Alert.show("Microphone seems to be unavailable");
 }
 }

 This is code which I am using to play live stream:

//Action script code to play stream
private function playAudioStreaming():void
 {
 broadcastScope = new NetConnection();
 broadcastScope.addEventListener(NetStatusEvent.NET_STATUS, playAudioStreamHandler);  
 broadcastScope.connect("rtmp://localhost:1935/ChatRooms/broadcasts");
 }
 private function playAudioStreamHandler(event:NetStatusEvent):void
{
        switch(event.info.code)
 {
 case "NetConnection.Connect.Success" :
 var ns:NetStream = new NetStream(broadcastScope);
 ns.play("mic_stream");
   break;
 case "NetConnection.Connect.Failed" :
   ncRoomScope = null;
   Alert.show("Could not connect.");
   break;
 case "NetConnection.Connect.Closed" :
   break;
 case "NetConnection.Connect.InvalidApp" :
   ncRoomScope = null;
   Alert.show("An error occured.");
   break;
 case "NetConnection.Connect.AppShutDown" :    
   break;
 case "NetConnection.Connect.Rejected" :
   break;
 default:
   break;
 }
}


 When I am trying to publish audio stream, I get a permission dialog for using microphone. Before allowing it, my audio stream is unpublished. I have attached logs in console. I tried debugging this code but was unable to find the reason. Please help.

--

---
You received this message because you are subscribed to the Google Groups "red5" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--

---
You received this message because you are subscribed to the Google Groups "red5" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Unable to stream audio using red5 & actionscript

ak_001
Yes you're right, before getting permission I was publishing Netstream to red5. Thanks a lot..!

--

---
You received this message because you are subscribed to the Google Groups "red5" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Unable to stream audio using red5 & actionscript

Rajdeep Rath
Welcome

On Jul 18, 2017 4:53 PM, "Anuja Kothekar" <[hidden email]> wrote:
Yes you're right, before getting permission I was publishing Netstream to red5. Thanks a lot..!

--

---
You received this message because you are subscribed to the Google Groups "red5" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--

---
You received this message because you are subscribed to the Google Groups "red5" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.