Hi,
Why does my MediaPlayer stop when I change the layout?
MediaPlayer mp = MediaPlayer.create(this, R.raw.background_song); mp.setLooping(true); mp.start(); setContentView(R.layout.menu_screen);
Thanks in advance
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hi,
Why does my MediaPlayer stop when I change the layout?
MediaPlayer mp = MediaPlayer.create(this, R.raw.background_song); mp.setLooping(true); mp.start(); setContentView(R.layout.menu_screen);
Thanks in advance
First set the layout file
setContentView(R.layout.menu_screen); MediaPlayer mp = MediaPlayer.create(this, R.raw.background_song); mp.setLooping(true); mp.start();
I cant because I have set it so that when I click on a button the this is called: setContentView(R.layout.menu_screen);
I tried making a different activity for the menu_screen.xml layout but when I changed to that one the audio stopped, so i tried staying in the same activity bt again the audio/MediaPlayer stops.
Basically im trying to get audio to play constantly, and continue playing when i change the screen, how can i do this?
Thanks
Ive created a service which plays the audio, but still when i change the layout on the activity the audio stops?
I got it working now, just to let you know why it wasnt working:
I changed this:
public class BackgroundService extends Service{ @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } public void onCreate(){ MediaPlayer mp = MediaPlayer.create(this, R.raw.background_song); mp.start(); mp.setLooping(true); mp.setVolume(100, 100); } }
To this:
public class BackgroundService extends Service{ MediaPlayer mp; @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } public void onCreate(){ mp = MediaPlayer.create(this, R.raw.background_song); mp.start(); mp.setLooping(true); mp.setVolume(100, 100); } }