видео поток: onBWDone: недефиниран и видеото не се възпроизвежда

Опитвам се да предавам поточно видео от услугата CloudFront/S3 на Amazon. Въпреки че името на файла ми е правилно и състоянието „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

...и нищо не се случва. Няма видео, няма аудио, нищо. Може ли някой да види проблеми с моя код?


person zakdances    schedule 10.09.2012    source източник


Отговори (2)


Вярвам, че не всички стрийминг приложения трябва да използват функцията onBWDone, така че ако не я използват, тя вероятно предава null или undefined на функцията вместо kbps.

Така че вашият проблем вероятно е с e в израза ви за проследяване по-долу:

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

Освен това функцията не получава обект на събитие, а по-скоро масив ... rest, който обикновено има само един елемент в него. опитайте това вместо това:

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: http://help.adobe.com/en_US/FlashMediaServer/3.5_Deving/WS5b3ccc516d4fbf351e63e3d11a0773d56e-7ffa.html

РЕДАКТИРАНЕ

По отношение на вашия видео път:

Приложенията на Flash Media Server се осъществяват в следния формат през rtmp: "сървър:порт/приложение/екземпляр". За VOD екземплярът е името на вашия файл, а за FLV не изисква разширението.

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

person BadFeelingAboutThis    schedule 10.09.2012
comment
Благодаря ви, много хубаво...това изглежда изчисти грешката onBWDone: undefined, въпреки че не знам дали нулевата стойност за rest е проблем или не за моето CloudFront приложение. Също така наличната променлива на честотната лента също звучи интересно, не знаех за това. Въпреки това видеото все още не се възпроизвежда... надяваме се, че това ще ви помогне да намерите отговор на този въпрос. - person zakdances; 10.09.2012
comment
Вашият код ми изглежда добре. Опитахте ли да използвате предварително вграден плейър, за да видите дали може би проблемът е в сървъра? Опитайте да се свържете със строб плейъра: osmf.org/configurator/fmp - person BadFeelingAboutThis; 10.09.2012
comment
onBWDone се използва само за получаване на честотната лента на връзката, чисто по избор, така че предадената му стойност да е нула няма да засегне програмата ви изобщо. - person BadFeelingAboutThis; 10.09.2012
comment
Проверете отговора, който току-що публикувах. Сега работи в резултат на премахване на файловото разширение на моя низ на videoFileName. - person zakdances; 11.09.2012
comment
Трябва да имате нещо във вашето FMS приложение, което обърква .flv нещо. По подразбиране ще приеме файла със или без разширение .flv. - person BadFeelingAboutThis; 11.09.2012

промених се

var videoFileName:String = "myVideo.flv";

to

var videoFileName:String = "myVideo";

и сега работи. По някаква причина изключването на файловото разширение го кара да работи за мен. Не знам защо... странно.

person zakdances    schedule 10.09.2012