gpt4 book ai didi

ios - AVPlayer 仅以选定的速率播放一次

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:32:13 25 4
gpt4 key购买 nike

我遇到了 AVPlayer 的问题。案例是:我有一个功能,可以设置 AVPlayer 的速率

func applyEffect(effectNumber : Int) {
switch effectNumber {
case 0:
self.AvPlayer.setRate(Float(1.0), time: kCMTimeInvalid, atHostTime: kCMTimeInvalid)
case 1:
self.AvPlayer.setRate(Float(1.5), time: kCMTimeInvalid, atHostTime: kCMTimeInvalid)
case 2:
self.AvPlayer.setRate(Float(0.5), time: kCMTimeInvalid, atHostTime: kCMTimeInvalid)
default:
self.AvPlayer.setRate(Float(1.0), time: kCMTimeInvalid, atHostTime: kCMTimeInvalid)
}
}

对于每个响应,我都会将音频文件下载到 AVPlayerItem 并将它们保存为数组。如果 AVPlayerItem.status 更改,我有一个项目观察者调用 applyEffect 函数,否则它会立即应用效果:

if AVCurrentItem.status != AVPlayerItemStatus.readyToPlay {
AVCurrentItem.addObserver(self, forKeyPath: "status", options: NSKeyValueObservingOptions.new, context: nil)
pushMessageLoading()
} else {
self.applyEffect(effectNumber: currentEffect)
}

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "status" {
popMessageLoading()
self.applyEffect(effectNumber: currentEffect)
AVCurrentItem.removeObserver(self, forKeyPath: "status")
}

}

AVPlayer 属性“automaticallyWaitsToMinimizeStalling”在初始化期间设置为 false。因此,第一次音频以请求的速率播放,但之后所有时间都以 1.0 之类的速率播放。有什么问题?

最佳答案

罪恶的根源很简单:我使用了 AVPlayer.play,它等于 AVPlayer.rate = 1.0,而不是你需要使用 AVPlayer.rate = desired value

关于ios - AVPlayer 仅以选定的速率播放一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45529995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com