大家好我想尝试使用Avplayer从s3播放视频。现在,如果我播放视频,视频将在整个视频缓冲后开始播放。所以我添加了player.automaticallyWaitsToMinimizeStalling = false
,但现在视频会自动暂停
import UIKit
import AVFoundation
import AVKit
class ViewController: UIViewController {
var player: AVPlayer!
var item : AVPlayerItem!
override func viewDidLoad() {
super.viewDidLoad()
item = AVPlayerItem(url: URL(string: "https://cent-churchconnect.s3-ap-southeast-2.amazonaws.com/cent-churchconnect/testAdmin/eb8cc8b5-80e0-468a-a2c9-979cf1b5ac76_toystory.mp4")!)
player = AVPlayer(playerItem: item)
let controller = AVPlayerViewController()
present(controller, animated: true) { _ in }
controller.player = player
addChildViewController(controller)
view.addSubview(controller.view)
controller.view.frame = CGRect(x: 0, y: 50, width: self.view.frame.size.width, height: 300)
controller.player = player
controller.showsPlaybackControls = true
if #available(iOS 10.0, *) {
player.automaticallyWaitsToMinimizeStalling = false
player.play()
} else {
// Fallback on earlier versions
}
}
}
答案 0 :(得分:1)
以下步骤对我有用,我遇到了同样的问题,
尝试使用方法func playImmediately(atRate:)
,并确保属性player.automaticallyWaitsToMinimizeStalling = false
的设置正确。
答案 1 :(得分:0)
使用方法func playImmediately(atRate:)
代替func play()
答案 2 :(得分:0)
我使用了可可豆荚https://github.com/piemonte/Player。
您可以使用委托方法来控制播放。