PHP media streamer

The idea is that I want to create a simple PHP media streamer for my website.

I manage to stream a video on the web browser and in a VideoView on Android just fine.

What I want to do

  • Stream this video to multiple users at once
  • Cache the HTML5 video on sdcard on android

Problems

  • I can stream a video but for only one user
  • I'm unable to get the video cached on the sdcard

Codes

streamer.php

<?php
$file = './'.$_GET["file"];
$pos = (isset($_GET["pos"])) ? intval($_GET["pos"]): 0;

header("Content-Type: video/x-flv");
header('Content-Length: ' . filesize($file));

$fh = fopen($file,"rb");
fseek($fh, $pos);
fpassthru($fh);
fclose($fh);

?>

page.html

<HTML manifest="./cache.appcache">
  <video id="vid" controls>
  <source src="http://example.com/streamer.php?file=video.mp4" type="video/mp4">
  </video>
</HTML>

cache.appcache

CACHE MANIFEST
# 2014-03-08 v1.0.0
/video.mp4

On android's side

...
String appCachePath = Environment.getExternalStorageDirectory().getAbsolutePath();
wv.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
wv.getSettings().setAppCachePath(appCachePath);
wv.getSettings().setAppCacheEnabled(true);
wv.getSettings().setAllowFileAccess(true);
wv.getSettings().setDomStorageEnabled(true);
...

Answers


I guess, the caching issue is due to headers not send/set. Give this a try:

    header('Pragma: private');
    header('Expires: '.date('D, d M Y H:i:s \G\M\T', time() + 7200));
    header('Cache-control: private, max-age=7200, must-revalidate');
    header('Content-Length: '.filesize($file));
    header('Content-Disposition: filename='.md5($file));

Also: you set header('Content-Type: video/x-flv'); but use type="video/mp4". I guess, it should be header('Content-Type: video/mp4');

Next: for getting $_GET["pos"] to work, you need to calculate and set the accept range header accordingly.


Need Your Help

How to configure FlashDevelop for unit test builds?

actionscript-3 unit-testing flashdevelop

I'm using AsUnit for unit-testing my current AS3 project. My Main() is basically:

Propagation of Oracle Transactions Between C++ and Java

java c++ oracle transactions jta

We have an existing C++ application that we are going to gradually replace with a new Java-based system. Until we have completely reimplemented everything in Java we expect the C++ and Java to hav...