我有一个自定义视图,其中嵌入了表视图单元格中的AVPlayer。 AVPlayer加载.m3u8链接。但事实是,它在模拟器中工作,但不在物理设备上。关于修复的任何想法?提前谢谢。
class CameraView: UIView {
var player: AVPlayer? {
get {
return playerLayer.player
}
set {
playerLayer.player = newValue
}
}
var playerLayer: AVPlayerLayer {
return layer as! AVPlayerLayer
}
override static var layerClass: AnyClass {
return AVPlayerLayer.self
}
private func presentNewStream() {
let asset = AVAsset(url: URL(string: self.pathToStream)!)
let keys: [String] = ["playable"]
asset.loadValuesAsynchronously(forKeys: keys, completionHandler: {
var error: NSError? = nil
let status = asset.statusOfValue(forKey: "playable", error: &error)
switch status {
case .loaded:
DispatchQueue.main.async {
let item = AVPlayerItem(asset: asset)
self.player = AVPlayer(playerItem: item)
let playerLayer = AVPlayerLayer(player: self.player)
playerLayer.videoGravity = AVLayerVideoGravity.resize
playerLayer.frame = self.bounds
self.layer.addSublayer(playerLayer)
self.player?.isMuted = true
}
break
case .failed:
DispatchQueue.main.async {
print("failde asset")
//do something, show alert, put a placeholder image etc.
}
break
case .cancelled:
DispatchQueue.main.async {
print("cancelled asset")
//do something, show alert, put a placeholder image etc.
}
break
default:
break
}
})
}
编辑: 在物理设备上进行测试时,我得到了:
2018-04-12 16:30:50.653392+0300 App_Name[3543:1572246] CredStore - performQuery - Error copying matching creds. Error=-25300, query={
class = inet;
"m_Limit" = "m_LimitAll";
"r_Attributes" = 1;
sync = syna;
}
答案 0 :(得分:0)
出现此问题是因为您在本地保存文件的方式正在尝试播放。在您的设备中,您的播放器可能无法访问您的媒体文件。请检查您的网址
此外,尝试使用http url播放服务器上可用的任何媒体文件,看看它是否正常工作。
另外,请确保在服务器的情况下从https提供HLS流。如果您的流网址以http开头,请从您的info.plist文件中允许任意加载。否则它将不会播放任何http流。
{
"_id" : ObjectId("5ad0870d2602ff20497b71b8"),
"Hotel" : {}
}