react & youtube

https://www.npmjs.com/package/react-youtube

https://developers.google.com/youtube/iframe_api_reference

通过 IFrame Player API,您可以在自己的网站上嵌入 YouTube 视频播放器并使用 JavaScript 控制播放器。

与 Flash 和 JavaScript Player API 不同的是,这两者都要求在您的网页上嵌入一个 Flash 对象,而 IFrame API 会将内容发布到网页上的<iframe>标记中。

这种方法比之前提供的 API 更加灵活,因为它允许 YouTube 针对不支持 Flash 的移动设备提供 HTML5 播放器(而非 Flash 播放器)。

demo


<!DOCTYPE html>
<html>
<body>
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div> <script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); // 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '360',
width: '640',
videoId: 'M7lc1UVf-VE',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
} // 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
} // 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function stopVideo() {
player.stopVideo();
}
</script>
</body>
</html>

react & youtube的更多相关文章

  1. RxJS + Redux + React = Amazing!(译一)

    今天,我将Youtube上的<RxJS + Redux + React = Amazing!>翻译(+机译)了下来,以供国内的同学学习,英文听力好的同学可以直接看原版视频: https:/ ...

  2. RxJS + Redux + React = Amazing!(译二)

    今天,我将Youtube上的<RxJS + Redux + React = Amazing!>的后半部分翻译(+机译)了下来,以供国内的同学学习,英文听力好的同学可以直接看原版视频: ht ...

  3. React Native开发技术周报2

    (1).资讯 1.React Native 0.22_rc版本发布 添加了热自动重载功能 (2).技术文章 1.用 React Native 设计的第一个 iOS 应用 我们想为用户设计一款移动端的应 ...

  4. React学习资料

    以下是我整理的React学习资料,包括:React基础.Redux.reat-router, redux middleware, higher order components, React验证等, ...

  5. 【转】React.js 概览

    原文转自:http://segmentfault.com/blog/jiyinyiyong/1190000000693651 这里关于 React 的收集的消息的一个提纲, 具体内容看下边的链接,微博 ...

  6. React vs Angular 2: 冰与火之歌

    黄玄 · 3 个月前 本文译自 Angular 2 versus React: There Will Be Blood ,其实之前有人翻译过,但是翻得水平有一点不忍直视,我们不希望浪费这篇好文章. 本 ...

  7. 移动应用跨平台框架江湖将现终结者?速来参拜来自Facebook的React Native

    React Native使用初探 February 06 2015 Facebook让所有React Conf的参与人员都可以初尝React Native的源码---一个编写原生移动应用的方法.该方法 ...

  8. 【翻译】React vs Angular: JavaScript的双向性

    翻译原文链接:https://blog.prototypr.io/react-vs-angular-two-sides-of-javascript-b850de22b413 我的翻译小站:http:/ ...

  9. react源码总览(翻译)

    用react也有段时间了, 是时候看看人家源码了. 看源码之前看到官方文档 有这么篇文章介绍其代码结构了, 为了看源码能顺利些, 遂决定将其翻译来看看, 小弟英语也是半瓢水, 好多单词得查词典, 不当 ...

随机推荐

  1. mongodb查询的语法(大于,小于,大于或等于,小于或等于等等)

    1 ) . 大于,小于,大于或等于,小于或等于 $gt:大于$lt:小于$gte:大于或等于$lte:小于或等于 例子: db.collection.find({ "field" ...

  2. ogg-01027(长事务)

    OGG-01027(长事务) 示例9-25: WARNING OGG-01027  Long Running Transaction: XID 82.4.242063, Items 0,  Extra ...

  3. openjdk8源码编译

    1. 安装源码管理工具 yum install mercurial 2. 下载源码 hg clone http://hg.openjdk.java.net/jdk8u/jdk8u jdk8u #执行源 ...

  4. AI caffe

    caffe,是一个深度学习框架. Blob 存储数据. 批量图像数据(n, k, h, w):图像数量,图像通道,图像高度,图像宽度. data:值 diff:梯度 Layer data_layers ...

  5. linux上搭建svn服务器

    1.检查当前版本,没有的话用yum安装rpm -qa subversion 2.安装yum install subversion -y 2.建库mkdir -p /home/svn/projectsv ...

  6. Python-TXT文本操作

    一.列出IO操作的标识符及描述 标识符 描述 r 以只读方式打开文件.文件的指针将会放在文件的开头.这是默认模式. rb 以二进制格式打开一个文件用于只读.文件指针将会放在文件的开头.这是默认模式. ...

  7. kattis Programming Tutors 给游客与导游匹配(二分+二分图)

    题目来源:https://vjudge.net/problem/Kattis-programmingtutors 题意: 有n个游客,n个导游,给出他们的坐标,问你怎么匹配可以使他们最大距离最小 题解 ...

  8. PHP实用代码片段(四)

    1. 删除文件夹内容 function Delete($path) { if (is_dir($path) === true) { $files = array_diff(scandir($path) ...

  9. php微信公众号开发入门小教程

    1.配置相关服务器 (1) 如下,把自己的服务器ip白名单配置上: (2) 开始配置令牌,配置令牌时先需要把现成的代码放到自己的服务器上面,代码里面包含自己的设置的令牌号码,这样才可以配置成功. 注意 ...

  10. 正则表达式验证input文本框

    方便以后的查找,直接copy代码在这里了. eg: //公司邮箱验证 if ($("#Email").val() != "") { var myreg = /^ ...