i'm trying to play video from url using AVPlayer
.
but video is not playing.
because video url is "unsecure"(Not Secure).
but i've already allow NSAppTransportSecurity
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
here viewController Code
import AVKit
import AVFoundation
let playerViewController = AVPlayerViewController()
let url = Constants.API.imageURL + (GlobalVariables.sharedManager.userDetailObj.UserDetail?.intro_video_path)! //which is "http://23.97.79.216:8000/api/media/intro-video/video_file_2rg3tio.mp4"
//let videoURL = URL(string: "http://jplayer.org/video/m4v/Finding_Nemo_Teaser.m4v") //testing unsecure(Not Secure) url which is working.
let videoURL = URL(string: url)
let player = AVPlayer(url: videoURL!)
playerViewController.player = player
self.present(playerViewController, animated: true) {
self.playerViewController.player!.play()
}
as i mention in code that "http://jplayer.org/video/m4v/Finding_Nemo_Teaser.m4v" is unsecure(Not Secure) but its working fine.
but my url "http://23.97.79.216:8000/api/media/intro-video/video_file_2rg3tio.mp4" is not working.
there is any way that we can play video of unsecure(Not Secure) url?
It looks like your problem is that the link that's not working can not be upgraded to https.
Why:
iOS doesn't allow http url requests for security reasons. (https://developer.apple.com/documentation/security/preventing_insecure_network_connections)
This means that if you try to access a resource that uses http instead of https iOS will try to upgrade it automatically to https. If you go to the second link in your browser, and add the https transport protocol the link will still work. That server can handle SSL connections (which are secure). However, your first link can not upgrade to https and will always fail.
Solution
If this server (the first, broken, link) is one you own, add SSL security. That's the easy fix. If you don't have access to it, you'll need to download the video and host it somewhere with SSL security.
Workarounds
Sadly there aren't any workarounds for this besides hosting it yourself. Apple simply does not allow http requests as they can open an attack on the user's device using a man-in-the middle attack.