Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 15    Views: 134

franciscoWuLin
Aspiring developer
Profile
Posts: 23
Reg: Mar 15, 2013
Kaohsiung
8,680
05/01/13 06:05 AM (11 years ago)

Interactive Quiz Background Audio on Android not playing

I'm compiling a Quiz App in Eclipse and in the simulator it runs well, plays the right and wrong sounds when taking the Quiz, but, it doesn't play the background audio. I've tried setting the Audio Stops with "Back Button" to No, Audio number of loops to -1, checked that the mp3 file is actually in the assets BT_Audio folder (like the other mp3 that play), that the audio file name is correctly referenced, etc. Tried an extensive search on Google, this Forum and elsewhere and it isn't mentioned anywhere. Anybody can help? Thanks!
 
LA
Aspiring developer
Profile
Posts: 3278
Reg: Aug 16, 2012
Jerseyville, IL
42,880
like
05/01/13 06:22 AM (11 years ago)
Hi @franciscoWuLin, A little more info please. This on Man or PC? Everything works fine in the emulator but not on device? You wanting the background audio to play with the right/wrong audio? LA
 
franciscoWuLin
Aspiring developer
Profile
Posts: 23
Reg: Mar 15, 2013
Kaohsiung
8,680
like
05/01/13 06:43 AM (11 years ago)
Hi LA, It's on a Mac, running Eclipse. The simulator is Google API 13 (Android 3.2) (in preparation to include AdMob). Have not tried on an actual device yet. This background audio plays as soon as you start the Quiz (at least in the iOS version I compiled). I do get the custom audios I included for the right and wrong answers, but not the custom background song. Tks! Francisco
 
LA
Aspiring developer
Profile
Posts: 3278
Reg: Aug 16, 2012
Jerseyville, IL
42,880
like
05/01/13 06:50 AM (11 years ago)
@franciscoWuLin, Ok still confused sorry. You state the background audio plays so is it not stopping then? LA
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
05/01/13 07:02 AM (11 years ago)
@franciscoWuLin, I can never get the background audio playing either so I hardcode it into the BT_screen_quiz.java file instead: under: public class BT_screen_quiz extends BT_activity_base{ add: private MediaPlayer mPlayer; // bg music so you have: public class BT_screen_quiz extends BT_activity_base{ private MediaPlayer mPlayer; // bg music Further down the file find: //add the view to the base view... baseView.addView(thisScreensView); and underneath it add: mPlayer = MediaPlayer.create(this, R.raw.bg); mPlayer.setLooping(true); // Set looping mPlayer.setVolume(5,5); mPlayer.start(); bg is the name of the audio file and it resides in the res > raw folder. If you haven't got a raw folder just add one: right click "res" > New > Folder > name it raw. Finally, find "onPause" - around line 340ish - and under: killQuizSounds(); add: finish(); That should do it.
 
franciscoWuLin
Aspiring developer
Profile
Posts: 23
Reg: Mar 15, 2013
Kaohsiung
8,680
like
05/01/13 07:22 AM (11 years ago)
Raveyd, that was brilliant! It's working, both in the simulator and on the HTC Wildfire S. Just had a bit of problem with the name of the audio file, but simply removed "mp3" from the code (bg=audiofilenamewithoutextension) and it was all good. Thanks! Francisco
 
LA
Aspiring developer
Profile
Posts: 3278
Reg: Aug 16, 2012
Jerseyville, IL
42,880
like
05/01/13 07:26 AM (11 years ago)
Sorry @franciscoWuLin! I guess I need another cup of coffee..lol Thank you @raveyd! LA
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
05/01/13 07:30 AM (11 years ago)
Excellent! Yeah, should have mentioned to not include the file extension - Don't use file extensions for anything in java files referenced from the res folder. Glad it's working :) @LA, lol! My poor kettle's permanently boiling!
 
franciscoWuLin
Aspiring developer
Profile
Posts: 23
Reg: Mar 15, 2013
Kaohsiung
8,680
like
05/19/13 11:30 PM (11 years ago)
@raveyd, I've got a message from Amazon Apps declining my app because of this: Bug Description:Call interrupt fail Steps to Reproduce: 1.Install and launch the app. 2.Tap on "Trivia". 3.The audio starts playing. Make an incoming call to the device. Answer the call. 4.The audio is heard at the back ground of the call. Do you know how to deal with this issue? Thanks in advance for any advice! Francisco
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
05/20/13 04:25 AM (11 years ago)
Hi Francisco, In the file, find all the references to "killQuizSounds();" and underneath each reference add: finish(); Hopefully that should work. If possible test the app before re-submitting to Amazon to make sure it's working as expected. Cheers!
 
franciscoWuLin
Aspiring developer
Profile
Posts: 23
Reg: Mar 15, 2013
Kaohsiung
8,680
like
05/20/13 07:23 PM (11 years ago)
Hi Raveyd, I found 5 references to killQuizSounds and added finish(); 1. //onPause @Override public void onPause() { super.onPause(); //BT_debugger.showIt(activityName + ":onPause"); //kill possible sound effect players... killQuizSounds(); finish(); //was already here } 2. //onStop @Override protected void onStop(){ super.onStop(); //BT_debugger.showIt(activityName + ":onStop"); if(downloadScreenDataWorker != null){ boolean retry = true; downloadScreenDataWorker.setThreadRunning(false); while(retry){ try{ downloadScreenDataWorker.join(); retry = false; }catch (Exception je){ } } } //kill timer for countdown timer... if(updateCountdownHandler != null){ updateCountdownHandler.removeCallbacks(mUpdateCountdownTask); } //kill timer for running quiz timer... if(updateTimeHandler != null){ updateTimeHandler.removeCallbacks(mUpdateTimeTask); } if(delayHandler != null){ delayHandler.removeCallbacks(mDelayTask); } //kill possible sound effect players... killQuizSounds(); finish(); //added this } 3. //kill possible sound effects.. public void killQuizSounds(){ BT_debugger.showIt(activityName + ":killQuizSounds"); //didn't add anything here 4. //kill possible sound effects.. public void killQuizSounds(){ BT_debugger.showIt(activityName + ":killQuizSounds"); //didn't add anything here 5. //start countdown... public void startCountdown(){ BT_debugger.showIt(activityName + ":startCountdown"); //kill possible sounds... killQuizSounds(); //added it here, but then it would start the music, but not go through the trivia proper, but normalised after removing it from here. I tested on a Samsung Galaxy S2 mini and the music didn't stop when I made a call to it, it just moved from the speaker to the ear during the call. On another note, it doesn't even stop when I hit back the hard Back button and return to the main menu. It stops when I enter another screen inside the App. It continues playing the music when I return to the main Android screen, for about 7 seconds, then dies. Anything else you think we could try? Cheers! Francisco
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
05/21/13 05:06 AM (11 years ago)
Hi Francisco, hmmmm... just tested mine, I have finish() in the onPause and onStop events (I didn't notice there were so many other references!). When a phone call is received the audio - and quiz - both stop. The quiz actually closes and kicks back to the start screen. Is this what happens with yours?
 
franciscoWuLin
Aspiring developer
Profile
Posts: 23
Reg: Mar 15, 2013
Kaohsiung
8,680
like
05/21/13 08:21 AM (11 years ago)
Hi Raveyd, I'm not that lucky unfortunately. I think I'll just remove the background music for now, at least for the Amazon version. It's my first App, and also first time dealing with Amazon Apps. They seem to take testing of the apps very seriously. This is like the fourth issue they've raised, so I can make the corrections and resubmit. Good and bad, of course. I appreciate your help a lot! Cheers, Francisco
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
05/21/13 08:51 AM (11 years ago)
Hi Francisco, Yeah, they're strict. You should also try submitting to the Samsung marketplace, they're super strict but provide really excellent reports including videos replicating problems, and recommendations on fixes. If you can pass their tests you shouldn't have too many problems anywhere else. Strange about your quiz behaviour.. Have you made any other changes? It's not a question of luck, it should behave as expected, unless there are differences in how devices handle the code of course...
 
franciscoWuLin
Aspiring developer
Profile
Posts: 23
Reg: Mar 15, 2013
Kaohsiung
8,680
like
05/25/13 06:10 PM (10 years ago)
Hi Raveyd, I know, it's a bit frustrating, but it's a learning process. I should start with more simple stuff and understand the behaviours and triggers properly. Thanks for your help! Francisco
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
05/25/13 06:24 PM (10 years ago)
No problem Francisco, we're all learning! Don't hesitate to post any questions, there's always someone who will help, or at least try to - Honestly, no questions are dumb on here! PS, a good resource to help in understanding code is http://stackoverflow.com
 

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.