AS2:没有网络流视频,只有音频

发布于 2024-12-15 09:21:16 字数 452 浏览 2 评论 0原文

所以我在加载网络流视频时遇到了 AS2 问题。

my_vid = _root.createEmptyMovieClip("my_vid", _root.getNextHighestDepth());
var video:Video = new Video();
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
video.attachVideo(ns);
my_vid.attachVideo(video);

and later 
ns.play("http://localhost/video.mp4");

我实际上可以在后台收听音频,但由于某种原因我看不到任何图片。我尝试只播放没有影片剪辑的视频,反之亦然,只听音频。

我肯定做错了什么,但是什么?

So I'm having a problem with AS2 when loading a netstream video.

my_vid = _root.createEmptyMovieClip("my_vid", _root.getNextHighestDepth());
var video:Video = new Video();
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
video.attachVideo(ns);
my_vid.attachVideo(video);

and later 
ns.play("http://localhost/video.mp4");

I can actually listen to the audio in background but for some reason i can't see any picture. I tried with a video only without a movieclip, and the other way around and keep listening only to audio.

I'm definitely doing something wrong but what?

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

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

发布评论

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

评论(1

回忆追雨的时光 2024-12-22 09:21:16

您的问题是您从未将视频对象附加到舞台上。此行 my_vid.attachVideo(video); 不执行任何操作,因为 MovieClip 没有名为 attachVideo 的方法。

您需要在库中创建一个视频对象并将其添加到舞台上。为此,请在 IDE 中执行以下步骤:

  1. 单击库面板右上角的箭头,然后从下拉列表中选择 New Video...
  2. 在对话框中,选择视频(ActionScript 控制) 单选按钮,然后单击“确定”。
  3. 将新创建的视频对象拖到舞台上并为其指定实例名称(例如myVideo)。
  4. 选择舞台上的视频对象,然后按 F8 以从中创建一个新元件。
  5. 将符号设置为MovieClip 类型,勾选导出为ActionScript 复选框并提供标识符(例如videoContainer),然后按确定。
  6. 从舞台中删除该元件,并将其保留在库中。

现在,您的库中有一个可以使用代码附加的项目,该项目已经包含可以使用的视频对象。假设您使用与我上面相同的名称,您的代码应按如下方式修改。

//attach the container from the library
my_vid = _root.attachMovie("videoContainer", "my_vid" _root.getNextHighestDepth());
//create a reference to the video object inside the container
var video:Video = my_vid.myVideo;
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
video.attachVideo(ns);
//
// ...
//
ns.play("http://localhost/video.mp4");

Your problem is that you don't ever attach the video object to the stage. This line my_vid.attachVideo(video); does nothing, because MovieClip does not have a method called attachVideo.

You need to create a video object in your library and add it to the stage. To do this, follow these steps in the IDE:

  1. Click the arrow at the top right of the libray panel and select New Video... from the dropdown.
  2. In the dialog box, Select the Video (ActionScript-controlled) radio button and click OK.
  3. Drag the newly created video object to the stage and give it an instance name (e.g. myVideo).
  4. Select your video object on the stage and press F8 to create a new symbol from it.
  5. Set the symbol to type MovieClip, tick the Export for ActionScript checkbox and give an Identifier (e.g. videoContainer), then press OK.
  6. Delete the symbol from the stage, keeping it in the library.

Now you have an item in your library that you can attach with code, that already contains a video object that is ready to work. Your code should be modified as follows, assuming you used the same names as I did above.

//attach the container from the library
my_vid = _root.attachMovie("videoContainer", "my_vid" _root.getNextHighestDepth());
//create a reference to the video object inside the container
var video:Video = my_vid.myVideo;
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
video.attachVideo(ns);
//
// ...
//
ns.play("http://localhost/video.mp4");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文