ios AVPlayerViewController 无法播放本地mp4
<p><p>我尝试使用 <code>AVPlayerViewController</code> 播放 mp4 视频。我用“http url”,它可以播放,但是当我使用<code>fileUrl</code>时,它就不起作用了……</p>
<pre><code> NSString *filePath = [ pathForResource:@"mp4ForDownloadTest" ofType:@"mp4"];
if ([ fileExistsAtPath:filePath]) {
NSURL *url = ;
AVPlayerViewController *playerVC = [ init];
AVAsset *movieAsset = ;
AVPlayerItem *playerItem = ;
AVPlayer *player = ;
playerVC.player = player;
[self presentViewController:playerVC animated:YES completion:^{
;
}];
}
</code></pre>
<p> <a href="/image/ysN2s.png" rel="noreferrer noopener nofollow"><img src="/image/ysN2s.png" alt="enter image description here"/></a> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>试试这个:</p>
<pre><code> guard let path = NSBundle.mainBundle().pathForResource("drum", ofType:"mp4") else {
break
}
let url = NSURL(fileURLWithPath: path)
self.loadPlayer(url)
</code></pre>
<p>然后:</p>
<pre><code>private func loadPlayer(url: NSURL) {
// present video window
let playerItem = AVPlayerItem(URL: url)
let player = AVPlayer.init(playerItem: playerItem)
self.playerViewController.player = player
self.view.addSubview(self.playerViewController.view)
self.videoControlView.alpha = 1.0
self.setupPlayerObserver()
self.playPlayer()
self.setSlider()
}
</code></pre></p>
<p style="font-size: 20px;">关于ios AVPlayerViewController 无法播放本地mp4,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/36302220/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/36302220/
</a>
</p>
页:
[1]