Reputation: 195
I have my project to play sound. It worked well but when I rotate the mobile the sound doesn't work also it worked well when the app start. Also there isn't any error.
@JavascriptInterface
public void playsound(String value ) {
if (value.equals("on")) {
mp= MediaPlayer.create(mContext,R.raw.sound);
mp.start();
} else {
mp.stop();
}
}
Upvotes: 0
Views: 164
Reputation: 2042
You should create the MediaPlayer instance in onCreate and start it in onResume(). Alternatively you can make your program work in only either portrait or landscape mode. This can be set in the manifest.
Upvotes: 0
Reputation: 13564
When your device is rotated, the current Activity
gets recreated. You likely need to hook into the Activity
lifecycle events in order to properly manage the playing of your sound. See the onPause
and onResume
methods explained here: http://developer.android.com/guide/components/activities.html#Lifecycle.
Upvotes: 1