`
izuoyan
  • 浏览: 8879881 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Adobe荐文:处理Flash视频里的元数据和录像暗点

阅读更多

所需条件:
用户水平: 中级以上
产品: Flash Professional(下载 试用版 )
样例文件example01.zip example02.zip example03.zip
example04.zip example05.zip example06.zip example07.zip


这篇速成文章描述了在使用NetConnection和NetStream类时,采用onMetaData和onCuePoint这两个回调函数来装载Flash
视频 (FLVs)。你将发现如何通过使用asyncError事件 (AsyncErrorEvent.ASYNC_ERROR),或NetStream类里的client属性来掌握或忽略元数据 或录像暗点(Cue Point)。

下面的部分讲述了用最流行和实用的方式来对正在装载的视频使用asyncError和client属性。


用NetConnection和NetStream类装载视频


很多情况下你会更与愿意创造你自己定制的视频
播放器 来代替既有的组件 。比如,你试图在自己的个性播放器上加一些特性,又或者试图做一个非常轻量级的文件。当你要建立自己的代码 的时候,理解onMetaData和onCuePoint事件如何使用是很重要的。它使你能根据情况使用。

例子


接下来的例子在一个
swf 文件里创建了一个新的NetConnection,NetStream和Video对象来动态地装载一个FLV文件。


虽然这个特定的FLV含有元数据和3个录像暗点,却没有定义onMetaData和onCuePoint事件的处理器。asyncError被分发以提示你NetStream类无法相应地引用onMetaData和onCuePoint的回调。


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

var ns:NetStream = new NetStream(nc);
ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");

var myVideo:Video = new Video();
myVideo.attachNetStream(ns);
addChild(myVideo);


结果

之前的例子装载了一个Flash视频并播放。一旦遇到视频的元数据或录像暗点,asyncError就会被分发。

如果你在Flash创作环境里运行这段代码,你将会在输出面板看到类似于后面所示的4个错误信息。


Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetStream was unable to invoke callback onMetaData. error=ReferenceError: Error #1069: Property onMetaData not found on flash.net.NetStream and there is no default value.
at asyncErrorExample_fla::MainTimeline/asyncErrorExample_fla::frame1()
Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetStream was unable to invoke callback onCuePoint. error=ReferenceError: Error #1069: Property onCuePoint not found on flash.net.NetStream and there is no default value.
at asyncErrorExample_fla::MainTimeline/asyncErrorExample_fla::frame1()
Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetStream was unable to invoke callback onCuePoint. error=ReferenceError: Error #1069: Property onCuePoint not found on flash.net.NetStream and there is no default value.
at asyncErrorExample_fla::MainTimeline/asyncErrorExample_fla::frame1()
Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetStream was unable to invoke callback onCuePoint. error=ReferenceError: Error #1069: Property onCuePoint not found on flash.net.NetStream and there is no default value.
at asyncErrorExample_fla::MainTimeline/asyncErrorExample_fla::frame1()


而如果你在一个网页浏览器里看到这个在线SWF,你会看到以下错误(error):

pic-1.jpg



为防止这些错误,你有两种主要的解决方案:

1. 加一个asyncError事件的监听器;
2. 为NetStream对象的client属性设一个值。

要获取这个例子的源文件,你可以下载本页面顶部的example01.zip。其中包括了Flash Proffessional CS5版本下的文件。


监听NetStream对象的asyncError事件


掌握被NetStream对象所分发的asyncError事件的最简单方式就是用addEventListener()方法进行监听。这可以让你选择处理或者忽略事件。


例子


后面的例子装载了一个FLV文件并在asyncError被分发的时候打印(trace)了asyncError事件的text属性。


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

var ns:NetStream = new NetStream(nc);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");

var myVideo:Video = new Video();
myVideo.attachNetStream(ns);
addChild(myVideo);

function asyncErrorHandler(event:AsyncErrorEvent):void {
trace(event.text);
}


结果
如果你在Flash创作环境运行以上代码,你会看到输出面板上会显示如下文本:


Error #2095: flash.net.NetStream was unable to invoke callback onMetaData.
Error #2095: flash.net.NetStream was unable to invoke callback onCuePoint.
Error #2095: flash.net.NetStream was unable to invoke callback onCuePoint.
Error #2095: flash.net.NetStream was unable to invoke callback onCuePoint.


本帖最后由 chocoZero 于 2010-12-14 10:24 编辑

所需条件:

用户水平: 中级以上
产品: Flash Professional(下载 试用版 )
样例文件example01.zip example02.zip example03.zip
example04.zip example05.zip example06.zip example07.zip


这篇速成文章描述了在使用NetConnection和NetStream类时,采用onMetaData和onCuePoint这两个回调函数来装载Flash
视频 (FLVs)。你将发现如何通过使用asyncError事件 (AsyncErrorEvent.ASYNC_ERROR),或NetStream类里的client属性来掌握或忽略元数据 或录像暗点(Cue Point)。

下面的部分讲述了用最流行和实用的方式来对正在装载的视频使用asyncError和client属性。


用NetConnection和NetStream类装载视频


很多情况下你会更与愿意创造你自己定制的视频
播放器 来代替既有的组件 。比如,你试图在自己的个性播放器上加一些特性,又或者试图做一个非常轻量级的文件。当你要建立自己的代码 的时候,理解onMetaData和onCuePoint事件如何使用是很重要的。它使你能根据情况使用。

例子


接下来的例子在一个
swf 文件里创建了一个新的NetConnection,NetStream和Video对象来动态地装载一个FLV文件。


虽然这个特定的FLV含有元数据和3个录像暗点,却没有定义onMetaData和onCuePoint事件的处理器。asyncError被分发以提示你NetStream类无法相应地引用onMetaData和onCuePoint的回调。
  1. var nc:NetConnection = new NetConnection();
  2. nc.connect(null);

  3. var ns:NetStream = new NetStream(nc);
  4. ns.play("http://www.helpexamples.com/flash /video/cuepoints.flv ");

  5. var myVideo:Video = new Video();
  6. myVideo.attachNetStream(ns);
  7. addChild(myVideo);
复制代码
结果

之前的例子装载了一个Flash视频并播放。一旦遇到视频的元数据或录像暗点,asyncError就会被分发。

如果你在Flash创作环境里运行这段代码,你将会在输出面板看到类似于后面所示的4个错误信息。
  1. Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetStream was unable to invoke callback onMetaData. error=ReferenceError: Error #1069: Property onMetaData not found on flash.net.NetStream and there is no default value.
  2. at asyncErrorExample_fla::MainTimeline/asyncErrorExample_fla::frame1()
  3. Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetStream was unable to invoke callback onCuePoint. error=ReferenceError: Error #1069: Property onCuePoint not found on flash.net.NetStream and there is no default value.
  4. at asyncErrorExample_fla::MainTimeline/asyncErrorExample_fla::frame1()
  5. Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetStream was unable to invoke callback onCuePoint. error=ReferenceError: Error #1069: Property onCuePoint not found on flash.net.NetStream and there is no default value.
  6. at asyncErrorExample_fla::MainTimeline/asyncErrorExample_fla::frame1()
  7. Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetStream was unable to invoke callback onCuePoint. error=ReferenceError: Error #1069: Property onCuePoint not found on flash.net.NetStream and there is no default value.
  8. at asyncErrorExample_fla::MainTimeline/asyncErrorExample_fla::frame1()
复制代码
而如果你在一个网页浏览器里看到这个在线SWF,你会看到以下错误(error):

pic-1.jpg


为防止这些错误,你有两种主要的解决方案:

1. 加一个asyncError事件的监听器;
2. 为NetStream对象的client属性设一个值。

要获取这个例子的源文件,你可以下载本页面顶部的example01.zip。其中包括了Flash Proffessional CS5版本下的文件。


监听NetStream对象的asyncError事件


掌握被NetStream对象所分发的asyncError事件的最简单方式就是用addEventListener()方法进行监听。这可以让你选择处理或者忽略事件。


例子


后面的例子装载了一个FLV文件并在asyncError被分发的时候打印(trace)了asyncError事件的text属性。
  1. var nc:NetConnection = new NetConnection();
  2. nc.connect(null);

  3. var ns:NetStream = new NetStream(nc);
  4. ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
  5. ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");

  6. var myVideo:Video = new Video();
  7. myVideo.attachNetStream(ns);
  8. addChild(myVideo);

  9. function asyncErrorHandler(event:AsyncErrorEvent):void {
  10. trace(event.text);
  11. }
复制代码
结果
如果你在Flash创作环境运行以上代码,你会看到输出面板上会显示如下文本:
  1. Error #2095: flash.net.NetStream was unable to invoke callback onMetaData.
  2. Error #2095: flash.net.NetStream was unable to invoke callback onCuePoint.
  3. Error #2095: flash.net.NetStream was unable to invoke callback onCuePoint.
  4. Error #2095: flash.net.NetStream was unable to invoke callback onCuePoint.
复制代码
如果你是在网页浏览器上看在线的这个SWF,将不会看到任何错误提示。因为你处理了asyncError事件。

要获取这个例子的源文件,你可以下载本页面顶部的example02.zip。其中包括了Flash Proffessional CS5版本下的文件。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics