【问题标题】:how to disable sound in my game app?如何在我的游戏应用中禁用声音?
【发布时间】:2014-04-12 15:08:55
【问题描述】:

现在我开发了一个游戏应用程序,就像 google play 上的所有游戏一样,它们都有一个切换按钮来打开/关闭声音。

有没有什么技巧可以让我一步一步禁用游戏中的所有声音,或者我必须单独禁用每个声音??

我使用 MediaPlayer 播放声音

private int playSound(int file) {

    int duration = 1000;
    sound = new MediaPlayer();

    AssetFileDescriptor fd = getResources().openRawResourceFd(file);
    try {
        sound.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
        sound.prepare();
        sound.start();

        sound.setOnCompletionListener(new OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                // Do the work after completion of audio
                Toast.makeText(GameActivity.this, "good", Toast.LENGTH_SHORT).show();
                mp.release();
            }
        });
        duration = sound.getDuration();

    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return duration;
}

【问题讨论】:

    标签: android audio toggle


    【解决方案1】:

    试试这个

       media.setVolume(0,0);
    

    【讨论】:

    • 还有其他声音,比如默认按钮声音?
    猜你喜欢
    • 2016-07-25
    • 1970-01-01
    • 1970-01-01
    • 2014-01-13
    • 1970-01-01
    • 2011-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多