2013-10-24 54 views
0

我已經創建了一個Android應用程序,它工作得很好。 在我使用媒體播放器播放.wav文件的應用程序中,這也是工作正常。Android的音量奇怪的問題

唯一的問題來了,當我嘗試提高應用程序的音量, 只是當我接觸到了,音量按鈕,音量呼叫增加 但用於應用程序的體積保持相同

任何建議,什麼是影響因素?

這裏是我的代碼來播放音頻

MediaPlayer mediaPlayer;//as global var in activity 
mediaPlayer=new MediaPlayer(); // inside onCreate() method 

每當我需要播放音頻我把這種方法

private void playAudio() { 
     Log.d("hussi","before the media "); 
     try { 
      mediaPlayer.stop(); 
      Log.d("hussi","so the file name passed is"+gif_char+".wav"); 
      AssetFileDescriptor descriptor = getApplicationContext().getAssets().openFd(gif_char+".wav"); 
      long start = descriptor.getStartOffset(); 
      long end = descriptor.getLength(); 
      mediaPlayer.reset(); 
      mediaPlayer.setDataSource(descriptor.getFileDescriptor(), start, end); 
      mediaPlayer.prepare(); 
      mediaPlayer.start(); 

     } catch (IllegalArgumentException e) { 
      Log.d("hussi","1===>>>"+e); 
      e.printStackTrace(); 
      Log.d("hussi",e.getMessage()); 
     } catch (SecurityException e) { 
      Log.d("hussi","2===>>>"+e); 
      e.printStackTrace(); 
     } catch (IllegalStateException e) { 
      Log.d("hussi","3===>>>"+e); 
      e.printStackTrace(); 
     } catch (IOException e) { 
      Log.d("hussi","4===>>>"+e); 
      e.printStackTrace(); 
     }catch (Exception e) { 
      Log.d("hussi","5===>>>"+e); 
      e.printStackTrace(); 
     } 

    } 
+1

setVolumeControlStream(AudioManager.STREAM_MUSIC);在您的onCreate()方法中。這會告訴操作系統,當您的應用程序可見時,音量按鈕應該會影響「媒體」音量,這就是它用於應用程序的音量。 – SeasonalShot

回答

3

setVolumeControlStream(AudioManager.STREAM_MUSIC);
在onCreate()方法。這會告訴操作系統,當您的應用程序可見時,音量按鈕應該會影響「媒體」音量,這就是它用於應用程序的音量。 記住你的應用程序需要關注。

+0

解決了這個問題thanx –

+1

歡迎您 – SeasonalShot