Playing youtube video in windows 8 app

和自甴很熟 提交于 2019-12-11 01:26:08

问题


I have been trying to play a youtube video in a windows 8 html5 & javascript app with no luck!

I tried copy pasting the code youtube provided for embedding videos in the body of default.html, for example:

<iframe width="420" height="315" src="http://www.youtube.com/embed/k07IaB9yq_U" frameborder="0" allowfullscreen></iframe>

This gives the following error:

The Adobe Flash player or an HTML5 supported browser is required for video playback. Get the latest flash player Learn more about updating an HTML5 browser.

when I try using the video tag with the previous link, for example:

<video src="http://www.youtube.com/embed/k07IaB9yq_U" controls></video>

It says an invalid source!

What is the right way to do this?

Thanks


回答1:


YouTube has a beta program to provide some videos in HTML5. You can join it here . Once you have done that you should be able to embed HTML5 YouTube videos in a WebView control by navigating to the YouTube URL.

Flash videos cannot be displayed in a Metro style app.

Code for the webview control

string htmlFragment =
@"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
            <html>
               <head>
                  <title>YouTubePagesample</title>
               </head>
               <iframe width='560' height='315' src='http://www.youtube.com/embed/{YoutubeID}' frameborder='0' allowfullscreen></iframe>
               <body>
               </body>
            </html>;";
        this.webView.NavigateToString(htmlFragment);



回答2:


Use the setInnerHTMLUnsafe method as win 8 apps don't like the external JS being injected in the app. videoPlayer is the div which you want to add the embed to.

 var content = '<iframe width="480" height="270" src="http://www.youtube.com/embed/8sPj0Ic8KQ8?rel=0" frameborder="0" allowfullscreen></iframe>' ;
 WinJS.Utilities.setInnerHTMLUnsafe(videoPlayer, content);


来源:https://stackoverflow.com/questions/13507557/playing-youtube-video-in-windows-8-app

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