我使用 jwplayer 运行 m3u8 hls 很长时间了。我只想通过 php 创建一个动态 m3u8 如果我直接将 php 粘贴到浏览器中,我可以获得 m3u8 文件。我还在 VLC 中测试了 m3u8 文件,没有问题。
php:
<?php
/*
create m3u8 here
*/
header("Content-type: application/text");
header("Content-Disposition: attachment; filename=index.m3u8");
echo $m3u8file;
?>
m3u8 文件在这里输出:
#EXTM3U
#EXT-X-KEY:METHOD=NONE
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:138497571
#EXTINF:10,
ch22/2013112102/138497571.ts
#EXTINF:10,
ch22/2013112102/138497572.ts
#EXTINF:10,
ch22/2013112102/138497573.ts
#EXTINF:10,
ch22/2013112102/138497574.ts
#EXTINF:10,
ch22/2013112102/138497575.ts
#EXTINF:10,
ch22/2013112102/138497576.ts
#EXTINF:10,
ch22/2013112102/138497577.ts
#EXTINF:10,
ch22/2013112102/138497578.ts
#EXTINF:10,
ch22/2013112102/138497579.ts
#EXTINF:10,
ch22/2013112102/138497580.ts
#EXT-X-ENDLIST
此脚本将在 jwplayer 中显示错误“加载播放器时出错:找不到可播放的源”
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TEST</title>
<script type="text/javascript" src="jwplayer/jwplayer.js"></script>
<script type="text/javascript">jwplayer.key="xxxxxxxxxxxxx";</script>
</head>
<body>
<div class="player_box">
<div id="player_outer">
<div id="player" style="padding-top:100px;"></div>
</div>
<script>
jwplayer("player").setup({
image: "",
file: "http://xxx.xxx.xxx.xxx/tvod/tvod.php?starttime=1384975713&endtime=1384975803",
width: '680',
height: '450',
autostart: true,
});
</script>
</div></body>
</html>