我正在尝试在带有 PHP 的移动浏览器上使用 html5 流式传输 mp4 视频。
我正在使用以下课程:
http://labs.divx.com/node/17030
该脚本工作正常,除了对 mime_types 数组的引用,我必须删除 $ 才能使其工作。
无论如何,我的问题是这个。当我使用 file.mp4 运行此脚本时,它在我的手机上运行良好。
但是一旦我输入代码以验证是否允许播放文件等(如果客户购买了视频,他们是否超过了允许的观看次数等)
该文件根本不会加载。
不过,它确实会在桌面浏览器中加载。它仅在移动浏览器中不加载。
这是我用来播放文件的代码:
当我这样运行它时,它适用于桌面浏览器,但不适用于移动设备:
<?php
apc_clear_cache();
session_start();
require(dirname(__FILE__) . "/../_includes/config.php");
require(dirname(__FILE__) . "/../_includes/validate_session.php");
$id = (int)$_GET['id'];
if (!$result = $mysqli->query('SELECT
orders_item_product_downloadable_videos.id,
orders_item_product_downloadable_videos.current_no_downloads,
DATE_ADD(IF(orders.id IS NOT NULL,orders.date_order,o.date_order),INTERVAL orders_item_product_downloadable_videos.no_days_expire DAY) AS date_expire,
product_downloadable_videos.embed_code,
orders_item_product_downloadable_videos.no_days_expire,
orders_item_product_downloadable_videos.no_downloads,
product_downloadable_videos.filename,
product_downloadable_videos.stream,
product_downloadable_videos.source
FROM
orders_item_product_downloadable_videos
LEFT JOIN
(orders_item_product CROSS JOIN orders_item CROSS JOIN orders)
ON
(orders_item_product_downloadable_videos.id_orders_item_product = orders_item_product.id AND orders_item_product.id_orders_item = orders_item.id AND orders_item.id_orders = orders.id)
LEFT JOIN
(orders_item_product AS oip CROSS JOIN orders_item_product AS oip_parent CROSS JOIN orders_item AS oi CROSS JOIN orders AS o)
ON
(orders_item_product_downloadable_videos.id_orders_item_product = oip.id AND oip.id_orders_item_product = oip_parent.id AND oip_parent.id_orders_item = oi.id AND oi.id_orders = o.id)
INNER JOIN
product_downloadable_videos
ON
(orders_item_product_downloadable_videos.id_product_downloadable_videos = product_downloadable_videos.id)
WHERE
orders_item_product_downloadable_videos.id = "'.$id.'"
AND
(
(orders.id IS NOT NULL AND orders.status IN (1,7) AND orders.id_customer = "'.(int)$_SESSION['customer']['id'].'")
OR
(o.id IS NOT NULL AND o.status IN (1,7) AND o.id_customer = "'.(int)$_SESSION['customer']['id'].'")
)
LIMIT 1')) throw new Exception('An error occured while trying to get video info.'."\r\n\r\n".$mysqli->mysqli->error);
if (!$result->num_rows) {
//throw new Exception(language('account/order', 'ERROR_DOWNLOAD_EXPIRED'));
exit;
}
$row = $result->fetch_assoc();
$result->free();
if ($row['no_downloads'] > 0 && $row['current_no_downloads'] >= $row['no_downloads']) {
//throw new Exception(language('account/order', 'ERROR_NO_DOWNLOADS_REACHED'));
exit;
}
if ($row['no_days_expire'] > 0 && strtotime($row['date_expire']) <= time()) {
//throw new Exception(language('account/order', 'ERROR_DOWNLOAD_EXPIRED'));
exit;
}
$file = dirname(__FILE__).'/../admin/protected/streaming_videos/'.$row['source'];
require(dirname(__FILE__).'/../_includes/classes/stream.php');
$st = new VSTREAM();
$st->stream(dirname(__FILE__).'/../397d729225599bcda978ac4fd4aaeba2.mp4');
当我像这样评论和运行它时,它可以在移动浏览器中运行,但为什么呢?
<?php
apc_clear_cache();
session_start();
require(dirname(__FILE__) . "/../_includes/config.php");
require(dirname(__FILE__).'/../_includes/classes/stream.php');
$st = new VSTREAM();
$st->stream(dirname(__FILE__).'/../397d729225599bcda978ac4fd4aaeba2.mp4');
如果我添加validation_session.php 代码,它就不起作用。
<?php
apc_clear_cache();
session_start();
require(dirname(__FILE__) . "/../_includes/config.php");
require(dirname(__FILE__) . "/../_includes/validate_session.php");
require(dirname(__FILE__).'/../_includes/classes/stream.php');
$st = new VSTREAM();
$st->stream(dirname(__FILE__).'/../397d729225599bcda978ac4fd4aaeba2.mp4');
validation_session.php 代码里面只有这个:
<?php
if(!$_SESSION['customer']['id']){
header("Location: /account/login");
exit;
}
?>
我什至通过使用非工作短代码在屏幕上输出会话来测试会话,我可以看到 $_SESSION['customer']['id'] 确实存在。
所以我不知道我在这里缺少什么。
如果有人知道为什么这不起作用,我将非常感谢您对此的意见!
谢谢!