Search code examples
iosswiftavfoundationalamofireavplayer

Playing Video (.MP4) from server that's behind Digest authentication in iOS Swift


I'm a beginner in swift my problem is this:

-I need to play a .MP4 video in my ios swift app - the server needs authentication

let myVideoUrl = "playmyvidmp4123.org" [as an example]

when I put myVideoUrl in a web browser a pop up appears and asks you to put in your username and password (authentication) so I put in my credentials:

User: "sherry" pass: "789"

then the video starts downloading

How do I play these links in my app? I use alamofire for networking, so I use .Authenticate however how do I pass the data to AVPlayer/ somme player to play the video and allow for scrubbing as well

There was a technique I did before, whereby when I get the data, I convert DATA to UIImage and then display the UIImage in my image view and constantly refresh the img by timers and it plays (there is no scrubbing functionality in it either)

I do not know how to authenticate the server with the stock inbuilt method either i.e. without using alamofire. So please if someone knows, how may I accomplish this task - A code snippet would be much appreciated in which I can plug my creds, & link and test it out


Solution

  • Try to format your URL to video this way https://user:pass@url => https://sherry:[email protected]