Home Handle Media Player
Reply: 2

Handle Media Player

Lemans Trương
Lemans Trương Published in 2014-12-02 16:05:57Z

I have created an application that has 2 activities A and B. From activity A I have a button to call B, in that B I have MediaPlayer to play a song list. When I press back button to back to A, then I press the button to call B again. All of my information's gone but the last Media Player keep playing, when I try to play another song, both Media play as the same. My problem is I want to keep the music playing when I press back button to A, and then I go back to B from A and play other songs without create new Media or just continue the last activity using the last Media Player.

Nazgul Reply to 2014-12-02 16:09:59Z

check State diagram of the MediaPlayer. That should answer your problem. Read the javadoc about how and when to stop the player.

Dexter Reply to 2014-12-02 16:21:14Z

I would suggest you maintain a global MediaPlayer object in your Activity B.

public static final MediaPlayer player = new MediaPlayer():

In your activity B, whenever you make any change to the player just call

player.stop() or player.reset();

before starting the audio session.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.327555 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO