我正在使用 MPMoviePlayerController
播放 avi 格式的视频文件。
音频有效,但视频无效。这是为什么呢?
MPMoviePlayerViewController
仅支持 .mov、.mp4、.mpv 和 .3gp,并且已弃用。
来自 Apple 的 documentation :
The MPMoviePlayerViewController class is formally deprecated in iOS 9. (The MPMoviePlayerController class is also formally deprecated.) To play video content in iOS 9 and later, instead use the AVPictureInPictureController or AVPlayerViewController class from the AVKit framework, or the WKWebView class from WebKit.
你应该使用 AVPlayerViewController:
import AVFoundation
import AVKit
let videoPath = "https://video.avi"
let videoURL = URL(string: videoPath)
let player = AVPlayer(url: videoURL!)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
present(playerViewController, animated: true) {
playerViewController.player?.play()
}
或者只是将 AVPlayer 添加为 subview :
let videoURL = URL(string: videoPath)
let player = AVPlayer(url: videoURL!)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.view.bounds
view.layer.addSublayer(playerLayer)
player.play()
它支持以下音频/视频格式: .mpeg、.mpeg-2-video、.avi、.aifc-audio、.aac-audio、.mpeg-4、.au-audio、.aiff-audio、.mp2、.3gpp2、.ac3-audio、. mp3、.mpeg-2-transport-stream、.3gpp、.mpeg-4-audio
关于ios - .avi 文件视频无法在 MPMoviePlayerController ios 播放器中播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47428121/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |