用户使用 RingtonePreference 选择铃声,我可以使用以下方法提取 Uri:
String pathString = mPreferences.getString(sKeySoundRingtone, null);
Uri pathUri;
if (pathString == null)
pathUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);;
else
pathUri = Uri.parse(pathString);
现在我想使用 SoundPool类,因为我只使用通知(持续时间通常在 5 秒以下)并且我喜欢它提供的循环和速率选项。
尽我所能但失败了,因为类可以用路径构造,而 pathUri.getPath() 不起作用。
有没有办法让它工作?
最佳答案
当您的通知被广播时,您将收到任何接收者的电话。届时您只需调用该函数即可播放音源池中的声音。
见下文:
public void Sound(){
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
float volume = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
android.util.Log.v("SOUND","["+volume+"]["+spool.play(soundID, volume, volume, 1, 0, 1f)+"]");
};
关于android - SoundPool 播放铃声通知的方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13251911/