Phone in silent mode and the volume of a MediaPlayer

All your problems with Audio, Video and Images.

Phone in silent mode and the volume of a MediaPlayer

Postby bluef » Wed Dec 23, 2009 5:34 pm

Hello,

My application has to play a sound. I use this code, and it works fine:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                 mp = new MediaPlayer();
  3.  
  4.                 mp = MediaPlayer.create(theContext, R.raw.mynotif);
  5.  
  6.                 mp.start();                    
  7.  
  8.  
  9.  
  10.                 mp.setOnCompletionListener(new OnCompletionListener() {
  11.  
  12.                                 @Override
  13.  
  14.                                 public void onCompletion(MediaPlayer mp) {
  15.  
  16.                                            mp.release();
  17.  
  18.                                 }
  19.  
  20.                         });
  21.  
  22.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


To test outside the emulator, I installed the APK on my phone.

Everything is ok, except one point:
when my phone is set to SILENT mode, the sound my application plays is NOT muted

Do I have to link my application sound volume to the global phone settings or something like this ?

Thank you for your help.

BlueF
bluef
Developer
Developer
 
Posts: 33
Joined: Thu Nov 19, 2009 9:45 am

Top

Postby bluef » Thu Dec 24, 2009 10:26 am

I foudn a way to manage it:

I added
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. AudioManager am;
  3.  
  4. am = (AudioManager) theContext.getSystemService(theContext.AUDIO_SERVICE);
  5.  
  6. if (am.getRingerMode()>1) { //Not silent nor vibrate mode !
  7.  
  8.     //Can play the sound
  9.  
  10. }
  11.  
  12.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


In fact, am.getRingerMode will be 1 if phone is set to VIBRATE, or 0 if set to SILENT...

Hope this may help.

BlueF
bluef
Developer
Developer
 
Posts: 33
Joined: Thu Nov 19, 2009 9:45 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 14 guests