Android app to browse/serve media across DLNA devices

After spending couple of weekends on creating demo app, finally I am able to publish this post on DLNA/Upnp media management.

First of all – What is DLNA?

DLNA is a standard to facilitate access to multimedia content between devices connected within the same computer network. For more information about DLNA, see http://en.wikipedia.org/wiki/Digital_Living_Network_Alliance.

This blog post shows how to create an Android app which can –

  • Browse contents of any DLNA media server and renders their content  locally on Android device.
  • Controls playback on other Media Renderers on same network.
  • Also I have added a functionality to server local device media files to a selected Renderer device thorough hosting a NanoHttpD server in application. (Yes, not a standard DMS device, but works to serve files to other devices)

I have used CyberLinkForJava library which controls DLNA protocols automatically and supports to create your devices and control points quickly. For more info on how this library works, here is a quick programming guide for CyberLink Java.

Let’s run through the details of the demo app – Source & demo APK links are available at the end of blog post 🙂

Backbone of this app is DLNA service which starts a HandlerThread to handle lifecycle of a ControlPoint which notifies when a device is added/removed along with search response callbacks. This Service gets started in Launcher activity and runs indefinitely until we stop it.

Launcher activity hosts two listviews – PlayFrom & PlayTo. I have appended local device entry to both lists explicitly (not through search callbacks from service). You can browse through ‘PlayFrom‘ devices to pick media content to play on selected Renderer(default is local device).

device-2015-03-07-093227      device-2015-03-07-094149

BrowseDMSManager class takes care of enquiring content directories using service name: ‘urn:schemas-upnp-org:service:ContentDirectory:1

If you select local device to browse, I’ve used FilePickerLibrary to pick files locally and start a HttpServer to serve those files to selected Renderer device. Read my earlier blog post on how to serve local files using HttpServer, though I’ve used NanoHttpD here to handler all possible scenarios.

RemoteDlnaController class is responsible for managing communications b/w client and server devices. It has utilities to send PLAY, PAUSE, STOP, VOLUME controls etc.. actions to Renderer device. device-2015-03-07-094701  Screen Shot 2015-03-07 at 9.45.11 am

I’ve added zoom functionality to Image Pageview and some Jazziness, thanks to TouchView, JazzyViewPager & Universal ImageLoader.

Posted demo source to my GitHub. APK is available here.

let me know what you think of it 🙂

Advertisements

HttpServer on Android to stream local video files to other devices

This blogs explains how to embed a mini HttpServer into your android app to serve local video files from your device to  other devices/desktop browsers/mediaplayers

You can do it by serving the local file using Java ServerSocket : server-side socket that waits for incoming client connections. A ServerSocket handles the requests and sends back an appropriate reply.

I made a demo App explaining this functionality, check out the code from Github (demo has a sample mp4, you can find it in assets folder. Move it your SD card  root folder to run the demo successfully)

device-2014-09-06-210137

LocalFileStreamingServer is a Thread which implements Runnable interface, you can create server object by passing the video file object from your activity. Continue reading