4

I've been looking for a solution to this for years, but nothing is conclusively documented. There are many Shoutcast Flash players out there (e.g. radio.de) so I know it's possible. However, most of my research leads to this:

s = new Sound();
s.loadSound ("url.of.shoutcaststream:8003",true);

Which works for me in FireFox but not in IE. I don't want to buy a component, I want to know how those components do it so that I can build my own custom player.

4

5 回答 5

8

您快到了。完整的口头禅是:

s = new Sound();
s.loadSound ("http://url.of.shoutcaststream:8003/;",true);

注意尾部的斜杠和分号。Shoutcast 服务器 (DNAS) 查看请求的用户代理,以检测在响应中发回的内容。如果它是一个浏览器,那么它提供一个 HTML 页面。如果它不是浏览器 UA,它会发送流。尾随分号(由于某些未记录的原因)导致 DNAS 忽略 UA 并始终发送流。

播放 AAC 流没有令人满意的解决方案,虽然 Flash 有这样做的设备,但出于某种原因,AAC 的 API 完全不同,无法播放 AAC Shoutcast。

这里的 NetStream 解决方案不太可能提供解决方案。

有关更多信息,请参阅我的博客:

http://www.flexiblefactory.co.uk/flexible/?p=51

于 2009-11-18T22:27:20.610 回答
3

在 Flash 中制作 Stream-Player 的主要问题是内存消耗。

Flash Player一直在内存中记录流,浪费了所有的计算机资源,直到它冻结,使用户非常生气。:)

// 使用 setTimeout 或 setInterval 定期检查 sound.bytesLoaded,将声音变量设为 null

MEM_MAX = 10 * 1024 * 1024
if(sound.bytesLoaded > MEM_MAX)
  { reloadSound(); flash.system.System.gc(); }
于 2010-08-05T10:58:18.790 回答
1

If it's a stream, it's probably played through the NetStream and NetConnection classes. For example:

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);
    }
}
于 2009-08-13T17:39:52.217 回答
1

由于跨域问题,您将无法直接在 Flash 中读取元数据。您可以播放音频流,因为 Flash 播放器将其视为“内容”,但您将无法读取元数据,因为 Flash 播放器将其视为受跨域策略约束的“数据”。

您可以将跨域策略文件添加到 ShoutCast 服务器,但这对大多数用户来说会很困难(您需要在 ShoutCast 服务器上安装网络服务器)

乔治·加德纳 http://www.commonmode.co.uk

于 2010-11-24T14:15:15.780 回答
0

查看 wavestreaming.com 的播放器,它非常易于使用。

http://www.wavestreaming.com/servers/flash-streaming/shoutcast-player.php

于 2010-03-14T15:01:43.930 回答