A
A
Andrey Zhidenko2016-09-02 20:31:30
Android
Andrey Zhidenko, 2016-09-02 20:31:30

How to turn off sounds in the application?

In the application, I implemented the playback of a certain sound at a certain event.

MediaPlayer mp = MediaPlayer.create(activity, R.raw.my_sound);
mp.start();

Now I'm trying to make an analogue of the "silent" mode, but only for my application, not for the entire system. Here's what we found
AudioManager aManager=(AudioManager)getActivity().getSystemService(Context.AUDIO_SERVICE);
        if(aManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT){
            aManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            textView.setText("SOUND:OFF");
        } else{
            aManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
            textView.setText("SOUND:ON");
        }

This solution doesn't work like this
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setVolume(0, 0);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question