2010-01-10 39 views
4

我想在Flash CS3發揮遠程AAC文件在ActionScript 3,我目前使用此代碼:AAC/MP4在ActionScript 3的NetStream的不工作

var url:String = " http://a1.phobos.apple.com/us/r1000/020/Music/d4/50/94/mzm.kjjofihr.aac.p.m4a ";
var connect_nc:NetConnection = new NetConnection();
connect_nc.connect(null);
var stream_ns:NetStream = new NetStream(connect_nc);
stream_ns.play(url);

(這是基於: http://www.adobe.com/devnet/flashplayer/articles/hd_video_flash_player_03.html

沒有發生錯誤,但沒有播放聲音。我使用本地AAC文件和本地MP4視頻獲得相同的行爲。

如果我使用的URL或文件路徑不是流傳輸文件,我得到一個NetStream.Play.StreamNotFound錯誤,我猜測這意味着該流在有效URL的情況下找到。如果我使用本地FLV,則其音頻播放效果很好。

如果我在netStatusHandler中添加了以下監聽器和跟蹤(evt.info.code),我只能看到任何用FLV跟蹤的代碼(例如NetStream.Play.Start)。沒有代碼跟蹤AAC或MP4。 stream_ns.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);

添加此監聽器(即onMetaData參數只跟蹤FLV,而不跟其他文件類型)的情況也是如此,其中metaDataListener被定義爲具有跟蹤其參數的onMetaData方法的對象。
stream_ns.client = metaDataListener;

這裏有什麼可能出錯或者如何診斷的想法?

謝謝!

回答

0

如上所述http://www.adobe.com/devnet/flashplayer/articles/hd_video_flash_player_03.html你在做什麼是正確的。

var connect_nc:NetConnection = new NetConnection(); 
connect_nc.connect(null); 
var stream_ns:NetStream = new NetStream(connect_nc); 
stream_ns.play("RE-Sample.m4a"); 

然而,關於nestream ActionScript語言參考這裏找到: http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/NetStream.html#play%28%29

指出:

play()方法

...

...

在沒有Flash Media Server的情況下使用此方法時,存在安全考慮事項。本地信任或本地聯網沙箱中的文件可以從遠程沙箱加載和播放視頻文件,但無法以跨域策略文件的形式獲得明確許可,無法訪問遠程文件的數據。另外,可以通過在包含SWF內容的HTML頁面中設置對象的allowNetworking參數和嵌入標記,來防止Flash Player中運行的SWF文件使用此方法。

... ...

參數 ...參數 - 視頻文件播放的位置,作爲URLRequest對象或字符串。在Flash Player和應用程序安全沙箱以外的AIR內容中,可以播放存儲在與SWF文件相同的目錄中或存儲在子目錄中的本地視頻文件;但是,您無法導航到更高級別的目錄。

所以這可能是一個安全沙箱問題。

0

由於您沒有從與NetStream相關的任何事件偵聽器獲得任何反饋,所以Oliver的說法是真實的,並且您正在收到StreamNotFound響應。

StreamNotFound在未連接到FMS時意味着由於安全問題,您要麼有路徑錯誤,要麼沒有看到它。

1

ActionScript 3.0中的所有內容都基於事件(幾乎沒有使用回調的隨機異常)。

爲了可以調用NetStream.play()函數,您需要偵聽帶有info.code「NetConnection.Connect.Success」的NetStatusEvent。

這裏的一些作品(我只是寫了現在,並測試它你):

package 
{ 
    import flash.display.Sprite; 

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

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

    public class MainDocument extends Sprite 
    { 
     private var _connection:NetConnection=new NetConnection(); 
     private var _netStream:NetStream=null; 

     private var _strM4AURL:String="http://a1.phobos.apple.com/us/r1000/020/Music/d4/50/94/mzm.kjjofihr.aac.p.m4a"; 

     //constructor 
     public function MainDocument():void 
     { 
      this._connect(); 
     } 

     private function _connect():void 
     { 
      this._connection.close(); 
      this._connection=new NetConnection(); 
      this._connection.addEventListener(NetStatusEvent.NET_STATUS, this._netStatusHandler); 
      this._connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, this._asyncErrorHandler); 

      this._connection.connect(null); 
     } 

     private function _netStatusHandler(event:NetStatusEvent):void 
     { 
      trace(event.info.code); 
      switch (event.info.code) 
      { 
       case "NetConnection.Connect.Success": 
        this._requestAudio(); 
        break; 
      } 
     } 

     private function _requestAudio():void 
     { 
      if(this._netStream!==null) 
       this._netStream.close(); 

      this._netStream=new NetStream(this._connection); 

      this._netStream.addEventListener(NetStatusEvent.NET_STATUS, this._netStatusHandler); 
      this._netStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, this._asyncErrorHandler); 

      this._netStream.checkPolicyFile=false; 

      this._netStream.play(this._strM4AURL); 
     } 

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

更多信息,請參考ActionScript 3.0語言參考。

相關問題