Swift YouTube video in Full Screen & Auto Play with SFSafariViewController

211 Views Asked by At

Problem:

I would like SFSafariViewController to autoplay a YouTube video in full screen.

Code:


import SafariServices

@objc func handleYTTap(_ sender: UIGestureRecognizer) {
        
        let youtubeVideoURL = "https://youtu.be/d9MyW72ELq0"
        
        let bookmark = NSURL(string: youtubeVideoURL)
        let safari = SFSafariViewController(url: bookmark as! URL)

        if(UIDevice.current.userInterfaceIdiom == .pad) {
            safari.modalPresentationStyle = .fullScreen
        }else{
            safari.modalPresentationStyle = .fullScreen
        }

        self.present(safari, animated: true, completion: nil)
        
    }

Tried Solutions:

I have tried to implement

"?playsinline=1?autoplay=1".

to the url but still cant get the SFSafariViewController to autoplay in full screen. is this even possible to do without creating a custom view or using a library of some sort?

0

There are 0 best solutions below