音频音量是零? [英] The audio volume is zero?

查看:199
本文介绍了音频音量是零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个静音键的应用程序。我一直停留在这4个半小时,现在,让我平淡绝望。我想有静音,当用户点击静音,然后当用户再次单击它取消静音。这工作得很好,除了音频是不是在玩。出于某种原因,Stream_Music是0?

I have an application with a mute button. I have been stuck on this for 4 and a half hours now, so I am plain desperate. I am trying to have the volume mute when user clicks mute and unmute when user clicks it again. This works fine, except the audio isn't playing. For some reason, Stream_Music is 0?

 public void mute(View view) {
        mutebutton = (ImageButton) findViewById(R.id.mutebutton);

        if ((variableForMute.x % 2) != 0) { //If it's odd UNMUTE
            Log.v(TAG, "Use this volume to unmute " +userVolumeOnStart.userVolume +"");
            Toast.makeText(Main_Menu.this, "UNMUTED", Toast.LENGTH_SHORT).show();
            mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, userVolumeOnStart.userVolume, 0);
            variableForMute.x++;


        } else { //If its even MUTE
            userVolumeOnStart.userVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
            Log.v(TAG, "Right Before Mute " +userVolumeOnStart.userVolume +"");
            mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
            Toast.makeText(Main_Menu.this, "MUTED", Toast.LENGTH_SHORT).show();
            variableForMute.x++;
        }
    }

下面是我声明的变量和对象的开头:

Here is the beginning where I declare the variables and objects:

ImageButton leftcenter;
ImageButton mutebutton;
final String TAG = "userVolume";
private AudioManager mAudioManager;



@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main__menu);
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    leftcenter = (ImageButton) findViewById(R.id.startGame);


}

的事情是,作为日志输出,我得到了以下内容:

The thing is, as log outputs, I am getting the following:

输入图像的描述在这里

我应该有容积变化来之前,我开始了我的应用程序是什么我量了。我希望能有取消静音的应用程序,以用户最初在相同体积的用户。但由于某些原因,它始终是0!?这究竟是为什么?我的手机体积是满了吗?!

I should have the volume change to what my volume was before I started my app. I want to be able to have the user unmute the app to the same volume that the user was originally on. But for some reason it is always 0!? Why is this happening? My phone volume is at full?!

请帮忙,

我已经花了太多的时间在这个-I AP preciate所有反馈:  积极的,消极的,中立的,等等。

I have spent way too much time on this-I appreciate all feedback: positive, negative, neutral, whatever.

推荐答案

我发现这个问题。我已经改变了 STRAM_MUSIC STREAM_RING 和变量 userVolumeOnStart.userVolume 成功地改变了!

I found the issue. I have changed STRAM_MUSIC to STREAM_RING, and the variable userVolumeOnStart.userVolume changes successfully!

这篇关于音频音量是零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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