In the last days i implemented a small Android app that is able to give you a very simple HTML5 camera streaming feature for your smartphone without installing any additional client software. The idea behind this app is, that the HTML5Cam app opens a simple HTTP server that is serves a HTML5 camera updating page from your smartphone. In order to implement this HTTP server feature within my app i used and modified the NanoHTTPD server that consists of single Java 1.1 compatible Java source file, thanks to the great work of Jarno Elonen!
The HTML5 cam page consists of a single page that uses the canvas element to dynamically refresh and update the camera image that is served by the Android app. I modified the NanoHTTPD server to serve files directly out of the compressed assets folder that comes with your app package (apk). So the HTML5 camera page as well as all its styles, images and other resources resides within the assets folder. The source of the HTML5 camera page looks like as follows:
If you open your HTML5 compatible browser and type in the address of your smartphone on port 8080 you get following visual output:
The HTML5Cam app opens a NanoHTTPD server on port 8080 (Android does not allow any server socket port numbers below 1000) and serves this HTML5 camera page and all necessary resources that are found within the compressed assets folder.
To capture the camera image, the app enables the camera preview by creating a live preview SurfaceView:
By implementing and register (setPreviewCallback()) a PreviewCallback listener we can get the notification whenever the preview captured a valid camera image:
You can get the full source code without warranty from here: HTML5Cam.