我正在尝试在JSQMessagesViewController的子类中播放视频,但是它没有开始播放onClick事件。 我正在从firebase下载视频,然后通过附加唯一引用 -LK7WSGtGAQ2anpDxkCQ 在设备上写入数据。请参阅下面的打印说明,以获取完整路径。
//response to collection view tap events
//called every time we type on a message
override func collectionView(_ collectionView: JSQMessagesCollectionView!, didTapMessageBubbleAt indexPath: IndexPath!) {
let message = messages[indexPath.item]
print("message type is \(message.type) and message media uid is \(message.mediaMessage?.mediaUID)")
if message.type == MessageType.image {
let jsqMessage = jsqMessages[indexPath.item]
let mediaItem = jsqMessage.media as! JSQPhotoMediaItem
let photos = IDMPhoto.photos(withImages: [mediaItem.image])
let browser = IDMPhotoBrowser(photos: photos)
self.present(browser!, animated: true, completion: nil)
}
if message.type == MessageType.video {
let jsqMessage = jsqMessages[indexPath.item]
if jsqMessage.isMediaMessage {
if let mediaItem = jsqMessage.media as? JSQVideoMediaItem {
print("mediaItem.fileURL is \(mediaItem.fileURL)")
let player = AVPlayer(url: mediaItem.fileURL)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true) {
playerViewController.player!.play()
}
}
}
}
}
}//end of extension
mediaItem.fileURL是 可选(file:/// Users / bogdanbarbulescu / Library / Developer / CoreSimulator / Devices / 7FB42206-997D-4AC2-B0BD-CEE2E22DAFBE / data / Containers / Data / Application / 8F17DF31-16B1-4B27-ACB2-015AA55D8979 / Documents /- LK7WSGtGAQ2anpDxkCQ)
更新
将.MOV附加到上面的url后,现在可以播放视频了,但是播放时没有声音。该如何解决?
答案 0 :(得分:0)
问题是当我将数据保存到磁盘上时,我没有将.MOV
扩展名附加到路径的末尾,因此AVPlayer无法播放视频。
之前: mediaItem.fileURL是file:/// Users / bogdanbarbulescu / Library / Developer / CoreSimulator / Devices / 7FB42206-997D-4AC2-B0BD-CEE2E22DAFBE / data / Containers / Data / Application / 8F17DF31-16B1-4B27-ACB2-015AA55D8979 / Documents / -LK7WSGtGAQ2anpDxkCQ
之后:文件:/// Users / bogdanbarbulescu / Library / Developer / CoreSimulator / Devices / 7FB42206-997D-4AC2-B0BD-CEE2E22DAFBE / data / Containers / Data / Application / 8F17DF31-16B1-4B27-ACB2-015AA55D8979 /文档/-LK7WSGtGAQ2anpDxkCQ.MOV