Embedded YouTube videos in Html/WebView in NativeScript iOS

人走茶凉 提交于 2019-12-08 13:32:47

问题


I am trying to implement embedded YouTube videos in Html/WebView in Nativescript iOS. I was able to get it done on android, as I don't have enough native iOS experience I am posting the question here. I found some links but they deal with native iOS in ObjC and Swift.

How to embed YouTube video on iOs and play it directly on UIWebview without full screen

Can someone guide me to get this done?

Update: Here is the screenshot of Android and iOS that I am getting by using in src of WebView (Android) and html of HtmlView (iOS) -

Android

iOS


回答1:


To do that you could use NativScript WebView and bind its src property. For example:

main-page.xml

<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded">     
    <GridLayout>
        <WebView src="{{ htmlString }}" height="250" />
    </GridLayout>

</Page>

main-page.js

var observable = require("data/observable");

// Our new Observable view model for data binding
var viewmodel = new observable.Observable({});

// Page loaded      
function pageLoaded(args) {
    var page = args.object;

    viewmodel.set("htmlString", '<iframe width="560" height="315" src="https://www.youtube.com/embed/t1x8DMfbYN4" frameborder="0" allowfullscreen></iframe>');

    page.bindingContext = viewmodel;
}
exports.pageLoaded = pageLoaded; 

You could also review this article.



来源:https://stackoverflow.com/questions/42773444/embedded-youtube-videos-in-html-webview-in-nativescript-ios

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!