我正在AppleTV上播放一个简单的幻灯片。我能够很好地流式传输视频文件并且效果很好,但是当我在本地移动文件(捆绑)时,它无法在实际的AppleTV上播放。但是,它在模拟器上运行良好。
Swift 4.1 Xcode 9.3 带有tvOS 11.3的AppleTV第4代
这是我的代码:
guard let fileURL = Bundle.main.path(forResource: "showroom", ofType:"m4v") else {
debugPrint("video not found")
return
}
playerAsset = AVAsset (url: URL(fileURLWithPath: fileURL))
playerItem = AVPlayerItem(asset: playerAsset!) //(url: fileURL as URL)
queuePlayer = AVQueuePlayer(items: [playerItem!])
playerLooper = AVPlayerLooper(player: queuePlayer!, templateItem: playerItem!)
// Create a new AVPlayerViewController and pass it a reference to the player.
let controller = AVPlayerViewController()
controller.player = queuePlayer
// Modally present the player and call the player's play() method when complete.
present(controller, animated: true) {
queuePlayer!.play()
}
当我在设备上运行时,我收到以下控制台消息,而AppleTV上只有一个带有微调器的空白屏幕:
2018-04-03 09:13:00.225001-0500 ShowRoom[231:10709] [UIDevice.battery] No internal battery found
2018-04-03 09:13:00.404092-0500 ShowRoom[231:10709] [AXM-MediaDesc] Did observe change on. path:'currentItem' object:<AVQueuePlayer: 0x1c0027420> change:{
kind = 1;
new = "<AVPlayerItem: 0x1c40049f0, asset = <AVURLAsset: 0x1c4420c20, URL = file:///var/containers/Bundle/Application/D6FD828D-2109-4946-BCAE-4080A0114912/ShowRoom.app/showroom.m4v>>";
2018-04-03 09:13:00.469734-0500 ShowRoom[231:10709] [AXM-MediaDesc] Did observe change on. path:'currentItem' object:<AVQueuePlayer: 0x1c0027420> change:{
kind = 1;
notificationIsPrior = 1;
old = "<AVPlayerItem: 0x1c40049f0, asset = <AVURLAsset: 0x1c4420c20, URL = file:///var/containers/Bundle/Application/D6FD828D-2109-4946-BCAE-4080A0114912/ShowRoom.app/showroom.m4v>>";
2018-04-03 09:13:00.470929-0500 ShowRoom[231:10709] [AXM-MediaDesc] Did observe change on. path:'currentItem' object:<AVQueuePlayer: 0x1c0027420> change:{
kind = 1;
new = "<AVPlayerItem: 0x1c40053c0, asset = <AVURLAsset: 0x1c4420c20, URL = file:///var/containers/Bundle/Application/D6FD828D-2109-4946-BCAE-4080A0114912/ShowRoom.app/showroom.m4v>>";
old = "<AVPlayerItem: 0x1c40049f0, asset = <AVURLAsset: 0x1c4420c20, URL = file:///var/containers/Bundle/Application/D6FD828D-2109-4946-BCAE-4080A0114912/ShowRoom.app/showroom.m4v>>";
2018-04-03 09:13:00.543119-0500 ShowRoom[231:10709] [AXM-MediaDesc] Will stop processing legibility events for player item: (null)
关于我在这里缺少什么的想法?我也尝试了一个具有相同结果的.MOV文件。谢谢!