How to play url video using AVPlayerViewController

1k Views Asked by At

While hitting my video url, the response which i am getting is :

Error Domain = AVFoundationErrorDomain 
Code = -11853 "Playlist not received, See -[AVPlayerItem errorLog] for 2 events"
UserInfo = {
    NSUnderlyingError = 0x600000251670 
        {
        Error Domain = CoreMediaErrorDomain 
        Code=-12884 "Playlist File not received" 
        UserInfo = {NSDescription = Playlist File not received}
        }, 
    NSLocalizedFailureReason = This data is damaged, incomplete, or incompatible.,
    NSDebugDescription = Playlist not received, 
    See -[AVPlayerItem errorLog] for 2 events, 
    NSLocalizedDescription = Cannot Parse
}

I am stuck on this past two days and couldn't figure out a way out.

1

There are 1 best solutions below

0
On

Use the following code to play URL video.This will work for you.

The "message?.link" if the video URL. handlePlay() function call on the click button for playing video.

var playerLayer: AVPlayerLayer?
var player: AVPlayer?

func handlePlay() {
    if let videoUrlString = message?.link {                      
        let videoURL = URL(string: videoUrlString)
        self.player = AVPlayer(url: videoURL!)
        let playerViewController = AVPlayerViewController()
        playerViewController.player = ChatMessageCell.player
        nav.present(playerViewController, animated: true, completion: {
            self.player?.play()
        })         

    }

Thanks!!