Turning a Raspberry Pi Zero W into a travel media centre

Photo of a Raspberry Pi Zero W, in the palm of my hand. There is a micro HDMI to HDMI adapter, and a micro USB to USB adapter with a USB memory stick. The Pi is a black plastic case, with a visible black heatsink

tl;dr

I installed and configured Kodi on a Raspberry Pi Zero W.

What’s this about

I am going to be travelling a bit more in the coming months, and that probably means a few more hotel stays. Most hotels have a TV with an HDMI connection, and I’d like to be able to watch some of my own programmes / films.

I have a jellyfin server, which is excellent, but I won’t register for Wi-Fi usage, so that means, in some hotels, I’m reliant on a cellular connection, and I don’t want to stream video over that.

So it needs to cope with local playback.

And, as luck would have it, I already have a USB stick, to which I rsync music, films, and programmes.

So, basically, I need a way of playing that content on a hotel room TV.

I could just hook up my laptop, but I’d rather not tie that up with media playback.

So some kind of small, cheap media player is in order.

I couldn’t find anything which did what I wanted and was available to buy, so I decided to build my own. And it was a lot easier than I’d expected.

I also considered:

Thank you, Simon!

When I mooted doing this project in a post on the fediverse, and whether a Raspberry Pi Zero W would do the job or not, very kind chap, Simon John Green offered to send me one! How generous is that?!

I think he said that the camera port might not work but, since I wasn’t intending to use the camera, no big deal.

And, even more amazingly, it arrived the next day, via Royal Mail, just in time for weekend tinkering…

Thank you, Simon!

Raspberry Pi OS and Kodi

Nothing fancy here - I just installed Raspberry Pi OS (including the desktop), and then, when that had finished, I installed Kodi from the default Raspbian repository.

Dead easy.

(For this particular application, I wasn’t worried about full disk encryption, so I didn’t bother setting up LUKS, and I am comfortable that the Pi logs in automatically. This is not my usual setup!)

The Pi will go into my pencil case that houses all my tech stuff in my bag (charger, cables etc), so I spent £9 on a black plastic case, a micro HDMI to HDMI adapter, and a micro USB to USB adapter. I already had a suitable micro SD card and USB memory stick.

(Yes, it turns out that there is a protective film on the case, which I did not notice until I’d screwed it together. Oh well.)

Booting straight into Kodi, slowly

I used autostart to load Kodi on boot.

I created the text file ~/.config/autostart/kodi.desktop and put into it

[Desktop Entry]
Type=Application
Name=kodi
Exec=/usr/bin/kodi

and that did the trick.

From plugging the power in to Kodi being ready to use, it takes 3m 30s.

This is fine for my planned use - very occasional use in a hotel / when travelling, but definitely long enough to be annoying if I needed to do it multiple times a day.

Configuring Kodi for offline usage and a USB memory stick

Since I already have the content I want on a USB stick, I want to be able to plug that in to the Pi, and have Kodi use the content from there.

Fine: I configured the USB stick to be a media source within Kodi.

Since most times I use it I won’t have an Internet connection, there’s no point trying to get metadata from the Internet for the newly-loaded content. To deal with this, when adding sources (from my USB memory stick), I set each folder to the correct type (Movies, or TV Shows), and set it to local information gather, so that it relied on file metadata rather than gathering metadata from the internet.

I also want it to pick up new content automatically, since I occasionally rsync new stuff onto my USB stick.

In Kodi, I switched on Settings / Media / Update library on startup (video) and “Update library on startup (music)”, and that seems to do the trick.

Configuring a Wi-Fi access point on the Pi

While trying to get my head around remote control of Kodi (below), I wondered if I was going down the wrong route completely, and whether I’d be better off just using vlc or similar.

So, to do that, I configured a Wi-Fi access point on the Pi: I set the Pi to use Network Manager (using raspi-config), then enabled the hotspot mode, and finally set it to connect automatically (i.e. so it runs the hotspot on boot).

That way, when I boot it, the Pi runs a Wi-Fi AP, and I can connect to it from my laptop. I can then access services (such as ssh, or Kodi’s web interface) on the Pi.

This is not ideal, in the sense that I’d need to drop whatever Wi-Fi connection I was using on my laptop to connect to this Wi-Fi network instead but, for how I’m going to be using it, this will be just fine.

It turns out that vlc is not the way forward - it is much easier to control, using cvlc, from the command line, than Kodi, but performance was so poor as to be unusable.

So back to Kodi it was, if I could solve the remote control aspect.

How to control Kodi remotely

I am not going to bring a keyboard and mouse with me, so I need a way to control Kodi on the Pi.

I was originally thinking of a small Bluetooth hardware remote, but even that would double the size of this tiny little computer, so there must be a better way.

Well, there are certainly different ways.

TV remote via HDMI passthrough

After much tinkering on my desk, plugged into a monitor, I plugged it into my TV, to test it.

And, to my surprise - although perhaps I should have thought of it - the use of HDMI meant that the TV’s remote also controlled Kodi. Nice. I was not expecting that.

So that might solve the problem, as I expect to be using this connected to a TV in a hotel room, which is likely to have a remote.

But all the same, I wouldn’t want to rely on it, so I carried on looking.

Control Kodi via CLI

I appreciate that it is an option which most people would want, but I’d happily control it via terminal over ssh.

There is a Kodi API, but it is not obvious that there’s a CLI implementation. If there was, I’d probably use that by preference.

But I did find a three year old npm package called “kodi-cmd”, which promised to be a front end / wrapper for a library which implements the API. So that seemed like a good start.

As I am going to use this box offline, and not a sensitive box anyway, the lack of updates is not unduly problematic.

To get it working, first I installed nodejs from the unofficial repositories.

Then I used nvm to install it:

sudo npm i -g kodi-controller-cli

But I couldn’t get it to connect to my Kodi server.

I tried every permutation I could think of for the host field (localhost, ::1, http://localhost, and many more - looking at the , it looks like it should just be an IP address in the host field)), but I could not resolve the error message Unable to connect to Kodi player @ "http://localhost:8080".

sigh

(If I (bother to) work it out / fix it, I’ll update this…)

Kodi’s web interface

I’d rather not use a web interface if I can use a command line, but, hey, Kodi has a web interface, so I gave that a try.

In Kodi’s Settings / Services, I enabled “Allow remote control via HTTP”, “Allow remote control from applications on this system” and “Allow remote control from applications on other systems”.

Lots of warnings about insecurity but since this will only be accessible to someone on the same LAN, and since that will only happen if someone has connected to the RPi’s Wi-Fi hotspot, and even then all they can do is control my Kodi box, I am not worried.

And… it works!

So far, I’ve managed to do everything I want bar one thing: I could not find a way to dismiss an on-screen error message (“Playback failed”) using the web interface. So, if that happens, I restart Kodi…

Kodi phone app

There are also official (I think) remote control apps for Kodi, including for Android.

I tried it, and it’s fine. But it needs to be on the same Wi-Fi network, and I was really hoping it would work over Bluetooth.

Because I’d need to connect to the AP on the Raspberry Pi, I’d need to drop the always-on VPN on my phone (the WireGuard client on Android isn’t as flexible, in terms of on-demand usage, as its iOS counterpart), and that’s definitely sub-optimal so, while I have the app, just in case, I don’t intend to use it.

What’s it like?

Bloomin’ impressive!

I mean, I have a computer, which fits in the palm of my hand, which I can power off a TV’s USB port, and - slowish boot time aside - I get a perfectly usable media centre experience from it.

Media playback works well. And that’s really what matters.

I’m really quite blown away. I’ve used Raspberry Pi machines for years, but I’ve never tinkered with the Zero range before, and so I wasn’t sure whether it would be anywhere close to up to the job or not. And it is (for me).