当旋转移动播放声音不工作 [英] The play sound does not work when rotate the mobile

查看:146
本文介绍了当旋转移动播放声音不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的项目来播放声音。它运作良好,但是当我旋转移动声音不也工作,它运作良好时,应用程序启动。也没有任何错误。

  @JavascriptInterface
公共无效playsound(字符串值){
    如果(value.equals(上)){
        MP = MediaPlayer.create(mContext,R.raw.sound);
        mp.start();
    }其他{
        mp.stop();
    }
}


解决方案

当您的设备旋转时,电流活动被重建。您可能需要以正确地管理你的声音的播放挂接到活动生命周期事件。请参阅的onPause onResume 方法了说明:的 http://developer.android.com/guide/components/activities.html#Lifecycle

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();
    }
}

解决方案

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.

这篇关于当旋转移动播放声音不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆