I have an ipfs encrypted video URL.
I am not able to play video in avplayer but URL plays well in webview.
here is URL: https://ipfs.moralis.io:2053/ipfs/QmUjWnQZVVNmTSVak2QDhTxMkn3dPQozxawa1sm3jE5bLr
let currentURL = URL(string: "https://ipfs.moralis.io:2053/ipfs/QmUjWnQZVVNmTSVak2QDhTxMkn3dPQozxawa1sm3jE5bLr")!
let playerItem = AVPlayerItem(url: currentURL)
playerItem.addObserver(self, forKeyPath: "status", options: NSKeyValueObservingOptions(), context: nil)
player = AVPlayer(playerItem: playerItem)let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.avplayerUIView.bounds
self.avplayerUIView.layer.addSublayer(playerLayer)
player.play()
Also, I have used AVUrlAssets with video extension and video codecs but still, video is not playing
let mimeType = "video/mp4; codecs="avc1.42E01E, mp4a.40.2""
let asset: AVURLAsset = AVURLAsset(url: videoURL!, options: ["AVURLAssetOutOfBandMIMETypeKey" : mimeType])
2
Answers
Strange. It seems
AVPlayerLayer
can not resolve video. If you removeplayerLayer
, you will hear audio is playing fine.My solution is using
AVPlayerViewController
.It’s a good practice to handle errors from your code to get info about the problem so lets make next error handler:
If you run your code it produces next error:
"The server is not correctly configured." is often related to the HTTP range requests issue on a server side because supporting downloading by ranges is required to play media from the Internet.
Lets check this with
curl
:As you can see from the response the server supports ranges – "accept-ranges: bytes".
Lets check the partial request:
The server responds with
HTTP/2 200
and the full content length but the response must be like this:So that your server doesn’t support HTTP ranges requests and AVPlayer can’t play your mp4 video.
You can resolve the issue with two ways: