判断一个视频播放结束

其实下面那篇参考文章提到的问题眼下对我来讲意义不大。因为我需要做的事情只是当一个视频在播放中被中断时,进行一些必要的清理工作,比如释放资源。


通常播放本地磁盘上的flv/f4v文件的代码写法是:


this._video = new Video();
this._connection = new NetConnection();
this._connection.connect(null);
this._stream = new NetStream(this._connection);
this._video.attachNetStream(this._stream);
this._clientObject = new Object();
this._clientObject.onMetaData = this.metaDataListener;
this._clientObject.onXMPData = this.XMPDataListener;
this._clientObject.onTextData = this.XMPDataListener;
this._stream.client = this._clientObject;
this._stream.addEventListener(NetStatusEvent.NET_STATUS, this.netStreamStatusHandler);
this._stream.addEventListener(IOErrorEvent.IO_ERROR, this.netStreamIOErrorsHandler);
this._stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, this.netStreamAsynErrorsHandler);
this.addChild(this._video);
this._stream.play(this._file);

当将 _video 从playlist中移走,或者当前播放的视频文件已经播放完——即收到 Stream.Play.Stop 事件——都不会令NetStream关闭与这个资源的链接,所以一定要呼叫 _stream.close() ,当然建议在这个操作前做判断 if(this._stream) ,以免收到空引用的异常。


在close()被执行之后,当前播放中的视频会被终止,并且Flash的播放器(AIR)会释放这个视频文件的资源给windows,于是该视频文件就可以被其他软件使用,也可以被删除或重写。


正常来讲,播放一个视频文件的过程中收到的NetStatus事件的顺序是:


NetStream.Play.Start
NetStream.Buffer.Full
NetStream.Buffer.Flush
NetStream.Buffer.Flush
.......
NetStream.Buffer.Empty
NetStream.Buffer.Flush
NetStream.Play.Stop




Refs:

http://huisecheng.com/blog/2011/07/netstream%E7%9C%9F%E6%AD%A3%E7%9A%84%E6%92%AD%E6%94%BE%E5%AE%8C%E6%AF%95%E5%88%A4%E6%96%AD-as3/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是符合要求的BAT代码: ```bat @echo off set /a count=0 :start set /a count+=1 echo -----------------Round %count%----------------- rem 随机看新闻10分钟 echo Start reading news... set /a time_limit=600 set /a time_elapsed=0 :read_news set /a time=180+%random% %% 120 set /a time_elapsed+=%time% if %time_elapsed% leq %time_limit% ( echo Reading news for %time% seconds... timeout /t %time% >nul goto read_news ) else ( echo Finished reading news. ) rem 看视频20分钟 echo Start watching videos... set /a time_limit=1200 set /a time_elapsed=0 :watch_videos set /a time=360+%random% %% 240 set /a time_elapsed+=%time% if %time_elapsed% leq %time_limit% ( echo Watching videos for %time% seconds... timeout /t %time% >nul goto watch_videos ) else ( echo Finished watching videos. ) if %count% lss 3 goto start echo All done! pause ``` 代码解释: 1. `count` 变量用于记录已执行的循环次数。 2. `time_limit` 变量用于记录每个操作的时间上限(单位:秒)。 3. `time_elapsed` 变量用于记录每个操作已经执行的时间(单位:秒)。 4. `set /a time=180+%random% %% 120` 和 `set /a time=360+%random% %% 240` 分别用于生成随机的新闻和视频播放时间(范围分别为 3~5 分钟和 6~10 分钟)。 5. `timeout /t %time% >nul` 用于等待一段时间,其中 `>nul` 表示不在屏幕上显示等待的时间。 6. `if %count% lss 3 goto start` 用于判断是否已经执行了 3 次循环,如果是则结束程序。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值