我躲使用PHP输出文件HLS网址,但不工作 [英] I hide HLS URL using PHP to output files but doesn't work

查看:943
本文介绍了我躲使用PHP输出文件HLS网址,但不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我原来的网址: http://xxx.xxx.xxx。 XXX / 01 / MV01 / index.m3u8 基于安全考虑,我搬到网站上的文档根目录以外的所有HLS文件(在/ var / www / html等)。 IE浏览器。它们移动到/var/www/video/01/MV01/index.m3u8包括在同一个文件夹中的所有.ts文件上。

This is my original URL: http://xxx.xxx.xxx.xxx/01/MV01/index.m3u8 For security concern I moved all HLS files outside the document root of web site (/var/www/html). IE. move them to /var/www/video/01/MV01/index.m3u8 including all .ts files in the same folder.

然后我创建的文档根目录中的.htaccess:

And then I created a .htaccess in the document root:

的.htaccess:

.htaccess:

RewriteEngine on
RewriteCond %{REQUEST_URI} .*ts$|.*m3u8$ [NC]
RewriteRule ^(.*) auth.php?file=$1 [NC,L]

这将重定向所有要求,并获得通过PHP输出文件。

This will redirect all requirement and get files outputted by php.

auth.php:

//
Some codes to check authorization first.
//
$reqpath = strip_tags($_GET['file']);
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache,must-revalidate");
header("Cache-Control: post-check=0, pre-check=0",false);
header("Pragma: no-cache");
header('Content-type:application/force-download');
if (strpos($_GET['file'],".ts")>1) header("Content-type: video/MP2T");
if (strpos($_GET['file'],".m3u8")>1) header("Content-type: application/x-mpegURL");
@readfile("/var/www/video/".$reqpath);

当用户访问 http://xxx.xxx.xxx我的目的是什么。 XXX / 01 / MV01 / index.m3u8 他仍然可以播放视频。

My purpose is when user accesses http://xxx.xxx.xxx.xxx/01/MV01/index.m3u8 he still can play the video.

其结果是: 它运作良好的iOS和Android,但可以在PC上,包括jwplayer和VLC不能播放。

The result is: It is working well on iOS and Android but can not play on PC including jwplayer and VLC.

在jwplayer错误消息是错误加载播放器:未找到可玩源 在VLC错误消息是主输入错误:对 HTTP没有合适的解复用模块//xxx.xxx.xxx.xxx/01/MV01/index.m3u8

The error message on jwplayer is " Error loading player: No playable sources found" The error message on VLC is "main input error: no suitable demux module for 'http://xxx.xxx.xxx.xxx/01/MV01/index.m3u8'

**我用的是HLS示例文件下载在apple.com所以我觉得.m3u8和.ts文件上都没有问题。

**I use the HLS sample files download on apple.com so I think the .m3u8 and .ts files are no problem.

帮助!

推荐答案

我已经解决了它最后。

为什么只能打在iOS和Android,但不是在PC上?我想这个问题应该是在PHP中的输出,所以我试图改变HTTP头,然后我找到了答案。

Why can only play on iOS and Android but not on PC? I guess the problem should be in the outputting in PHP so I tried to change the HTTP header and then I found the answer.

只是增加一个标题:

header('Content-Length: ' . filesize("/var/www/video/".$reqpath));

这里所有的首部

All of the header here

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache,must-revalidate");
header("Cache-Control: post-check=0, pre-check=0",false);
header("Pragma: no-cache");
header('Content-type:application/force-download');
header('Content-Disposition: attachment; filename='.basename($filename));
header('Content-Length: ' . filesize("/var/www/video/".$reqpath));
header('Content-Type: '.mime_content_type("/var/www/video/".$reqpath));

希望这可以帮助别人。

Hope this helps someone.

这篇关于我躲使用PHP输出文件HLS网址,但不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆