3

我正在尝试在 m4a (aac) 中流式传输本地音频文件,类似于 Tiberiu-Ionuț Stan (http://stackoverflow.com/questions/2036107/aac-mp4-not-working-in-actionscript-3s-netstream):

package
{

    import flash.net.NetConnection;
    import flash.net.NetStream;

    import flash.events.NetStatusEvent;
    import flash.events.AsyncErrorEvent;
    import flash.events.Event;

    public class Mysound
    {
        private var _connection:NetConnection;
        private var _netStream:NetStream;
        private var _filePath:String;
        private var _client:Object;

        public function MainDocument(filePath:String):void
        {
            _filePath = filePath;
            connect();
        }

        private function connect():void
        {
            _connection=new NetConnection();
            _connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
            _connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);

            _connection.connect(null);
        }

        private function netStatusHandler(event:NetStatusEvent):void
        {
            switch (event.info.code)
            {
                case "NetConnection.Connect.Success":
                    requestAudio();
                    break;
            }
        }

        private function requestAudio():void
        {
            _netStream=new NetStream(_connection);
            _netStream.addEventListener(NetStatusEvent.NET_STATUS, this._netStatusHandler);
            _netStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, this._asyncErrorHandler);

            _client = new Object();
            _client.onMetaData = onMetaData;
            _netStream.client = _client;

            _netStream.backBufferTime = 0;
            _netStream.bufferTime = 0.5;
            _netStream.bufferTimeMax = 5;


            _netStream.play(filePath);
        }

        private function asyncErrorHandler(event:AsyncErrorEvent):void
        {
            trace(event);
        }

        private function onMetaData(metadata:Object):void
        {
            var str:String = "";
            for (var key:String in metadata) {
                str += key + ": " + metadata[key];
            }
            trace(str);
        }
    }
}

它适用于我的模拟器,但不适用于设备(​​ipad)。我发现设备上的 netStatusHandler 捕获状态“NetStream.Play.Failed”,但我不知道为什么,我知道它正确读取文件,因为它确实获得了正确的元数据,它也开始缓冲声音,但无法播放它. 文件位于我的应用程序 swf 旁边的文件夹中,因此它不应该是沙盒问题。我还应该尝试什么让它工作?

4

0 回答 0