1

I am using AVPlayer to load video url from a server. It is working for a video in the root but not in the sub-domain.

My AVPlayer code is as follows: Player works with the below URL:

@IBAction func btnPlayClicked(_ sender: Any) {
    //let videoURL = URL.init(string: "http://musically.virgoexchange.com/storage/upload/videos/2018/10/1538719219video.mp4")
    let videoURL = URL(string: "http://somo.virgoexchange.com/demo.mp4")
    self.playVideo(videoURL: videoURL!)
}

Player not working with following url:

@IBAction func btnPlayFinalClicked(_ sender: Any) {
    let videoURL = URL(string: "http://somo.virgoexchange.com/user/gallery/video/1535522305_img_0006.mp4")
    self.playVideo(videoURL: videoURL!)
}

func playVideo(videoURL:URL) {
    let player = AVPlayer(url: videoURL)
    let playerViewController = AVPlayerViewController()
    playerViewController.player = player
    self.present(playerViewController, animated: true) {
        playerViewController.player!.play()
    }
}

I am not able to identify, whether this issue is from server side or iOS side. As this URL is also not loading on safari web browser too.

Any help will be appreciated.

Thanks, Puja Rathod

Denis
  • 492
  • 2
  • 15
puja
  • 209
  • 1
  • 15

2 Answers2

0

I think there is a problem on your server with the second URL. I went through Safari's web content documentation and followed the steps for both your URLs.

The first one worked as expected (it downloaded 100KB)

curl --range 0-99 http://somo.virgoexchange.com/demo.mp4 -o /dev/null
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   100  100   100    0     0      8      0  0:00:12  0:00:11  0:00:01    23

The second one did not work:

curl --range 0-99 http://somo.virgoexchange.com/user/gallery/video/1535522305_img_0006.mp4 -o /dev/null
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0  778k    0   100    0     0    198      0  1:07:06 --:--:--  1:07:06   198
curl: (18) transfer closed with 797201 bytes remaining to read

Hope this is why Safari fails to load the second URL and so does AVPlayer. Hope this helps.

Satheesh
  • 10,998
  • 6
  • 50
  • 93
0

For me your code seems to work as expected.

enter image description here

The only thing I had to change in the project was to Allow Arbitrary Loads

As I checked the logs and got an error message indicating this.

Durdu
  • 4,649
  • 2
  • 27
  • 47