0 Replies Latest reply on Feb 12, 2017 3:39 PM by ganduking

    Making changes to Javascript code to play Audio on Android


      Hi there.


      (Backgrounder - Feel free to scroll past) First off I apologize if my question seems rather basic for those more experienced.  I have just gotten back into hard core programming.  Where I have spent that last 14 years in Sales.  During my Sales Career, I would keep up some some small programming projects as a hobby.  Before my Sales Career I was a full blown programmer and was a little sharper on my game.  So I'm getting up to date with the standards of today.


      I spent many hours Googling searching this site and other.  And couldn't get a clear cut answer that I knew was 1) Up to date with todays standards 2) Easy to understand for someone brushing off the rust with his programming skills.


      I have been in the process of converting my first app that I released (When I was in Sales) for Android and Iphone.  Believe it or not I coded this in Adobe Flash and it ended up being a relatively popular app.  I am now in the process remaking this in Javascript.  Since the Android version requires the Adobe Air component (Iphone works stand-alone though)


      (The Meat) Everything looks great in my new re-coded version of my app when I look at in a Browser.  However the fun begins when I compile it to an APK and test it on the Android device.


      One of the core features of the app is playing music in the background.  And this works in the browser version, but not the compiled APK.  I have read this because of how Android works with a Webview with the App coming from Phonegap.


      The music object is first loaded as an HTML5 object :



      <audio id="audio" src="music/song.mp3" class="AudioPlayerV1"></audio>



      Where it is then activated with the pressing of a button which activates the music function :



        function play(){

        audio.loop = true;





      I know this is not an uncommon problem, however looking over most solutions I found confusing as it assumes knowledge of certain things like using certain respective libraries which I am filling in the process of filling in the gaps.  But seems like it should be a relatively straightforward fix, without having to get too fancy I would think to get the initial release out.


      Typically I learn best by taking small chunks.  So I usually would find small sample code that I know works.  And then see where the discrepancies in my code are an integrate them.


      The most popular post I see on the issue seems to be this article.  Which seems well written and clear :






      However I couldn't even get this working via the sample code.  As when I run it via browser and add phonegap.0.9.5 I get an error "gap:["Media","startPlayingAudio","Media0",true]" and when I compile it using Phonegap into APK doesn't do anything.



      Plus the article assumes this will work when its converted to the Iphone.  Stating it more of a should.  Not that matters a whole lot right now since I want to initially get this out for Android and the Iphone version can wait.



      Any other tutorials / samples that are easier to follow?  I am compiling things via build.phonegap.com