-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
音视频 #13
Comments
AVPlayer 相关1. 如何停止播放?AVPlayer 没有 stop 方法,我们可以调用 pause 方法,或者设置 rate 为 0。
参考: 2. 针对下载再播的小视频,如何实现视频的下载和缓存逻辑?可以参考 SDWebImage 的实现,不同的地方在于,这里没有内存缓存,因为 AVPlayer 是直接从磁盘上加载文件的,如果要做优化的话,可以将每个 URL 对应的 AVURLAsset 对象缓存起来:
3. 如果要实现一个边下边播的播放器?该如何实现?参考:
4. 当使用 AVPlayer 播放视频被来电铃声、闹钟铃声打断时,如何恢复播放?iOS 6以后,可以通过处理 首先,设置
然后,注册通知:
最后,处理终端通知:
5. 如何实现后台播放 AVPlayer?
6. 针对播放线路(耳机、扬声器)改变的响应
7. 如何实现播放视频时,不中断其他应用中正在播放的音频?答:可以通过设置 AVAudioSession 单例的 category 和 option 来实现,代码如下:
Audio Session 是什么?系统通过 audio sessions 来管理 app 级、app 间和系统级的音频播放、录制行为。我们可以在 app 中通过使用 audio sessions 来告诉系统,我们需要怎样配置音频服务。 Audio Session 的 category 和 mode、options ?配置 Audio Session 行为的三个层级,最基本的是 category,在 category 的基础上可以通过设置 mode 和 category 来进行“微调”。 参考: 8. 如何知道 AVPlayer 是否正在播放?可以通过判断 AVPlayer 的 rate 属性值是否不为 0 来判断:
参考: |
如何实现在列表中播放多个视频的同时,保证滚动的流畅性?我自己是使用 AVPlayer 在列表中显示视频的,发现在一开始加载时会比较卡,在需要展示的 cell 都初始化完后,就明显流畅多了。 参考:
|
iOS 上播放视频的几种方式 |
如何判断一个视频文件是否可以播放?方式一:通过监听 AVPlayer 或者 AVPlayerItem 的 status 来判断。值得注意的是,如果你直接在初始化 AVPlayer 之后就同步获取这个值,这个值会是 “unknown”。
方式二:直接通过 url 新建一个 AVAsset 对象,再通过 isPlayable 属性判断视频是否可以正常播放。
结论:方法一是异步,方法二是同步。方法二比方法一要快了将近一倍。 参考: |
The text was updated successfully, but these errors were encountered: