如何在 Windows8 html/javascript 应用程序中播放 YouTube 视频? [英] How to play YouTube videos in a Windows8 html/javascript app?

查看:25
本文介绍了如何在 Windows8 html/javascript 应用程序中播放 YouTube 视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Windows 8 html/javascript 应用程序中播放 YouTube 视频?我有剪辑的 ID,我只想播放它.也许通过html5的视频标签?

我已经尝试了 iframe api,但未能使其正常工作.我也尝试了 javascript api,但它无法从花药位置加载 javascript.

任何有关该主题的帮助将不胜感激!

解决方案

我为 Windows Phone 开发了一个 YouTube 类,它可以获取 YouTube 电影的 MP4 链接.也许您可以使用此代码并使用 MP4 链接启动视频应用程序或设置媒体元素的来源(如果存在于 Win8 中)?

如果有办法使用预定义的 MP4-URL 启动视频应用程序,我可以为 Windows 8 重写代码.

http://mytoolkit.codeplex.com/wikipage?title=YouTube

更新:我已经更新了代码.现在只需使用此异步方法加载 URL:

var url = await YouTube.GetVideoUriAsync("youtube_id");myMediaElement.Source = url.Uri;

myMediaElement 是一个 XAML MediaElement 控件.

从项目的 Subversion 存储库中查看整个库:http://mytoolkit.codeplex.com

更新:抱歉,它只是 C#,您必须将其移植到 Javascript...

How can I play YouTube videos in a Windows 8 html/javascript app? I have the clip's id and I just want to play it. Perhaps via html5's video tag?

I've tried the iframe api, but failed to get it to work. I've also made a try on the javascript api, but it failed to load javascript from anther location.

Any help on the subject would be very appreciated!

解决方案

I developed a YouTube class for Windows Phone which gets the MP4 link of a YouTube movie. Maybe you can use this code and start the video app with the MP4 link or set the source of a media element (if existent in Win8)?

If there's a way to start the video app with a predefined MP4-URL I can rewrite the code for Windows 8.

http://mytoolkit.codeplex.com/wikipage?title=YouTube

UPDATE: I've updated the code. Now simply load the URL with this async method:

var url = await YouTube.GetVideoUriAsync("youtube_id");
myMediaElement.Source = url.Uri;

myMediaElement is a XAML MediaElement control.

Check out the whole library from the project's Subversion repository: http://mytoolkit.codeplex.com

Update: Sorry it's C# only, you have to port it to Javascript...

这篇关于如何在 Windows8 html/javascript 应用程序中播放 YouTube 视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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