user10628073
user10628073

Reputation:

video will not load inline

I want my video to stream in the view not takeover the screen, ive specified that every way, toggled the option in storyboards and still nothing. any thoughts or ideas, maybe something im missing, please feel free to test the code your self and see the result (fills the entire screen, and still unable to play inline.)

    override func viewDidLoad() {

    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let webConfiguration = WKWebViewConfiguration()
    webConfiguration.allowsInlineMediaPlayback = true
    webConfiguration.mediaTypesRequiringUserActionForPlayback = []

    LiveStream = WKWebView(frame: CGRect(x: 0, y: 0, width: 375, height: 300), configuration: webConfiguration)
    self.view.addSubview(LiveStream)

    if let videoURL:URL = URL(string: "https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8?playsinline=1") {
        let request:URLRequest = URLRequest(url: videoURL)
        LiveStream.load(request)
    }

Edited the link to a 24/7 uptime (https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8?playsinline=1)

Upvotes: 0

Views: 331

Answers (1)

Dharmesh Kheni
Dharmesh Kheni

Reputation: 71854

I am seeing some mistakes here.

First of all you have already added WKWebView in your storyboard and I am guessing that from your

@IBOutlet var LiveStream: WKWebView! 

and you are also adding it into your view again with

self.view.addSubview(LiveStream)

Which is not correct way to add it.

You can use UIView for that.

For that add a UIView in your storyboard and create IBOutlet for that

@IBOutlet weak var viewForEmbeddingWebView: UIView!

then declare an instance var LiveStream: WKWebView!

Now you can configure LiveStream as shown below:

let webConfiguration = WKWebViewConfiguration()
webConfiguration.allowsInlineMediaPlayback = true
webConfiguration.mediaTypesRequiringUserActionForPlayback = []

LiveStream = WKWebView(frame: viewForEmbeddingWebView.frame, configuration: webConfiguration)
self.viewForEmbeddingWebView.addSubview(LiveStream)

if let videoURL:URL = URL(string: "https://www.youtube.com/embed/9n1e1N0Sa9k?playsinline=1") {
    let request:URLRequest = URLRequest(url: videoURL)
    LiveStream.load(request)
}

And your result will be:

enter image description here

As you have noticed video is playing inside the WKWebView not in full screen.

Note:

Your URL wasn't working for me so I have used another URL for demonstrate.

Upvotes: 1

Related Questions