AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
10/02/12 08:55 AM (11 years ago)

Does Background Audio Play in Android?

I have a simple app for ios and android. I want it to play an mp3 as background audio to a custom html/text page. The mp3 file lives outside the project and is referenced as a URL. App works fine on an iPhone, no sound on Android. Does anyone use background audio on Android? If so, please tell me how!
 
GilbertAZ
Aspiring developer
Profile
Posts: 37
Reg: Jul 16, 2012
Arizona
2,820
like
06/26/13 08:34 AM (10 years ago)
@AlanMac, did you ever find a solution to your question? I have the same issue, mp3 not playing. And when I looked into the code, there's nothing that is handling this ... guess that's why it doesn't work. :) Just interested to know what you found out or other alternatives. Thanks!
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
06/26/13 12:38 PM (10 years ago)
Hi @Alzooka I tried html5 - that worked reasonably well for android 2.3 and above. A discussion on this is here http://www.buzztouch.com/forum/thread.php?tid=8DB78038FD780BF39A5A2D4 I also had some success with this plugin https://www.buzztouchmods.com/downloads.php?cat_id=1&download_id=39 Problem for me was the visuals. Or you could google could try googling for javascript / jquery solutions. For what I wanted to do, I ended up making my audio into a video mp4 and using the AT53 video player plugin. Good luck, Alan
 
GilbertAZ
Aspiring developer
Profile
Posts: 37
Reg: Jul 16, 2012
Arizona
2,820
like
06/26/13 06:03 PM (10 years ago)
Thanks, Alan. I was hoping to have the audio play on the BT_Map plugin, to give instruction to the user on which pins to click, etc. My objective is to create a tour guide and I wanted to overlay voice while the map was displayed. With your suggestion, I can still make it possible in a variety of ways, so thank you for the lead.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
10/14/13 02:06 AM (10 years ago)
Guys, not sure if you worked this out, but if not, I did. The use is a bit limited, because apparently background audio is not supported in Android (at least, v2.2 which is what I'm working with) so I had to use my own audio methods. I did this in an HTML plugin, but it should work on most all of them. In my plugin class file, I declared 3 new variables: private String audioFileName = ""; private String pageTitle = ""; private MediaPlayer myMediaPlayer; In my 'onCreate' method I put this code right above the 'setup saveAsFilename' area... audioFileName = BT_strings.getJsonPropertyValue(this.screenData.getJsonObject(), "audioFileName", ""); pageTitle = BT_strings.getJsonPropertyValue(this.screenData.getJsonObject(), "localFileName", ""); BT_debugger.showIt(activityName + ": Audio File Name: " + audioFileName); BT_debugger.showIt(activityName + ": Page Name: " + pageTitle); ////////////////// if (pageTitle.toString().equals("about.html")) { BT_debugger.showIt(activityName + ": About Audio"); if(BT_fileManager.doesProjectAssetExist("BT_Audio", audioFileName)){ BT_debugger.showIt(activityName + ": File Exists"); try{ AssetFileDescriptor afd = getAssets().openFd("BT_Audio/" + audioFileName); myMediaPlayer = new MediaPlayer(); myMediaPlayer.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength()); myMediaPlayer.prepareAsync(); }catch(Exception e){ BT_debugger.showIt(activityName + ":EXCEPTION setting up soundPlayerCorrect. Message: " + e.toString()); } } } /////////////////////////// In my 'onStart' and 'onResume' methods I added this code: if(myMediaPlayer != null) { BT_debugger.showIt(activityName + ":media player should be starting..."); myMediaPlayer.start(); } And in my 'onPause', onStop, and onDestroy methods I added this code: if(myMediaPlayer != null){ if(myMediaPlayer.isPlaying()) myMediaPlayer.stop(); myMediaPlayer.release(); myMediaPlayer = null; } It only plays once when the screen loads, which is what I wanted. Hope it works out, or leads to a solution, for you guys. Cheers! -- Smug
 
yenael
Aspiring developer
Profile
Posts: 100
Reg: Sep 17, 2013
Detroit
2,950
like
10/14/13 05:09 AM (10 years ago)
Awesome! Man I was just about to search for background mp3 just now! I used it for home screen menu, but I will try this for the home screen, hope it works. Do I need the pagetitle string since I am using the Menu Screen Simple?
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
10/14/13 05:24 AM (10 years ago)
I only isolated the pageTitle (aka localFileName) because I wanted the audio on one page only. So that is how I created 'the trigger'; hardcoding the desired page filename. It plays the audio when the page is equal to 'about.html', otherwise, it stays silent. You might want to alter that so that it plays for all screens, or add/change additional 'if' or 'switch' statements to play just the ones you want. Cheers! -- Smug Oh, and when it gives you errors (and it WILL give you errors) just right-click on the error, and let the Eclipse IDE show you corrective options; the ones you want will always be a reference, not any classes or variables. References only.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.