文章目录
1.问题
Main thread blocked by synchronous property query on not-yet-loaded property (PreferredTransform) for HTTP(S) asset. This could have been a problem if this asset were being read from a slow network.
Asset is not playable
@objc func buttonClicked() {
guard let localVideoURL = Bundle.main.url(forResource: "sample1", withExtension: "mp4") else {
MyPrint("Invalid URL")
return
}
// 创建AVPlayer
player = AVPlayer(url: localVideoURL)
// 创建AVPlayerViewController并设置player
playerViewController = AVPlayerViewController()
playerViewController.player = player
present(playerViewController, animated: true) {
[self] in
player.play()
}
}
2.原因:iOS swift AVPlayerViewController无法播放HEVC (H.265) 格式的视频
3.解决方法用第三方框架MobileVLCKit来播放
pod 'MobileVLCKit'
pod install
import UIKit
import MobileVLCKit
class PlayerViewController: UIViewController {
var mediaPlayer: VLCMediaPlayer?
override func viewDidLoad() {
super.viewDidLoad()
// 设置媒体播放器
mediaPlayer = VLCMediaPlayer()
guard let mediaPlayer = mediaPlayer else {
return }
// 设置视频URL
let url = URL(string: "https://path/to/your/video.mp4")
mediaPlayer.media = VLCMedia(url: url!)
// 设置媒体播放器的显示区域
mediaPlayer.drawable = self.view
// 开始播放
mediaPlayer.play()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// 停止播放
mediaPlayer?.stop()
}
}
4.用MobileVLCKit写的播放器
4.1 两个oc版本的
iosMobileVLCKitDemo - gitee
WeLSee - github
4.2 两个swiftUI版本的
swiftui-vlc-video-player - github video MP4视频播放数据
VLCKitPlayer - github
文章评论