Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Problem With Play Background Music in Android Application
Problem With Play Background Music in Android Application [message #1702096] Sun, 19 July 2015 13:15 Go to next message
abo zar is currently offline abo zarFriend
Messages: 1
Registered: July 2015
Junior Member
hello dear friends. i have a really problem with my eclipse:

i write a code but execute music 2 times simultaneously. but i need music execute one time. this is my code: please help me

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aboutus);

		 if (mPlayer != null){
			 mPlayer.stop();
		        if (isFinishing()){
		        	mPlayer.stop();
		        	mPlayer.release();
		        }
		    }
		        mPlayer = MediaPlayer.create(aboutus.this, R.raw.nelflute);
		        mPlayer.start();
    }  
Re: Problem With Play Background Music in Android Application [message #1867704 is a reply to message #1702096] Thu, 04 July 2024 09:20 Go to previous message
Spice Kit Kat is currently offline Spice Kit KatFriend
Messages: 1
Registered: July 2024
Junior Member
The issue with your code is that you're not properly handling the MediaPlayer instance. You're creating a new instance of MediaPlayer every time onCreate is called, which can lead to multiple instances playing simultaneously.

To ensure that only one instance of the MediaPlayer is active at a time, you should check if the MediaPlayer is already playing before creating a new instance.


Previous Topic:Codeium will not install on 2024-06 (4.32.0)
Next Topic:Missing code implementation in the compiler
Goto Forum:
  


Current Time: Sat Jan 18 20:15:24 GMT 2025

Powered by FUDForum. Page generated in 0.03544 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top