目录

页面上下滑动后视频重新播放

问题现象

进入页面后视频正常播放,下滑页面至一定位置后,视频声音停止,重新上滑到视频所处位置,视频重新开始播放。

背景知识

问题定位

  1. 通过DevEco Testing软件的UIViewer可以查看到视频组件为Video,整体页面通过List组件进行组合。

  2. 在上下滑动过程中搜索日志关键词Player current status可以观察到视频进入了STOPPED状态,重新上滑后又恢复到STARTED播放状态。
    07-23 19:32:06.579   53213-53213   C03906/com.hm.example/AceVideo  com.hm.example     I     [(100000:100000:scope)] Player current status is PREPARED.
    07-23 19:32:06.605   53213-53213   C03906/com.hm.example/AceVideo  com.hm.example     I     [(100000:100000:scope)] Player current status is STARTED.
    07-23 19:32:21.971   53213-53213   C03906/com.hm.example/AceVideo  com.hm.example     I     [(100000:100000:scope)] Player current status is STOPPED.
    07-23 19:32:26.600   53213-53213   C03906/com.hm.example/AceVideo  com.hm.example     I     [(100000:100000:scope)] Player current status is PREPARED.
    07-23 19:32:26.622   53213-53213   C03906/com.hm.example/AceVideo  com.hm.example     I     [(100000:100000:scope)] Player current status is STARTED.
  3. 检查代码中List组件是否配置了cachedCount参数。

分析结论

使用List组件以及配置cachedCount属性会导致组件滑出时组件被其他ListItem占用,视频播放暂停;当对应组件滑动至界面时,Video组件重新创建并初始化播放资源,导致重新开始播放。

修改建议

将Video组件从List组件中剥离单独显示,可以参考如下代码: