How to stream media to an Android device over LAN or the Internet

A couple of weeks ago I purchased an Android tablet (The Google Nexus 7 which is excellent btw). One of the first things I wanted to do with it was to be able to stream my music and films to it over my home network. I naively thought something like this would have been supported as standard in the latest version of Android (v4.2.2 at the time of writing) but it isn’t. To get this working there are a number of steps that you will have to follow which I will outline below.

The first step is to set up a media server. Now what do I mean by this. Well ideally you want some software that can interface with all of your devices (not just Android). There are a set of networking protocols that allow this which come under the Universal Plug and Play (UPnP) system. So our server will have to support these. Also, many modern devices also support DLNA (Digital Living Network Alliance). Most modern TVs, games consoles, mobile phones and many more devices are DLNA certified so it would be ideal if our server software can interface with devices as well. After doing a bit of searching I found the Universal Media Server. It is a DLNA compliant UPnP server that is written in Java so it will work on Windows, Linux and OSX. After installing UMS you will be presented with the form below:

Universal Media Server

There are many things you can configure but the main thing we want to look at are under the “Navigation/Share Settings” tab. Here you can choose the folders you want to share and I also checked the “Hide #–Transcode–# Folder” option as you don’t want these cluttering up your view of the files.

transcode

Once you have made your changes to the sever settings, click “Save” at the top of the form and then restart the server. You now have a media server that is ready to serve all of your selected media over your home network (Don’t forget to add in firewall exceptions so Java can communicate through it). If you have an Xbox you will be able to see this server under “TV & Movies” -> “My Video Apps” -> “System Video Player”. You will then prompted to select a media source and the UMS should now be showing. You will then be able to play music and video through your Xbox so long it supports the format of media you are trying to play. However, this doesn’t help with my Android tablet I hear your cry. Well, to connect into the UMS that you just set up with an Android device you will have to download an app from the Google Play Store. There are quite a few apps that will do this however the one I would recommend is BubbleUPnP. BubbleUPnP is a fully featured UPnP/DLNA Control Point and UPnP Media Renderer as well as an actual UPnP Media Server as well. The free version of this app will allow you to connect to a media server over your LAN only. If you want to connect to your media over the Internet via it you will have to pay for the fill version which is around £3 at the time I am writing this blog. To connect BubbleUPnP to your UMS that you just set up go to the “Devices” tab. Here you will see all of the UPnP/DLNA servers on your network.

Screenshot_2013-03-23-15-06-30

You may have noticed a couple of things from the screen shot above. Firstly that my Xbox is listed in the renderers. A renderer is where the media will be played, so if I select “Local Renderer” it will be played on my tablet, if I select “Xbox 360” it will be played on my Xbox. Also if you have a TV with DLNA capabilities and have set it up on your home network it will also show on this list. This is how BubbleUPnP acts as a UPnP/DLNA control point allowing you to wirelessly choose where your media is played. You may have also noticed that my UMS that I set up is listed twice. The first UMS in this list is my tablet accessing the server over the LAN, the second is it accessing it over the internet. In this next section I’ll explain how to make your UMS accessible over the Internet.

The developer of BubbleUPnP has also made a bit of software called BubbleUPnP Server that sits over the top of our UMS that we set up earlier. BubbleUPnP Server allows one or more UPnP/DLNA media servers to be broadcast over your internet connection so you can have access to your media anywhere in the world. Installing BubbleUPnP server is straight forward however setting it up can be a bit tricky if you are unfamiliar with your router settings. However before setting up your router it is best to set up the BubbleUPnP server. Once it has been installed if the server management hasn’t opened up in your browser double click on the short cut it will have made on your desktop. You will then be presented with a page like this:

bubbleupnpserver1

This screen shows your external IP address (You will use this to connect to the server) and the ports that it will be running over. There isn’t anything you can change here but this page will be useful so we will come back to it later. The first thing you want to do is password protect your server otherwise anyone will be able to connect to it. Not doing this would be bad as not only would it be breaking the law in some countries but also it will eat up your internet connections upload bandwidth as people you don’t know can access all of your media. To do this click on the “Network and Security” tab.

bubbleupnpserver2

Here you can set up a Login and Password. These will be required when connecting to this server. Secondly you will have to say which media server you want to broadcast. This is done under the “Media Servers” tab.

bubbleupnpserver3

Once this has been done the server is good to go. To make this server visible to the outside world you may have to forward some ports through your router. The ports you will have to forward are 58050 (for HTTP traffic) and 58051 (for HTTPS traffic). Most modern routers have this capability so you will have to consult with the routers user manual if you don’t know how to do this.

If you want to connect to this BubbleUPnP Server through your Android tablet you will have to purchase the full version on BubbleUPnP on Google Play. Once you have done this go into “Settings” -> “Network & Settings” in BubbleUPnP on your Android device. Select one of the three “Unset” options and you will be able to enter in the connection settings. This is where the first “Status” page from BubbleUPnP Server will come in handy.

Screenshot_2013-03-23-15-18-39

The server address will be the in this form http://#ExternalIP#:58050 or for https https://#ExternalIP#:58051. You will also have to enter in the login name and password you set up in the BubbleUPnP Server settings. If you test the setting you have entered you will get a success or failure response. If you get at failed response then it will most likely be because you have entered in your IP address incorrectly or there is some not right in your router settings. If the connection is successful you will now be able to access all of your media from anywhere where your Android device has an Internet connection. The server will now be listed in the Libraries list and you will be able access all of your shared media files under the Library tab in BubbleUPnP.

Hopefully this guide will be useful and save someone a lot of time as this took me a good couple of hours to research all of the options and to get it all set up.

N.B. It is worth noting that streaming FLAC music files or HD movies over the Internet to your tablet will only work if your have a seriously good Internet connection as they will most likely use up all of your available upload bandwidth.

Changing C# Dataset (XSD) Connection Strings

One thing that I have often found I have needed to do when programming is to change the connection string properties of an dataset table adapter or queries table adapter. Allowing changes to the connection to be made programmatically can be very beneficial. For example time-outs can be controlled and the database or SQL server instance can be changed on the fly.

The usual way of accessing the connection is the make a partial class on the adapter that exposes the properties that you want to have access to. While this method does work it is not very generic and requires partial classes to be made and maintained. This is OK if you have a small set but can become an unnecessary overhead if you have a large collection of adapters. As such having a generic method of solving this issue was required.

The first thing we have to do is make connection and connection modifier properties on the adapter public because by default they are set to internal.

XSD Connection Moddifier

Next we need to make use of the .Net reflection library. This will allow us to make a generic method that will work over all of the XSDs strongly typed datasets. Due to the way the table adapters and query table adapters are generated I created two methods, however if required I’m sure they could be combined.

Hopefully this code will be helpful to some people as I could find very little online on how to do this.

Hello world!

For a while now I have entertained the thought of doing a blog. I had previously not considered doing one as I wasn’t sure I would get anything out of it. However, after some thought I figured that, in a kind of selfish way, it would help me organise my thoughts and ideas on some subjects that I hold dear to me.

So here I am, sitting here at my computer typing this out with the world of blogging laid out before me. Hopefully this wave of confidence that has got me this far does not fade and leads me to write some interesting articles :).