Actionscript - 视频播放器帮助! - 闪光

发布于 2024-11-05 00:18:28 字数 296 浏览 0 评论 0原文

几天来我一直在尝试弄清楚如何让视频在 Flash 中播放,但几乎一无所获。我有下面的代码,但不知道还有什么可以尝试让它工作。有人可以帮忙吗?

var conn:NetConnection = new NetConnection();
conn.connect(null);

var nstream:NetStream = new NetStream(conn);
nstream.setBufferTime(10);

trailer.attach(nstream);
nstream.play("arthur.flv");

I've been trying for days to figure out how to get a video to play in flash and I have got pretty much nowhere. I have the code below but have no idea what else to try to get it to work. Can anyone please help?

var conn:NetConnection = new NetConnection();
conn.connect(null);

var nstream:NetStream = new NetStream(conn);
nstream.setBufferTime(10);

trailer.attach(nstream);
nstream.play("arthur.flv");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

双马尾 2024-11-12 00:18:28

看来您忘记了一个关键部分,您需要在 NetConnection 连接成功后将 NetStream 添加到视频对象。


var connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

function netStatusHandler(event:NetStatusEvent):void {
      switch (event.info.code) {
          case "NetConnection.Connect.Success":
              connectStream();
              break;
          case "NetStream.Play.StreamNotFound":
               trace("Stream not found: " + videoURL);
                break;
          }
}

function connectStream():void {
    stream = new NetStream(connection);
    stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
    stream.client = new CustomClient();
    var video:Video = new Video();
    video.attachNetStream(stream);
    stream.play(videoURL);
    addChild(video);
}

请在此处查看 AS3 NetStream 文档。这里有很多信息和示例可以帮助您上路。

Looks like you forgot one crutial part, you need to add the NetStream to a video object after the NetConnection has connected successfully.


var connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

function netStatusHandler(event:NetStatusEvent):void {
      switch (event.info.code) {
          case "NetConnection.Connect.Success":
              connectStream();
              break;
          case "NetStream.Play.StreamNotFound":
               trace("Stream not found: " + videoURL);
                break;
          }
}

function connectStream():void {
    stream = new NetStream(connection);
    stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
    stream.client = new CustomClient();
    var video:Video = new Video();
    video.attachNetStream(stream);
    stream.play(videoURL);
    addChild(video);
}

Take a look at the AS3 NetStream docs here. Theres ALOT of info and examples there to get you on your way.

叫思念不要吵 2024-11-12 00:18:28

舞台上是否添加了预告片?像这样:

var trailer = new Video(); 
trailer.attachNetStream(nstream); 
addChild(trailer); 

您还检查过 NetStream 是否没有产生错误?像这样:

nstream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); 
nstream.play("video.flv"); 
function asyncErrorHandler(event:AsyncErrorEvent):void{ 
    trace(event);
} 

编辑:您还检查过网络状态和安全错误吗?像这样:

nstream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
conn.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
conn.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

function netStatusHandler(event:NetStatusEvent):void {
     switch (event.info.code) {
         case "NetConnection.Connect.Success":
             connectStream();
             break;
         case "NetStream.Play.StreamNotFound":
             trace("Unable to locate video: " + videoURL);
             break;
     }
} 

function securityErrorHandler(event:SecurityErrorEvent):void {
    trace("securityErrorHandler: " + event);
}

Is trailer added to the stage? Like this:

var trailer = new Video(); 
trailer.attachNetStream(nstream); 
addChild(trailer); 

Also have you checked that the NetStream doesn't produce an error? Like this:

nstream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); 
nstream.play("video.flv"); 
function asyncErrorHandler(event:AsyncErrorEvent):void{ 
    trace(event);
} 

Edit: Also have you check the net status and security errors? Like this:

nstream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
conn.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
conn.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

function netStatusHandler(event:NetStatusEvent):void {
     switch (event.info.code) {
         case "NetConnection.Connect.Success":
             connectStream();
             break;
         case "NetStream.Play.StreamNotFound":
             trace("Unable to locate video: " + videoURL);
             break;
     }
} 

function securityErrorHandler(event:SecurityErrorEvent):void {
    trace("securityErrorHandler: " + event);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文