Cordova Media Plugin vs HTML5 Audio

My Cordova app currently has two ways to play audio, one works on the web app and one works on the cross-platform native app.

  • HTML5 for Web HTML: <audio id="audio" src="audio.mp3"></audio> JS: document.getElementById('audio').play();
  • Cordova Plugin for Mobile JS new Media('audio.mp3').play();

I'm not a fan of writing things twice. Is there an audio solution that works for both web and mobile? Or an elegant way to fallback?

I have used both the media plugin, and HTML5 audio in Cordova apps.

https://github.com/devgeeks/ExampleHTML5AudioStreaming

The Audio element is fairly well supported on mobile.

There is a good solution here that works with the cordova media plugin on devices and the code to emulate it in browsers:

http://forum.ionicframework.com/t/how-to-play-local-audio-files/7479/5

.k

I released a Ionic/Angular module that interfaces with Cordova Media to play audio files. More: http://stackoverflow.com/a/30018460/1964599

You can find the module here: https://github.com/arielfaur/ionic-audio