我试图从流亚马逊的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
...并没有任何反应。没有视频,没有音频,什么都没有。任何人都可以看到我的代码的任何问题?
谢谢你,非常不错...这似乎清理“onBWDone:未定义”的错误,虽然我不知道“休息”空值是否是对我的CloudFront的应用程序中的问题或没有。此外,带宽可用变量听起来也很有趣,我不知道这一点。该视频仍然无法播放,尽管...希望这有助于弥补这个问题的答案。 – zakdances
你的代码对我来说看起来很好。您是否尝试过使用预制播放器来查看服务器上是否存在问题?尝试使用闪光灯播放器进行连接:http://www.osmf.org/configurator/fmp/ – BadFeelingAboutThis
onBWDone仅用于获取连接的带宽,纯粹是可选的,因此传递给它的值为null不会影响你的程序。 – BadFeelingAboutThis