How I got Cordova or Phonegap local html video playback working

I was working on a project recently where I had to create a Cordova Android app that could play video embedded in the “assets/www” directory. This proved to be quite challenging and it seems that there are a lot of hurdles to make this happen. There are many questions  on stackoverflow here and here , amongst many, regarding this issue and there are a lot of problems faced by developers as Android gets updated, with many new workarounds needing to be found.

For a while, I was able to use the Cordova Html5Video Plugin and it worked well, except there is a limited amount of video properties and events available and it is a little awkward, since videos have to be placed in a special directory, which are then placed in the sdcard partition of the device. When I tested this on my device, videos can be accessed from the device’s camera and video roll, which kind of begs the question why the user would watch the video in the app, if they can access the video clips directly outside. I am sure there are workarounds that can be applied in this case, but since this method stops working for me on devices above API 19, it feels kind of broken and messy.

I also was wanting to find a way to work with JSC3D to enable showing some 3D models in a Cordova application. Since JSC3D does not work unless the model is served over http, I was thinking that would it not be nice to have a mini server serving the files from inside the Cordova app? After working through a bit of Google magic, I found this project on Github, called Cordova-httpd, which is exactly what I was looking for.

Suddenly I realised that a lot of the problems with inline video in Cordova could be solved in the same way. One could create a folder for the video files and then serve them using the httpd server into the app. The only thing that would have to be modified were the src attribute of the video elements, which could be set at run time using the “deviceready” event of Cordova.

I have tested this on devices running Android 4.4 through to Android 5.1. So far so good. On older devices with Android versions prior to 4.4, I have tested this same method using Crosswalk API. I hope you find this information useful.

 

A simple checklist before updating your Android ROM

Initial Backup

  • Phone calls history
  • Messages history
  • Backup contacts (if not already in the cloud)
  • Write down backup authentication code for two-factor authentication of Google account

Pre-flash

  • Backup all apps (not Titanium backup)
  • Backup current ROM (Use Recovery mode)
  • Flash boot image

Let me know if there are others that I might be missing, but this is the checklist that I have used a number of times without any incident.