1

I am trying to develop an audio player.

My first activity has a list of the mp3's from my sd card and I can choose some them and put them in an ArrayList. I have a button (Add to playlist), and when I press it, it starts the new activity where I take the ArrayList, there I create my player, play music etc. But... when I press the back button on the device(you know this that look like such as a half-circled arrow), I go back to my first activity, but the music don't stop and I can choose again songs and if I press the Add To Playlist button then the app plays two songs simultaneously (my first and this second).

How can I handle this? (I want when i go back, choose or unchoose some tracks and then when i press the button (Add to playlist) to play my new list).

I start my second activity like that:

Intent intent = new Intent (Chooser.this, Player.class); Bundle b = new Bundle(); b.putStringArrayList("key", plist); b.putStringArrayList("pos", po); intent.putExtras(b); startActivity(intent); 

I don't want my player stops, simply I want to add or remove songs in my playlist.

1
  • Tim - please don't use answers to communicate updates or further questions to other users. Either update your question or (when you reach the requisite amount of rep) add a comment. Commented May 25, 2011 at 12:03

2 Answers 2

2

You want to implement the one of the Android Lifecycle methods in your second Activity and tell it to stop the MediaPlayer.

The ones you may be interested in are onPause(), onStop(), and onDestroy().

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, thanks you very match, can you tell me where i can declare this global variable?And ,also i don't want my player stops, simply i want to add or remove songs in my playlist...
0

You can use a global variable to maintain the "is playing" state. If you find the user tries to play a new song and the isPlaying variable is true then stop the player before starting the new song.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.