Skip to content Skip to sidebar Skip to footer

Android Sound Not Playing In Splash Screen

Im having troubles with playing sound while the splash screen shows. Ive created the 'raw' directory under 'res' directory and put the droid.mp3 file there (around 150Kb). This is

Solution 1:

instead of Thread try is using Handler.postDelayed as:

 Handler handler;
protectedvoidonCreate(Bundle splashBundle) 
    {
        super.onCreate(splashBundle);
        setContentView(R.layout.splash);
        handler = newHandler();  
        splashSound = MediaPlayer.create(SplashActivity.this, 
                                            R.raw.droid);   
        splashSound.start();  //<<<play sound on Splash Screen
        handler.postDelayed(runnable, 5000);
    }
privateRunnablerunnable=newRunnable() {
   @Overridepublicvoidrun() {
     //start your Next Activity here
   }
};

and second way is add MediaPlayer.setOnCompletionListener to MediaPlayer instance which invoke when playback of a media source has completed without putting 5000 Delay as :

protectedvoidonCreate(Bundle splashBundle) 
        {
            super.onCreate(splashBundle);
            setContentView(R.layout.splash);

            splashSound = MediaPlayer.create(SplashActivity.this, 
                                                R.raw.droid);   
            splashSound.setOnCompletionListener(newMediaPlayer.OnCompletionListener() {
           @OverridepublicvoidonCompletion(MediaPlayer splashSound) {

             splashSound.stop();
             splashSound.release();
                   //start your Next Activity here
           }
        });
        splashSound.start();  //<<<play sound on Splash Screen
   }

Post a Comment for "Android Sound Not Playing In Splash Screen"