ios - .avi 文件视频无法在 MPMoviePlayerController ios 播放器中播放
<p><p>我正在使用 <code>MPMoviePlayerController</code> 播放 <em>avi</em> 格式的视频文件。
音频有效,但视频无效。这是为什么呢?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p><code>MPMoviePlayerViewController</code> 仅支持 <em>.mov、.mp4、.mpv 和 .3gp</em>,并且已<strong>弃用</strong>。</p>
<p>来自 Apple 的 <a href="https://developer.apple.com/documentation/mediaplayer/mpmovieplayerviewcontroller" rel="noreferrer noopener nofollow">documentation</a> :</p>
<blockquote>
<p>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.</p>
</blockquote>
<p>你应该使用 <strong>AVPlayerViewController</strong>:</p>
<pre><code>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()
}
</code></pre>
<p>或者只是将 <strong>AVPlayer</strong> 添加为 subview :</p>
<pre><code>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()
</code></pre>
<p><strong>它支持以下音频/视频格式:</strong>
.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</p></p>
<p style="font-size: 20px;">关于ios - .avi 文件视频无法在 MPMoviePlayerController ios 播放器中播放,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/47428121/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/47428121/
</a>
</p>
页:
[1]