This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

MediaPlayer plays the same mp3 again after switching between activities

Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can I prevent this situation?
I have created a simple app that would play a short mp3 file with pause and stop implemented, everything goes fine when I am still in the main activity that control the MediaPlayer. but when I switch to  the child activity and then return to the parent throut the actionbar arrow somthing weared happen, I lose the reference to the MediaPlayer object and when pressing play  button the activity playes the mp3 file again while the first one is still playing in background and the my reference variable mp don't reference to the first one created anymore. the problem does not appear when I am using the back button on the smartphone. is there any solution to this problem ?
also I tryed mp.reset() in my stopDua() method in oreder to start the mp3 file from the beginnign but it didn't work !
thanks in advance....

Posts: 3409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to look at the Android activity life-cycle to understand how and when the methods in your code are called.  The Bundle passed to onCreate can have info about where in the cycle the code is being called.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!