gpt4 book ai didi

ios - 如何使用 AVPlayer 擦洗音频?

转载 作者:行者123 更新时间:2023-12-01 15:23:07 24 4
gpt4 key购买 nike

我将 seekToTime 用于 AVPlayer。它工作正常,但是,我希望在浏览视频时能够听到音频,就像 Final Cut 或其他视频编辑器的工作方式一样。只是在寻找想法,或者如果我错过了一些明显的东西。

最佳答案

做到这一点的方法是在视频旁边异步擦洗一个同步的 AVplayer。我是这样做的(在 Swift 4 中):

// create the simultaneous player and feed it the same URL:
let videoPlayer2 = AVPlayer(url: sameUrlAsVideoPlayer!)
videoPlayer2.volume = 5.0

//set the simultaneous player at exactly the same point as the video player.
videoPlayer2.seek(to: sameSeekTimeAsVideoPlayer)

// create a variable(letsScrub)that allows you to activate the audio scrubber when the video is being scrubbed:
var letsScrub: Bool?
//when you are scrubbing the video you will set letsScrub to true:
if letsScrub == true {audioScrub()}

//create this function to scrub audio asynchronously:
func audioScrub() {
DispatchQueue.main.async {

//set the variable to false so the scrubbing does not get interrupted:
self.letsScrub = false

//play the simultaneous player
self.videoPlayer2.play()

//make sure that it plays for at least 0.25 of a second before it stops to get that scrubbing effect:
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {

//now that 1/4 of a second has passed (you can make it longer or shorter as you please) - pause the simultaneous player
self.videoPlayer2.pause()

//now move the simultaneous player to the same point as the original videoplayer:
self.videoPlayer2.seek(to: self.sameSeekTimeAsVideoPlayer)

//setting this variable back to true allows the process to be repeated as long as video is being scrubbed:
self.letsScrub = true
}
}
}

关于ios - 如何使用 AVPlayer 擦洗音频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22705839/

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