I would like to create a Shoutcast player in Flex using NetStream and NetConnection classes. Looking at examples like this: http://livedocs.adobe.com/flex/3/langref/flash/net/NetStream.html#includeExamplesSummary everything seemed pretty much straightforward.
When i try it however it doesnt work.
Everything connects however i cant hear anything. So i tried extending my controller class to Video and adding it to the application but then it crashes on init with Type Coercion failed exception.
This is my controller:
package controller
{
import flash.events.NetStatusEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
public class ShoutcastController extends Video
{
private var _streamUrl:String;
private var _connUrl:String;
private var _netConnection:NetConnection;
private var _stream:NetStream;
private var _player:Video;
public function ShoutcastController(streamUrl:String)
{
_streamUrl = streamUrl;
_connUrl = "rtmp://conn.url";
}
public function playStream():void
{
_netConnection = new NetConnection();
_netConnection.addEventListener(NetStatusEvent.NET_STATUS, netEventsHandler);
_netConnection.connect(_connUrl);
}
private function netEventsHandler(event:NetStatusEvent):void
{
if (event.info.code == "NetConnection.Connect.Success")
playShoutcast();
}
private function streamEventsHandler(event:NetStatusEvent):void
{
trace(event);
}
private function playShoutcast():void
{
_stream = new NetStream(_netConnection);
_stream.addEventListener(NetStatusEvent.NET_STATUS, streamEventsHandler);
var streamClient:CustomStreamClient = new CustomStreamClient();
_stream.bufferTime = 2;
this.attachNetStream(_stream);
_stream.play(_streamUrl);
trace(_stream.time);
}
}
}
and this is how i call it on creationComplete:
_shoutcastController = new ShoutcastController("http://stream.url:8000");
_shoutcastController.playStream();
this.addChild(_shoutcastController);
Any ideas?