Thursday, March 5, 2015

Stream movies to Android devices

    After battling for some time with how to best stream movie content through Ethernet and Wifi from a media server (the Minix Neo Z64 running Linux in this case) where my USB hard disks are plugged, to Android devices connected to my TVs, I've found that the very best method for smooth streaming is to serve the files with a web server.

      That way, on any Android in the house (phone, tablet, TV box, MiniPC, or even an x86 PC) I can use a Web Browser to connect to the Z64 (with its static IP), then navigate my movie folder and click on the link of the movie I want to watch.
Android will prompt with what movie player (I use MX Player, and BSPlayer when MX has trouble) and playing will start, without installing any other app at all!

       I have even been able to have XBMC (now Kodi) on an Android device to read and manage this web-served movie collection just by adding it as an http server (however very long filenames are cut, making it harder for XBMC to link it to the Internet movie database).

For the basics of a NAS on Linux, you can read this article, which was for my original setup with the RK3188.

To serve the files just install on the Minix Neo Z64 a nice light web server, such as nginx. Then it's just a matter of editing the file /etc/nginx/sites-enabled/default to add a section for your file-web-server, like this:

server {
    charset utf-8;
    root /mnt;
    index index.html index.htm;


    location / {
        root /mnt/;
        try_files $uri $uri/ /index.html;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime off;

You'll just have to change the IP for the static one of your Z64, and the two lines that start with "root" which should point to the root folder that you want to share (subfolders will be shared too).

The "charset" line is very important for all of us with accented languages. The "autoindex" lines do the magic of creating a link for each file in a folder.

It is also a good idea to edit /etc/nginx/nginx.conf and set keepalive_timeout and send_timeout both to a large number of seconds, like:

keepalive_timeout 1200;
send_timeout 1200;

That way you can pause a movie for 10 minutes and still be able to resume (or else, after a X minutes pause, upon resume the Android movie player will stop after soem seconds and you'll have to open the file again).

Then, on any device on your local network enter the Z64's IP on a web browser and you'll see the files and folders under /mnt in your Z64.

I usually install also the openssh-server so I can ssh into the Z64 from my PC, instead of connecting it to a TV.

BONUS: Add a script to init that executes one line like this for every hard disk (substitute the sd_) connected to the media server:
sudo hdparm -S 200 -B 100 -K 1 /dev/sd_
 This invaluable piece of advice makes sure that the hard drivers spin off when not used for some time ("-S 200" for 16 minutes). This will enhance by orders of magnitude the life of your precious hard disks, and will reduce your energy bill.

1 comment:

  1. Nice work,

    How about the minix neo x8h? Have you made any progress porting a full distro to it yet?
    It seems like nobody did that yet, I wonder why