How to Delay Audio file after the acktivity is Started?

A

AC Question

public class ClassMain extends AppCompatActivity {

LinearLayout linearclass1;
Toolbar toolbar;
TextView customtexttoolbartitle;
MediaPlayer mediaPlayer;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_6_parts);

toolbar = (Toolbar) findViewById(R.id.custom_toolbar);
customtexttoolbartitle = (TextView) findViewById(R.id.custom_toolbar_title);
customtexttoolbartitle.setText("Select Your Grade");

sound();
linearclass1 = (LinearLayout) findViewById(R.id.linear_class_1);
linearclass1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ClassMain.this, ClassOneSubjectList.class);
startActivity(intent);
mediaPlayer.stop();

}
});
}

void sound() {

mediaPlayer = new MediaPlayer();
mediaPlayer = MediaPlayer.create(this, R.raw.got);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setLooping(false);
mediaPlayer.start();
// mediaPlayer.stop();
mediaPlayer.setVolume(100, 100);

}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
mediaPlayer.stop();
}

@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
mediaPlayer.stop();
}

}