IOS RTMP live stream audio
Hi guys hopefully some of you will be able to help me.
I am trying to stream audio from a live RTMP feed using the NetConnection and NetStream classes. I've managed to get my app running no problem on Android, however I am having some major difficulties getting it to play the audio back on iPad. Interestingly it works in the device emulators when debugging, however I'm assuming this is not really an accurate representation. I've tried streaming the RTMP in both AAC and MP3, but with no luck from either. I can verify through debug that it has connected to the stream, however I just get no audio playing.
Everything I've read about seems to suggest that this is possible on IOS as I'm only interested in audio and not video. Can anyone help?
Code sample below (it's quick and dirty!
).
THanks in advance!
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="Audio" creationComplete="init()">
<s:layout>
<s:VerticalLayout paddingLeft="10" paddingRight="10"
paddingTop="10" paddingBottom="10"/>
</s:layout>
<fx:Script>
<![CDATA[
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import mx.core.UIComponent;
private var vid:Video;
private var videoHolder:UIComponent;
private var nc:NetConnection;
private var defaultURL:String="[STREAM]";
private var streamName:String="[STREAMNAME]";
private var ns:NetStream;
private var msg:Boolean;
private var intervalMonitorBufferLengthEverySecond:uint;
private function init():void
{
vid=new Video();
vid.width=864;
vid.height=576;
vid.smoothing = true;
//Attach the video to the stage
videoHolder = new UIComponent();
videoHolder.addChild(vid);
addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
grpVideo.addElement(videoHolder);
connect();
}
public function onSecurityError(e:SecurityError):void
{
trace("Security error: ");
}
public function connect():void
{
nc = new NetConnection();
nc.client = this;
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.objectEncoding = flash.net.ObjectEncoding.AMF0;
nc.connect(defaultURL);
}
public function netStatusHandler(e:NetStatusEvent):void
{
switch (e.info.code) {
case "NetConnection.Connect.Success":
trace("audio - Connected successfully");
createNS();
break;
case "NetConnection.Connect.Closed":
trace("audio - Connection closed");
//connect();
break;
case "NetConnection.Connect.Failed":
trace("audio - Connection failed");
break;
case "NetConnection.Connect.Rejected":
trace("audio - Connection rejected");
break;
case "NetConnection.Connect.AppShutdown":
trace("audio - App shutdown");
break;
case "NetConnection.Connect.InvalidApp":
trace("audio - Connection invalid app");
break;
default:
trace("audio - " + e.info.code + "-" + e.info.description);
break;
}
}
public function createNS():void
{
trace("Creating NetStream");
ns=new NetStream(nc);
//nc.call("FCSubscribe", null, "live_production"); // Only use this if your CDN requires it
ns.addEventListener(NetStatusEvent.NET_STATUS, netStreamStatusHandler);
vid.attachNetStream(ns);
//Handle onMetaData and onCuePoint event callbacks: solution at http://tinyurl.com/mkadas
//See another solution at http://www.adobe.com/devnet/flash/quickstart/metadata_cue_points/
var infoClient:Object = new Object();
infoClient.onMetaData = function oMD():void {};
infoClient.onCuePoint = function oCP():void {};
ns.client = infoClient;
ns.bufferTime = 0;
ns.play(streamName);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
function asyncErrorHandler(event:AsyncErrorEvent):void {
trace(event.text);
}
intervalMonitorBufferLengthEverySecond = setInterval(monPlayback, 1000);
}
public function netStreamStatusHandler(e:NetStatusEvent):void
{
switch (e.info.code) {
case "NetStream.Buffer.Empty":
trace("audio - Buffer empty: ");
break;
case "NetStream.Buffer.Full":
trace("audio - Buffer full:");
break;
case "NetStream.Play.Start":
trace("audio - Play start:");
break;
default:
trace("audio - " + e.info.code + "-" + e.info.description);
break;
}
}
public function monPlayback():void {
// Print current buffer length
trace("audio - Buffer length: " + ns.bufferLength);
trace("audio - FPS: " + ns.currentFPS);
trace("audio - Live delay: " + ns.liveDelay);
}
public function onBWDone():void {
//Do nothing
}
public function onFCSubscribe(info:Object):void {
// Do nothing. Prevents error if connecting to CDN.
}
public function onFCUnsubscribe(info:Object):void {
// Do nothing. Prevents error if connecting to CDN.
}
]]>
</fx:Script>
<s:Group id="grpVideo">
</s:Group>
</s:View>
