gpt4 book ai didi

ios - 仅使用 iFrame 在 UIWebView 中播放 youtube 视频

转载 作者:可可西里 更新时间:2023-11-01 04:44:19 25 4
gpt4 key购买 nike

我正在尝试在我的 UIWebView 上播放 youtube 视频使用 <iframe>使用以下代码标记 -

NSString *html = @"\
<html><head>\
<style type=\"text/css\">\
body { background-color: transparent;\
color: white; \
}\
</style>\
</head><body style=\"margin:0\">\
<iframe class=\"youtube-player\" width=\"300\" height=\"300\" src=\"http://www.youtube.com/embed/efRNKkmWdc0\" frameborder=\"0\" allowfullscreen=\"true\"></iframe>\
</body></html>";

UIWebView *videoView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 460.0)];
[videoView loadHTMLString:html baseURL:nil];

它工作正常。

enter image description here

但是,我需要在 webview 本身上播放这个而不是使用 iPhone 默认播放器。我如何限制它在 UIWebView 上播放只要。我被定义为 iframe播放器类为 class=\"youtube-player\"还。但是,它采用了 iPhone 的默认播放器。

任何想法表示赞赏!

最佳答案

尝试使用此代码初始化 iframe 播放器:

        player = new YT.Player('player', {
height: '100%',
width: '100%',
videoId: 'M7lc1UVf-VE',
playerVars: {
'controls' : '0',
'playsinline' : 1
}
});

请注意“playsinline”参数设置为 1。在包含 View 中,使用此参数初始化 UIWebView:

webView.allowsInlineMediaPlayback = YES;

我注意到的一件事是您不能将 baseURL 参数设置为 NULL;它必须是一个 NSString。下面是一个加载名为 iframe-player.html 的 HTML 文件的示例,其中包含所需的 HTML 和 JavaScript 代码:

NSString *path = [[NSBundle mainBundle] pathForResource: @"iframe-player" ofType: @"html"];
NSString *embedHTML = [NSString stringWithContentsOfFile: path
encoding:NSUTF8StringEncoding
error: &error];

[webView loadHTMLString:embedHTML baseURL:[NSURL URLWithString:@"about:blank"]];

关于ios - 仅使用 iFrame 在 UIWebView 中播放 youtube 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16167134/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com