我尝试使用铃声(不是媒体,闹钟或通知)来运行文件mp3,但它无法正常工作。我的代码:
AudioManager mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
mAudioManager.setStreamVolume(
AudioManager.STREAM_RING,
mAudioManager.getStreamMaxVolume(AudioManager.STREAM_RING),
AudioManager.FLAG_PLAY_SOUND);
mAudioManager.setSpeakerphoneOn(true);
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(this, Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.nhaccho));
} catch (IOException e) {
e.printStackTrace();
}
mp.setAudioStreamType(AudioManager.STREAM_RING);
mp.setLooping(true);
try {
mp.prepare();
} catch (IOException e) {
e.printStackTrace();
}
mp.start();
请帮忙。谢谢!