我已经创建了一个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();
}
}
setVolumeControlStream(AudioManager.STREAM_MUSIC);
在您的onCreate()方法中。这会告诉操作系统,当您的应用程序可见时,音量按钮应该会影响“媒体”音量,这就是它用于应用程序的音量。 – SeasonalShot