源码地址:https://github.com/Tinywan/PHP_Experience


总结:

说明:

  测试环境:本测试全部来自阿里云直播和OSS存储点播以及本地服务器直播和点播

  播放器:VideoJs

直播:

1、阿里云直播,需要CDN设置HTTP头

  

2、本地直播需要设置直播访问服务器的头部信息(本地为Nginx)

add_header 'Access-Control-Allow-Origin' '*' always;

add_header 'Access-Control-Allow-Credentials' 'true';

add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';

add_header 'Access-Control-Allow-Headers' 'Range';

点播:

1、阿里云点播通过OSS存储

  

2、本地点播,需要添加的头部信息:

add_header 'Access-Control-Allow-Origin' '*' always;

add_header 'Access-Control-Allow-Credentials' 'true';

add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';

add_header 'Access-Control-Allow-Headers' 'Range';

flash播放器播放m3u8提示跨域错误

播放器跨域访问时需要添加策略文件,即在视频播放链接所在域名的根目录下,添加crossdomain.xml文件,其中添加播放器所在域名的权限,例如:

http://test1.com/app/test.m3u8 需要添加 http://test1.com/crossdomain.xml

<?xml version="1.0" encoding="UTF-8"?>
<cross-domain-policy>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="*" secure="false"/>
</cross-domain-policy>

或者;

<?xml version="1.0" encoding="UTF-8"?>
<cross-domain-policy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.adobe.com/xml/schemas/PolicyFile.xsd">
<allow-access-from domain="g.tinywan.com"/>
</cross-domain-policy>

如下所示:

使用Flash播放器在线播放M3U8文件,需要在M3U8文件所在Bucket根目录下放置crossdomain.xml文件,文件中包含Flash播放器所在域名,否则无法播放。

使用媒体转码控制台预览您的M3U8文件,请在该M3U8文件所在Bucket根目录下放置如下内容的crossdomain.xml文件:

其中 g.tinywan.com 是我的Web播放器所在的域名,如您使用其他的Flash播放器,将播放器所在的域名添加一条新的allow-access-from domain记录即可。

想播放hls协议的就是m3u8文件,video.js原生不支持,官方有个插件videojs-contrib-hls 直接进入即可:

<script src="__PUBLIC__/lib/video-js/videojs-contrib-hls.min.js"></script>

今天纠结了一天,调试到最后发现原来是跨域的问题:

如果使用阿里云OSS存储的话(别的服务器设置头部可访问即可),在跨域设置中做如下设置即可:

关于跨域问题:https://help.aliyun.com/document_detail/31928.html

<!DOCTYPE html>
<html>
<head>
<title>Video.js | HTML5 Video Player</title> <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="__PUBLIC__/lib/video-js/video-js.css" rel="stylesheet">
<script src="videojs-contrib-media-sources.min.js"></script>
<script src="__PUBLIC__/lib/video-js/video.js"></script>
<script src="__PUBLIC__/lib/video-js/videojs-contrib-hls.min.js"></script> </head>
<body>
<center>
<video id="live-stream" class="video-js vjs-default-skin vjs-big-play-centered"
controls autoplay preload="auto" width="1080" height="520" poster="__PUBLIC__/Common/static/images/videodemo.png"
data-setup='{"example_option":true}'>
<source src="http://amaitest.oss-cn-hangzhou.aliyuncs.com/record/live123/4001481793159.m3u8" type="application/x-mpegURL">
</video>
</center>
<script>
var options = {
width: 940,
height: 360
}
var player = videojs('live-stream', options); player.on(['loadstart', 'play', 'playing', 'firstplay', 'pause', 'ended', 'adplay', 'adplaying', 'adfirstplay', 'adpause', 'adended', 'contentplay', 'contentplaying', 'contentfirstplay', 'contentpause', 'contentended', 'contentupdate'], function(e) {
console.warn('VIDEOJS player event: ', e.type);
});
</script>
</body>
</html>

以上代码经过测试,可以正常播放m3u8文件。

官方文档当前不支持Internet Explorer <10。(The README states that there is currently no support for Internet Explorer < 10.Most of our enterprise clients are still running IE8, so I'm curious whether this will be on your roadmap once the codebase stabilizes, or whether you'll require users to upgrade?The two issues I noticed so far are lack of typed arrays and CORS support.)

特别提示:如果使用IE浏览器,建议升级IE浏览器到 IE 11 即可正常播放

阿里云视频直播:使用OBS推流RTMP 时候显示以上问题

解决办法:配置CDN,修改Http头即可以

http://tinywan.com/live/4001490605096.m3u8 播放正常

最新文章

  1. TortoiseSVN文件夹及文件图标不显示解决方法
  2. ubuntu 16.04 搭建无线共享热点(PC 无线直连Android移动终端 调试,监控屏幕)
  3. 转: windows下面安装Python和pip终极教程
  4. 启动Oracle
  5. [转] Spring注解@Component、@Repository、@Service、@Controller区别
  6. 关于项目使用可配置的properties 文件的实现
  7. Win 7 下制作 mac 系统启动U盘
  8. Dynamic Programming - Part1
  9. 第八章 jQuery与Ajax应用
  10. centos 挂载与卸载硬盘
  11. Linux下查看显示器输出状态以及修改显示器工作模式(复制 or 扩展)
  12. Django实现用户注册登录
  13. 使用c++如何实现在gRPC中传输文件
  14. 使用指针来实现变长数组(VLA)
  15. linux 服务器之间配置免密登录
  16. 如何使用eclipse创建JAVA项目并写一个简单的HelloWorld
  17. 安装samba脚本
  18. CTF中常见Web源码泄露总结
  19. Twitter OA prepare: Rational Sum
  20. FileTable的创建和使用

热门文章

  1. eclipse自动补全快捷键失效,sysout用不了!
  2. msysgit之git bash方便的复制粘贴,默认工作目录,窗口大小,提高速度等小窍门
  3. C#数组的声明
  4. javaSE基础第二篇
  5. HTML5--拖动02-dragstart、drag、dragenter、dragover、dragleave、drop、dragend属性
  6. 【转载】jQuery动画连续触发、滞后反复执行解决办法
  7. 夺命雷公狗-----React---21--小案例之心情留言板
  8. 8139too.c网卡驱动简单分析
  9. MongoDB - 在Windows上安装
  10. YbSoftwareFactory 代码生成插件【二十】:DynamicObject的序列化