2012-09-10 52 views
0

我試圖從流亞馬遜的CloudFront的/ S3服務的視頻。儘管我的文件名是正確的,並且是「NetConnection.Connect.Success」狀態,但我的NetConnection onBWDone回調會給我一個「未定義」的錯誤,並且該視頻不會在舞臺上的任何位置播放或顯示。連接報告說它是成功的,所以我不知道問題出在哪裏。這裏是我的代碼:視頻流:「onBWDone:未定義」,並不能播放視頻

var amazonCloudFrontDomain:String = "myCloudFrontDistributionID.cloudfront.net"; 
var amazonCloudFrontStreamURL:String = "rtmp://" + amazonCloudFrontDomain + "/cfx/st/"; 
var videoFileName:String = "myVideo.flv"; 

Security.allowDomain(amazonCloudFrontDomain); 
Security.allowDomain("rtmp://" + amazonCloudFrontDomain); 
Security.allowDomain(amazonCloudFrontStreamURL); 


var client:Object = new Object(); 
client.onBWDone = function(e){trace("onBWDone: " + e);} 
client.onMetaData = function(e){trace("onMetaData: " + e);} 
client.onCuePoint = function(e){trace("onCuePoint: " + e);} 


var video:Video = new Video(300, 400); // create a new Video item and set its width and height 
video.x = 0; // position the video's x position 
video.y = 0; // position the video's y position 
var duration:Number; // use this later to get the duration of the video being played 
this.addChild(video); 

var nc:NetConnection = new NetConnection(); // variable for a new NetConnection 
nc.client = client; 
nc.addEventListener(NetStatusEvent.NET_STATUS,netConnectionStatusHandler,false,0,true); 
nc.connect(amazonCloudFrontStreamURL); // set the nc variable to null 

var ns:NetStream; 
function netConnectionStatusHandler(e):void 
{ 
    switch(e.info.code) 
    { 
     case "NetConnection.Connect.Success": 
      trace("S3 Connected"); 

      ns = new NetStream(nc); // create a variable for a new NetStream connection & connect it to the nc variable 
      ns.addEventListener(NetStatusEvent.NET_STATUS, netStreamStatusHandler); // add a listener to the NetStream to listen for any changes that happen with the NetStream 
      ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, netStreamAsyncErrorHandler); // add a listener to the NetStream for any errors that may happen 
      ns.client = client; 

      video.attachNetStream(ns); // attach the NetStream variable to the video object 
      video.smoothing = true; 
      video.deblocking = 1; 

      ns.bufferTime = 5; // set the buffer time to 5 seconds 
      ns.play(videoFileName); // tell the netstream what video to play and play it 
      break; 
    } 
    trace(e.info.code); 
} 


function netStreamAsyncErrorHandler(Event:AsyncErrorEvent):void 
{ 
    // trace(event.text); // this will handle any errors with video playback 
} 

function netStreamStatusHandler(event:NetStatusEvent):void 
{ 
    trace(event.info.code); // this will handle any events that are fired when the video is playing back 
    switch(event.info.code) // switch statement to handle the various events with the NetConnection 
    { 

     case "NetStream.Buffer.Full": // when the buffer is full fire the code below 
      ns.bufferTime = 10; // set buffer time to 10 seconds  break; 
     case "NetStream.Buffer.Empty": // when the buffer is empty fire, code below 
      ns.bufferTime = 10; // set buffer time to 10 seconds 
     break; 
     case "NetStream.Play.Start": // when the video starts playing, fire the code below 
      ns.bufferTime = 10; // set the buffer time to 10 seconds 
     break; 
     case "NetStream.Seek.Notify": // when you seek with the scrubber it sends a notify signal of the time 
      ns.bufferTime = 10; // set the buffer time to 10 seconds 
     break; 
     case "NetStream.Seek.InvalidTime": // when you release the scrubber ahead of the video that has been loaded, you get this error. it will jump you back to the last frame that has been loaded 
      ns.bufferTime = 10; // set the buffer time to 10 seconds 
     break; 
     case "NetStream.Play.Stop": // when you reach the end of the video 
      ns.pause(); // pause the video 
      ns.seek(1); // seek the video to the first frame 
     break; 
    } 
} 

這是控制檯輸出:

S3 Connected 
netConnectionStatusHandler: NetConnection.Connect.Success 
onBWDone: undefined 
NetStream.Play.Reset 
NetStream.Play.Start 

...並沒有任何反應。沒有視頻,沒有音頻,什麼都沒有。任何人都可以看到我的代碼的任何問題?

回答

1

我認爲,不是所有的流媒體應用必須使用onBWDone功能,因此,如果他們不使用它,它可能傳遞空或未定義的函數,而不是kbps的。

所以你的問題很可能與下面的跟蹤語句e

client.onBWDone = function(e){trace("onBWDone: " + e);} 

此外,該函數不收到一個事件對象,而是一個... rest陣列,通常只有在一個項目它。試試這個: http://help.adobe.com/en_US/FlashMediaServer/3.5_Deving/WS5b3ccc516d4fbf351e63e3d11a0773d56e-7ffa.html

編輯

在問候你的視頻路徑:

的Flash Media Server應用程序訪問

client.onBWDone = function(... rest){ // 
    if(rest && rest.length > 0){ //since the function might not get any data, you need to check before trying to trace it out 
     trace("onBWDone: " + rest[0]); //this is the kbps of the bandwidth available 
    } 
}; 

您可以從Adobe的文檔瞭解更多在rtmp上使用以下格式:「server:port/application/instance」。對於VOD,實例是您的文件的名稱,對於FLV,它不需要擴展名。

http://help.adobe.com/en_US/FlashMediaServer/3.5_Deving/WS5b3ccc516d4fbf351e63e3d11a0773cfae-7ff3.html

+0

謝謝你,非常不錯...這似乎清理「onBWDone:未定義」的錯誤,雖然我不知道「休息」空值是否是對我的CloudFront的應用程序中的問題或沒有。此外,帶寬可用變量聽起來也很有趣,我不知道這一點。該視頻仍然無法播放,儘管...希望這有助於彌補這個問題的答案。 – zakdances

+0

你的代碼對我來說看起來很好。您是否嘗試過使用預製播放器來查看服務器上是否存在問題?嘗試使用閃光燈播放器進行連接:http://www.osmf.org/configurator/fmp/ – BadFeelingAboutThis

+0

onBWDone僅用於獲取連接的帶寬,純粹是可選的,因此傳遞給它的值爲null不會影響你的程序。 – BadFeelingAboutThis

0

我改變

var videoFileName:String = "myVideo.flv"; 

var videoFileName:String = "myVideo"; 

,現在它的工作原理。出於某種原因,排除文件擴展名使它適用於我。我不知道爲什麼......奇怪。