我已经尝试使用以下代码在我的应用程序中设置媒体播放器的音频流,但是当我这样做时,我在模拟器中听不到声音.如果我没有为播放器设置流,则音频播放正常.我确定我使用这个错误,但不能锻炼如何,任何帮助?
- MediaPlayer player = MediaPlayer.create(getApplicationContext(),R.raw.test_audio);
- AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUdio_SERVICE);
- audioManager.getStreamVolume(AudioManager.STREAM_ALARM);
- audioManager.setStreamVolume(AudioManager.STREAM_ALARM,audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM),AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
- player.setAudioStreamType(AudioManager.STREAM_ALARM);
- player.start();
注意:我已将MODIFY_AUdio_SETTINGS权限添加到我的清单.
谢谢!