Sound(MediaPlayer) working on emulator but not on a real android device -


the emulator using galaxy nexus api 22, , background music(mp3) works on , running service. however, not work on sumsung galaxy note, has api 16, don't think api-related problem though.

am need write some<uses-permission .../> in manifest? or other solutions.

thank in advance!!

here problem

context context = getapplicationcontext(); activitymanager = (activitymanager) context.getsystemservice(context.activity_service); list<activitymanager.runningtaskinfo> taskinfo = am.getrunningtasks(1); if (!taskinfo.isempty()) {     componentname topactivity = taskinfo.get(0).topactivity;     if (!topactivity.getpackagename().equals(context.getpackagename())) {         soundservice.pausesound();         toast.maketext(welcomepage.this, "you left app", toast.length_short).show();     }     else {         toast.maketext(welcomepage.this, "you switched activities within app", toast.length_short).show();     } } 

i used these code in onpause() in welcomepage activity (which 'mainactivity' in app) in order pause background music when press home key or whatever.but found toast shows "you left app" when activity shows without anything, think these piece of code problem is. can me? thank you!!

try code, works here:

in activity, declare media player session before oncreate this;

mediaplayer mp = new mediaplayer(); 

put mp3 file on res/raw folder!

finaly put code on java! (if want play automatic put on oncreate, or can put in button if want).

mp.stop(); // stop if run in place mp = mediaplayer.create(this, r.raw.nameofyourfile);//load file folder mp.setlooping(false); // set loop off, if want it's on change (true) mp.start(); // start playing sound 

i hope you!


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -