Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用AVPlayer清除音频?_Ios_Avfoundation - Fatal编程技术网

Ios 如何使用AVPlayer清除音频?

Ios 如何使用AVPlayer清除音频?,ios,avfoundation,Ios,Avfoundation,我在用seekToTime作为AVPlayer。它工作得很好,但是,我希望能够听到音频,因为我擦洗通过视频,就像最终剪辑或其他视频编辑器的工作方式。只是想寻找一些想法,或者我是否错过了一些明显的东西。实现这一点的方法是在视频旁边异步擦洗一个同步的AVplayer。我是这样做的(在Swift 4中): // create the simultaneous player and feed it the same URL: let videoPlayer2 = AVPlayer(url: sa

我在用seekToTime作为AVPlayer。它工作得很好,但是,我希望能够听到音频,因为我擦洗通过视频,就像最终剪辑或其他视频编辑器的工作方式。只是想寻找一些想法,或者我是否错过了一些明显的东西。

实现这一点的方法是在视频旁边异步擦洗一个同步的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
        }
}
}