【转】iOS:AvPlayer设置播放速度不生效的解决办法
现象:
项目有一个需求是实现视频的慢速播放,使用的是封装的AvPlayer,但是设置时发现比如设置rate为0.5,0.1,0.01都是一样的速度,非常疑惑.后来经过查找资料,发现iOS
10对这个API进行了更新
iOS10之前官方API对AvPlayer rate属性的解释是
/*!
@property rate
@abstract Changes the playback rate of the input signal
@discussion A value of 2.0 results in the output audio playing one octave higher.A value of 0.5, results in the output audio playing one octave lower.
Range: 0.5 -> 2.0
Default: 1.0
Mixer: AVAudioEnvironmentNode
*/
由上,我们可以发现这个rate只是支持0.5-2倍的
iOS10更新后对AvPlayer rate属性的解释是
/*!
@property rate
@abstract Indicates the desired rate of playback; 0.0 means "paused", 1.0 indicates a desire to play at the natural rate of the current item.
@discussion
Setting the value of rate to 0.0 pauses playback, causing the value of timeControlStatus to change to AVPlayerTimeControlStatusPaused.
Setting the rate to a non-zero value causes the value of timeControlStatus to become either AVPlayerTimeControlStatusWaitingToPlayAtSpecifiedRate or AVPlayerTimeControlStatusPlaying, depending on whether sufficient media data has been buffered for playback to occur and whether the player's default behavior of waiting in order to minimize stalling is permitted. See discussion of AVPlayerTimeControlStatus for more details.
AVPlayer can reset the desired rate to 0.0 when a change in overall state requires playback to be halted, such as when an interruption occurs on iOS, as announced by AVAudioSession, or when the playback buffer becomes empty and playback stalls while automaticallyWaitsToMinimizeStalling is NO.
The effective rate of playback may differ from the desired rate even while timeControlStatus is AVPlayerTimeControlStatusPlaying, if the processing algorithm in use for managing audio pitch requires quantization of playback rate. For information about quantization of rates for audio processing, see AVAudioProcessingSettings.h. You can always obtain the effective rate of playback from the currentItem's timebase; see the timebase property of AVPlayerItem.
*/
在代码中设置小于0.5的值一直不生效,查找资料,好像只是支持
I actually had a ticket with Apple DTS open for this issue and a bug filed. The only supported values are 0.50, 0.67, 0.80, 1.0, 1.25, 1.50, and 2.0. All other settings are rounded to nearest value.
详见 解决办法
这里面有人提供了这样一种办法:
I found that smaller values are indeed supported, but all tracks in the AVPlayerItem have to support the speed. However, Apple does not provide a property on individual tracks that would indicate what rates are supported, there is only the property canPlaySlowForward on AVPlayerItem.
What i found is, that AVPlayerItems with an audio track cannot play at rates slower than 0.5. However, if there is only a video track, the rate can have an arbitrary small value like 0.01. I will try to write a category that checks on-the-fly which values are supported and disable unsupported tracks if needed.
//I wrote a function which you can call whenever you want to set the rate for video below 0.5. It enables/disables all audio tracks.
- (void)enableAudioTracks:(BOOL)enable inPlayerItem:(AVPlayerItem*)playerItem
{
for (AVPlayerItemTrack *track in playerItem.tracks)
{
if ([track.assetTrack.mediaType isEqual:AVMediaTypeAudio])
{
track.enabled = enable;
}
}
}
我使用此方法解决了我的问题,非常感谢!!!!!特此记录,备忘!
from:http://www.jianshu.com/p/555cc5b88f6b
【转】iOS:AvPlayer设置播放速度不生效的解决办法的更多相关文章
- iOS 全局禁止横屏,但UIWebView 全屏播放视频,横屏,解决办法(任意页面横竖屏或禁止)
iOS 全局禁止横屏,但UIWebView 全屏播放视频,横屏,解决办法 时间 2015-07-14 20:59:00 博客园-原创精华区 原文 http://www.cnblogs.com/fe ...
- discuz论坛后台部分设置更改之后,清除了缓存网站前台不更新不生效的解决办法
discuz论坛后台部分设置更改之后,清除了缓存但网站前台不更新不生效的解决办法 在config/config_global.php 把 $_config['memory']['eaccelera ...
- 微信小程序警告设置 enable-flex 属性以使 flexbox 布局生效的解决办法
微信小程序警告设置 enable-flex 属性以使 flexbox 布局生效的解决办法 具体情况: scroll-view 滚动,设置 display:flex 不生效并警告设置 enable-fl ...
- WIN8.1的安装和打开"这台电脑"速度很慢的解决办法
WIN8.1的安装和打开"这台电脑"速度很慢的解决办法 对于非服务器用的电脑,如果电脑的内存在2G或更高,首推的操作系统是 WINDOWS8.1 64位企业版,用了就知道,没有比这流畅懂事的操作系统. ...
- Git忽略规则及.gitignore规则不生效的解决办法
在git中如果想忽略掉某个文件,不让这个文件提交到版本库中,可以使用修改根目录中 .gitignore 文件的方法(如无,则需自己手工建立此文件).这个文件每一行保存了一个匹配的规则例如: # 此为注 ...
- .gitignore规则不生效的解决办法
.gitignore规则不生效的解决办法 使用git 的时候,在.gitignore中已经添加了某个文件或者文件夹,但是使用git status还能看见该文件的修改提示--–说明.gitignore未 ...
- Git忽略规则和.gitignore规则不生效的解决办法
Git忽略规则和.gitignore规则不生效的解决办法 Git忽略规则: 在git中如果想忽略掉某个文件,不让这个文件提交到版本库中,可以使用修改根目录中 .gitignore 文件的方法(如果 ...
- 【转载】Git忽略规则和.gitignore规则不生效的解决办法
原文:https://www.cnblogs.com/zhangxiaoliu/p/6008038.html Git忽略规则: 在git中如果想忽略掉某个文件,不让这个文件提交到版本库中,可以使用修改 ...
- 极光推送设置标签和别名无效的解决办法:JPush设置别名不走成功回调
极光推送设置标签和别名无效的解决办法 JPush设置别名不走成功回调的解决办法 http://www.cnblogs.com/chenqitao/p/5506023.html 主要是网络加载过快导致的 ...
随机推荐
- Android sdk manager 下载速度慢的问题
不多说了,直接附上方法: 首先打开Ecplise 中Android sdk manager,打开后, 在此窗口的上方打开偏好设置选项,然后在里面设置HTTP Proxy server和HTTP Pro ...
- 修复IE7浮动元素自动换行的bug
bug重现以及修复后的表现 2. HTML源码 <!doctype html> <html> <head> <meta charset="utf-8 ...
- PHP通过api上传图片
参考:接口实现图片上传 提交端: $url="localhost:805/rdyc/123.jpg"; $img=file_get_contents($url); $img_api ...
- 浏览器从输入到输出的过程与原理三之DNS
1. DNS 在互联网上的每一个计算机都拥有一个唯一的地址,称作“IP地址”(即互联网协议地址).由于IP地址(为一串数字)不方便记忆,DNS允许用户使用一串常见的字母(即“域名”)取代.比如,您只需 ...
- 使用镶嵌数据集 MosaicDataSet管理不同分辨率影像数据
镶嵌数据集 MosaicDataSet是Esri推出的一种用于管理海量影像数据的数据模型,它是Geodatabase数据模型的一个子集定义. 该数据模型强大之处在于它能统一管理不同采集时间.不同采集来 ...
- 解决移动端touch事件(touchstart/touchend) 的穿透问题
情景: 我们在移动端点击事件click对比touchend会有很明显的300ms的延迟,为啥? 浏览器在 click 后会等待约300ms去判断用户是否有双击行为(手机需要知道你是不是想双击放大网页内 ...
- CSS的设计模式
什么是设计模式? 曾有人调侃,设计模式是工程师用于跟别人显摆的,显得高大上:也曾有人这么说,不是设计模式没用,是你还没有到能懂它,会用它的时候. 先来看一下比较官方的解释:“设计模式(Design p ...
- iOS上Delegate的悬垂指针问题
文章有点长,写的过程很有收获,但读的过程不一定有收获,慎入 [摘要] 悬垂指针(dangling pointer)引起的crash问题,是我们在iOS开发过程当中经常会遇到的.其中由delegat ...
- struts2 开发模式
在struts.xml中增加: <constant name="struts.devMode" value="true" />
- mysql的日期函数介绍
仅供参考 DAYOFWEEK(date) 返回日期date是星期几(1=星期天,2=星期一,……7=星期六,ODBC标准)mysql> select DAYOFWEEK('1998-02-03 ...