作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将 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/
我已经按照此处讨论的方式实现了搜索(AVAssetReader Seeking),但是在拆除 AVAssetReader 并构建新的 AVAssetReader 时当然会有明显的延迟(因为一旦开始读取
我想向用户展示一个嵌入的 HTML YouTube 视频,并防止他们快进或跳到视频的末尾。我可以通过使用 YouTube 的 API 删除播放器控件(请参阅代码片段)来获得大部分内容,但是在 iOS
在 Apple 的 AVPlayerDemoPlaybackViewController 中将 mPlayer.usesExternalPlaybackWhileExternalScreenIsAct
我是一名优秀的程序员,十分优秀!