非常感谢您提前提供的所有帮助!
有时,AVPlayer无法播放视频,而是显示交叉播放图标。调试起来很困难,因为它只是偶尔发生在不同位置的某些用户。该视频非常适合其他人。文件格式包括.mov和.mp4。
我发现最接近的StackOverflow问题和答案是:iOS AVPlayer showing screen with a cross line on Play icon
我将内容托管在数字海洋空间中。正如以上评论员所指出的那样-它可能链接到慢速网络,并且当AVPlayer没有足够的数据进行缓冲时。在哪里可以找到关于此的更多文档?还是其他人在某些地区的网络连接速度较慢的经验?
func setupVideoPlayback() {
player?.replaceCurrentItem(with: nil)
let movieURL = // MY URL
let asset = AVURLAsset(url: movieURL, options: nil)
let playerItem = AVPlayerItem(asset: asset)
player = AVPlayer(playerItem: playerItem)
player?.automaticallyWaitsToMinimizeStalling = false
NotificationCenter.default.addObserver(self, selector: #selector(VideoPlayerViewController.playerDidFinishPlaying), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player?.currentItem)
NotificationCenter.default.addObserver(self, selector: #selector(VideoPlayerViewController.playerPlaybackStalled), name: NSNotification.Name.AVPlayerItemPlaybackStalled, object: player?.currentItem)
NotificationCenter.default.addObserver(self, selector: #selector(VideoPlayerViewController.playerSessionRuntimeError), name: NSNotification.Name.AVCaptureSessionRuntimeError, object: player?.currentItem)
self.player?.play()
}
override func viewDidLoad() {
super.viewDidLoad()
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeMoviePlayback, options: [])
try session.setActive(true)
} catch {
print("couldn't switch audio session category")
}
setupVideoPlayback()
}