我将如何使用Swift& amp; AppleTV4显示XcodeProj内部的视频?我可以使用AVPlayer以后再播放Mp3吗?
这就是我所拥有的:
import UIKit
import AVFoundation
import AVKit
import MediaPlayer
class ViewController: UIViewController {
let videoplayer = AVPlayer(URL: NSURL(string: "file.mp4")!)
let audioplayer = AVPlayer(URL: NSURL(string: "file.mp3")!)
@IBOutlet weak var Buttonizer: UIButton!
@IBAction func ButtonPressed(sender: AnyObject) {
videoplayer.play()
audioplayer.play()
// let videoplayer = AVPlayer(URL: NSURL(string: "https://clips.vorwaerts-gmbh.de/VfE_html5.mp4")!)
}
and the rest.. (viewDidLoad stuff)
我尝试使用外部mp4运行AVPlayer,但videoplayer.play()只是使用breakcode崩溃。
答案 0 :(得分:2)
尝试此操作在AVPlayer中播放视频:
let path = NSBundle.mainBundle().pathForResource("test", ofType:"mp4")!
let videoURL = NSURL(fileURLWithPath: path)
let player = AVPlayer(URL: videoURL)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.view.bounds
self.view.layer.addSublayer(playerLayer)
player.play()