forked from: netstream 'n' such
forked from netstream 'n' such (diff: 40)
ActionScript3 source code
/**
* Copyright ohisama ( http://wonderfl.net/user/ohisama )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/qIdc
*/
// forked from wh0's netstream 'n' such
package
{
import flash.media.Sound;
import flash.net.NetStream;
import flash.net.ObjectEncoding;
import com.adobe.serialization.json.JSON;
import flash.events.NetStatusEvent;
import flash.net.NetConnection;
import flash.events.UncaughtErrorEvent;
import com.actionscriptbible.Example;
public class FlashTest extends Example
{
private var nc : NetConnection;
private var ns : NetStream;
public function FlashTest()
{
loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, function(e:UncaughtErrorEvent):void { trace(e.error); });
nc = new NetConnection();
nc.objectEncoding = ObjectEncoding.AMF0;
nc.client = new TraceClient(trace);
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
nc.connect('rtmp://stream.apmmusic.com/myapm_stream_app/');
}
private function netStatus(e:NetStatusEvent):void
{
switch (e.info.code)
{
case 'NetConnection.Connect.Success':
trace('connected (:');
success();
break;
default:
//trace('unhandled netStatus ' + JSON.encode(e.info));
break;
}
}
private function success():void
{
ns = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
ns.bufferTime = 2;
ns.play('mp3:audio/KPM/KPM_KPM_0768/KPM_KPM_0768_00101', 0, -1, true);
}
}
}
import flash.utils.Proxy;
import flash.utils.flash_proxy;
class TraceClient extends Proxy
{
private var trace : Function;
public function TraceClient(trace : Function)
{
this.trace = trace;
}
flash_proxy override function getProperty(name : *) : *
{
trace('getting ' + name);
return function (...rest):*
{
trace('calling ' + name + '(' + rest.join(', ') + ')');
};
}
}