博客
关于我
关于网站嵌入faceboook以及youtube视频
阅读量:253 次
发布时间:2019-03-01

本文共 4689 字,大约阅读时间需要 15 分钟。

在新闻网站中,我们针对国外用户,需要引入第三方视频,

首先引入youtube视频 

我们拷贝youtube视频网址

        https://www.youtube.com/watch?v=oK6k9O65QAs或则
        https://youtu.be/oK6k9O65QAs
 

我们可以看到他的规则  每个youtube视频都由特殊的id    oK6k9O65QAs 就是这个,我们取到他
参考youtube的
视频规则

 

也可以参考 https://developers.google.com/youtube/iframe_api_reference?hl=zh-cn youtube视频api

 

<iframe  type="text/html" src="http://www.youtube.com/embed/oK6k9O65QAs frameborder="0"></iframe>
可以给iframe定义自己的类名控制样式只需要被iframe嵌入到网站任何地方都可以出现视频,可以自定义视频样式

 

<!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: 'oK6k9O65QAs',//唯一的id          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><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: 'oK6k9O65QAs',//唯一的id          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>

这是通过js控制视频播放,可以控制播放以及暂停,也是通过唯一 oK6k9O65QAs来判断

下边讲解facebook视频我们找一个facebook视频地址如

https://www.facebook.com/ExtremeLoveShow/videos/598167423879792/

<div class="fb-video" data-href="https://www.facebook.com/ExtremeLoveShow/videos/598167423879792/" data-width="auto" data-show-text="false"></div> class="fb-video" data-href="https://www.facebook.com/ExtremeLoveShow/videos/598167423879792/" data-width="auto" data-show-text="false"></div>

最后调用这段js代码,注意要分清顺序,必须先有了 class为fb-video,的元素才可以出视频,上边的视频是根据父元素宽度自适应的,你也可以自己指定视频

 

  <script>(function(d, s, id) {    var js, fjs = d.getElementsByTagName(s)[0];    if (d.getElementById(id)) return;    js = d.createElement(s); js.id = id;    js.src = "https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.6";    fjs.parentNode.insertBefore(js, fjs);  }(document, 'script', 'facebook-jssdk'));</script><script>(function(d, s, id) {    var js, fjs = d.getElementsByTagName(s)[0];    if (d.getElementById(id)) return;    js = d.createElement(s); js.id = id;    js.src = "https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.6";    fjs.parentNode.insertBefore(js, fjs);  }(document, 'script', 'facebook-jssdk'));</script>

也可以直接拷贝facebook视频的嵌入就像下边

嵌入的视频,

你可能感兴趣的文章
mysql /*! 50100 ... */ 条件编译
查看>>
mudbox卸载/完美解决安装失败/如何彻底卸载清除干净mudbox各种残留注册表和文件的方法...
查看>>
mysql 1264_关于mysql 出现 1264 Out of range value for column 错误的解决办法
查看>>
mysql 1593_Linux高可用(HA)之MySQL主从复制中出现1593错误码的低级错误
查看>>
mysql 5.6 修改端口_mysql5.6.24怎么修改端口号
查看>>
MySQL 8.0 恢复孤立文件每表ibd文件
查看>>
MySQL 8.0开始Group by不再排序
查看>>
mysql ansi nulls_SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON 什么意思
查看>>
multi swiper bug solution
查看>>
MySQL Binlog 日志监听与 Spring 集成实战
查看>>
MySQL binlog三种模式
查看>>
multi-angle cosine and sines
查看>>
Mysql Can't connect to MySQL server
查看>>
mysql case when 乱码_Mysql CASE WHEN 用法
查看>>
Multicast1
查看>>
mysql client library_MySQL数据库之zabbix3.x安装出现“configure: error: Not found mysqlclient library”的解决办法...
查看>>
MySQL Cluster 7.0.36 发布
查看>>
Multimodal Unsupervised Image-to-Image Translation多通道无监督图像翻译
查看>>
MySQL Cluster与MGR集群实战
查看>>
multipart/form-data与application/octet-stream的区别、application/x-www-form-urlencoded
查看>>