Jwplayer播放由php生成的m3u8

时间:2013-11-22 04:19:28

标签: php jwplayer m3u8

我使用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>

1 个答案:

答案 0 :(得分:2)

我已经修好了。看来JWPlayer只能接受m3u8而不能接受php。我将网址更改为http://xxx.xxx.xxx.xxx/tvod/tvod.m3u8?starttime=1384975713&endtime=1384975803。并在服务器上将m3u8重写为php。然后就行了。