视频不会内联加载 [英] video will not load inline

查看:35
本文介绍了视频不会内联加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的视频在视图中流式传输而不是接管屏幕,我指定了每一种方式,在故事板中切换选项,但仍然没有.任何想法或想法,也许我遗漏了什么,请随时测试您自己的代码并查看结果(填满整个屏幕,但仍然无法内联播放.)

 覆盖 func viewDidLoad() {super.viewDidLoad()//在加载视图后做任何额外的设置,通常是从笔尖.让 webConfiguration = WKWebViewConfiguration()webConfiguration.allowsInlineMediaPlayback = truewebConfiguration.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") {让请求:URLRequest = URLRequest(url: videoURL)LiveStream.load(请求)}

编辑了 24/7 正常运行时间的链接(

正如您所注意到的,视频在 WKWebView 中不是全屏播放.

注意:

您的 URL 对我不起作用,所以我使用了另一个 URL 进行演示.

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)

解决方案

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:

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.

这篇关于视频不会内联加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆