When the Media player plays the sound and each time orientation of the phone is changed from Portrait to Landscape or Landscape to Portrait, the sound starts again each time orientation is changed.
How do I continue the same sound which is currently playing in other orientation, without playing a new sound?
Here is my code:
public void SoundStuff(final Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_viewpager_example);
mP = MediaPlayer.create(this, R.raw.c101);
//btn1 = (Button) findViewById(R.id.btnPlay);
tgbtn1 = (ToggleButton) findViewById(R.id.imageButton2);
btnstop1 = (Button) findViewById(R.id.button1);
tgbtn1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
// The toggle is enabled
try {
mP.start();
//tgbtn1.setVisibility(View.GONE);
}
catch (Exception exception) {
Log.v("exception:play", exception.toString());
}
}
else {
// The toggle is disabled
try {
mP.pause();
}
catch (Exception exception) {
Log.v("exception:pause", exception.toString());
}
}
}
});
btnstop1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(mP.isPlaying()){
mP.stop();
}
SoundStuff(savedInstanceState);
ZoomImageView mViewPager = (ZoomImageView) findViewById(R.id.view_pager);
Btn1ImageAdapter adapter = new Btn1ImageAdapter();
mViewPager.setAdapter(adapter);
}
});