Reputation: 3958
I create a simple splash screen which has a sound(mp3)
package in.isuru.Hello;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity {
MediaPlayer player;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//splash is a xml layout
setContentView(R.layout.splash);
//haha is a mp3 file.
player = MediaPlayer.create(Splash.this, R.raw.haha);
player.start();
//Timer to pause 5 seconds before go to next intent
Thread timer = new Thread(){
public void run(){
try{
//player starts playing mp3 file
sleep(5000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent openStartingPoint = new Intent("in.isuru.HELLO");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
player.release();
finish();
}
}
I tried android MediaPlayer not playing mp3 file too but it didn't work. I consulted Android Documentation too. but nothing seems to work either.
Upvotes: 1
Views: 921