我在此网站上找到了一个代码,用于在Flash AS3中进行shoutcast流式传输。 这是代码:
package {
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.Event;
public class NetConnectionExample extends Sprite {
private var streamURL:String = "https://myHost:myPort";
private var connection:NetConnection;
private var stream:NetStream;
public function NetConnectionExample() {
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
connection.connect(null);
}
private function netStatusHandler(event:NetStatusEvent):void {
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + streamURL);
break;
}
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function connectStream():void {
stream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
stream.client = new CustomClient();
stream.play(streamURL);
}
}
}
class CustomClient {
public function onMetaData(info:Object):void {
trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
}
public function onCuePoint(info:Object):void {
trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
}
}
但是当我编译SWF时出现这个错误:
打开网址'https:// myHost:myPort'时出错 SecurityError:错误#2000:没有活动的安全上下文。
任何人都可以告诉我如何正确地做到这一点?我一直在寻找两天,但没有用!
由于
答案 0 :(得分:2)
网址根本不存在,因为这只是一个示例,但此代码还存在一些其他问题。例如:connection.connect(null),它不会连接到任何地方,因此netconnection实例根本不会调度netstatus事件,这就是为什么connectStream方法不会被执行。 如果您想播放来自shoutcast的流,请使用以下代码:
var soundOBJ : Sound = new Sound();
soundOBJ.load(new URLRequest("http://78.159.104.147:80/"));
soundOBJ.play( );
(只需替换URLRequest构造函数中的url)
干杯
Tamas Gronas