多年来,我一直在寻找解决此问题的方法,但没有任何明确的文档。有许多Shoutcast Flash播放器(例如radio.de),所以我知道这是可能的。然而,我的大部分研究都指向了这个:
s = new Sound();
s.loadSound ("url.of.shoutcaststream:8003",true);
这在FireFox中可以正常工作,但在IE中却不行。我不想购买组件,我想知道这些组件是如何做到的,以便我可以构建自己的定制播放器。
多年来,我一直在寻找解决此问题的方法,但没有任何明确的文档。有许多Shoutcast Flash播放器(例如radio.de),所以我知道这是可能的。然而,我的大部分研究都指向了这个:
s = new Sound();
s.loadSound ("url.of.shoutcaststream:8003",true);
这在FireFox中可以正常工作,但在IE中却不行。我不想购买组件,我想知道这些组件是如何做到的,以便我可以构建自己的定制播放器。
你已经快成功了。完整的口诀是:
s = new Sound();
s.loadSound ("http://url.of.shoutcaststream:8003/;",true);
MEM_MAX = 10 * 1024 * 1024
if(sound.bytesLoaded > MEM_MAX)
{ reloadSound(); flash.system.System.gc(); }
如果是流媒体,它可能通过NetStream和NetConnection类播放。例如:
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 = "url.of.shoutcaststream:8003";
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);
}
}
由于跨域问题,您将无法直接读取 Flash 中的元数据。由于 Flash 播放器认为音频流属于“内容”,因此您可以播放该音频流,但是您将无法读取元数据,因为 Flash 播放器认为它是“数据”,受到跨域策略的限制。
您可以向 ShoutCast 服务器添加跨域策略文件,但这对大多数用户来说会很困难(需要在 ShoutCast 服务器上安装 Web 服务器)。
乔治·加德纳 http://www.commonmode.co.uk
请查看wavestreaming.com的播放器,它非常易于使用。
http://www.wavestreaming.com/servers/flash-streaming/shoutcast-player.php