如何通过AVPlayer iOS以2.0的速率播放视频和音频

问题描述 投票:1回答:1

我正在使用iOS上的视频播放器。我想具有以2.0播放速度播放视频的功能。但是,当我将速率设置为2.0时,可以播放视频,但是这里没有声音。请帮助我,告诉我我错了。波纹管是我的代码:

        let url = URL(string: self.url)

        let asset = AVAsset(url: url!)

        if (!asset.isPlayable) {
            print (self.url + " cannot to play.")
            return

        }

        let playItem = AVPlayerItem(asset: asset)
        playItem.audioTimePitchAlgorithm = AVAudioTimePitchAlgorithm.lowQualityZeroLatency
        self.player = MyAVPlayer(playerItem: playItem)

        self.playerViewController = AVPlayerViewController()
        self.playerViewController?.player = self.player
        self.player?.allowsExternalPlayback = true

        // self.playerViewController?.showsPlaybackControls = self.showControl

        if (self.autoPlay) {
           // player?.play()
            player?.play()
            player?.rate = 2.0
        }
ios swift avplayer
1个回答
0
投票

经过一个月的研究,我找到了解决方案。非常简单,将2.0替换为1.99。我认为快速将2.0强制转换为浮点值时可能会出现问题,强制转换后的值可能是2.00000000003,大于2.0则不起作用。

© www.soinside.com 2019 - 2024. All rights reserved.