Playing youtube video in windows 8 app

2019-07-16 03:33发布

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

2条回答
放荡不羁爱自由
2楼-- · 2019-07-16 03:59

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);
查看更多
爷、活的狠高调
3楼-- · 2019-07-16 04:11

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);
查看更多
登录 后发表回答