0

I am trying to play the video from the web url it showing buffering loader only but not getting played I have used the following code.

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    let url = URL(string: "https://sandbox-api.digiboxx.com/uploads/E2D6024483AB4B04/1602945683_sample_640x360.mp4")!

    playVideo(url: url)
}

func playVideo(url: URL) {
    let player = AVPlayer(url: url)

    let vc = AVPlayerViewController()
    vc.player = player

    self.present(vc, animated: true) { vc.player?.play() }
}

enter image description here

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
A J
  • 441
  • 4
  • 20
  • 1) https://theme.co/forum/t/html5-video-doesnt-work-on-safari-but-works-on-chrome/9684/5 2) https://stackoverflow.com/a/36299252/2522457 Check this links. Hope it will works – Er.Shreyansh Shah Oct 19 '20 at 15:54
  • Hi ! I think the problem comes from your URL source. Safari is not able to play the video neither. You should try with an other URL: "http://techslides.com/demos/sample-videos/small.mp4". – Pierre Perrin Oct 19 '20 at 16:43
  • https://stackoverflow.com/a/21121914/1974224 - your video is a H.264 one, maybe this will help – Cristik Oct 19 '20 at 18:45

2 Answers2

0

I tried your URL just in the browser (Safari) on my computer and nothing plays. So I think something is wrong with the URL or the file at the other end.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Weird, it plays for me – aheze Oct 19 '20 at 15:53
  • 1
    OK but an AVPlayer isn't the Chrome browser; it uses the same mechanisms as Safari. So I stand by my answer. There is something wrong with this file. Done. You asked why it doesn't play, I'm telling why I think that is. – matt Oct 19 '20 at 16:12
0

I tested your link and the video is loading, so I don't know why your code isn't working ...

This is how I use VideoPlayer in Swift :

import UIKit
import AVKit

class MediaManager: UIViewController {

    var player = AVPlayer()

    override func viewDidLoad() {
        super.viewDidLoad()
        play(url: "yourUrl")
    }

    func play (url: String) {
    
        player = AVPlayer(url: URL(string: url)!)
    
        let playerViewController = AVPlayerViewController()
        playerViewController.player = player
    
        self.view.present(playerViewController, animated: false) { self.player.play() }
    }
}

Try with my code and tell me if it's okay for you

swifthing
  • 440
  • 4
  • 11