Thursday, 29 August 2013

Play Sound at Activity Start Android


Play Sound at Activity start Android



When starting the activity i.e on onCreate put the following code.
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);        
    setContentView(R.layout.main);

    MediaPlayer mPlayer = MediaPlayer.create(FakeCallScreen.this, R.raw.mySmallsoundfile);
    mPlayer.start();
}
When stopping the activity i.e on onDestroy put the following code.
public void onDestroy() {
    mPlayer.stop();
    super.onDestroy();
}
Hope this will help J
Happpyyy Cooodddding J