0

Amazon の CloudFront/S3 サービスからビデオをストリーミングしようとしています。ファイル名が正しく、「NetConnection.Connect.Success」ステータスであるにもかかわらず、NetConnection 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

...そして何も起こりません。ビデオもオーディオも何もありません。誰でも私のコードに問題が見られますか?

4

2 に答える 2

1

すべてのストリーミング アプリケーションが onBWDone 関数を使用する必要があるわけではないと思います。したがって、使用しない場合は、kbps の代わりに null または undefined が関数に渡される可能性があります。

したがって、e以下のトレースステートメントに問題がある可能性があります。

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

また、この関数はイベント オブジェクトを受け取るのではなく、... rest通常は 1 つの項目しか持たない配列を受け取ります。代わりにこれを試してください:

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
    }
};

詳細については、次のAdob ​​e ドキュメントを参照して ください。

編集

ビデオパスに関して:

Flash Media Server アプリケーションは、rtmp 経由で「サーバー:ポート/アプリケーション/インスタンス」の形式でアクセスされます。VOD の場合、インスタンスはファイルの名前であり、FLV の場合は拡張子は必要ありません。

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

于 2012-09-10T02:33:18.540 に答える
0

私が変更され

var videoFileName:String = "myVideo.flv";

var videoFileName:String = "myVideo";

そして今それは動作します。何らかの理由で、ファイル拡張子を除外するとうまくいきます。理由はわかりません...奇妙です。

于 2012-09-10T22:49:31.590 に答える