我想知道我怎么能起到通知声音,但不播放过的媒体流。现在,我可以通过媒体播放器做到这一点,但我不希望它作为一个媒体文件播放,我想它作为一个通知或报警,或铃声播放。继承人的一个例子就是我的code看起来像现在:
MediaPlayer的熔点为新的MediaPlayer();
mp.reset();
mp.setDataSource(notificationsPath +(字符串)apptSounds.getSelectedItem());
MP prepare()。
mp.start();
解决方案
如果有人仍然在寻找一个解决办法,我发现在的如何发挥铃声/报警声在Android中
尝试{
URI通知= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
铃声R = RingtoneManager.getRingtone(getApplicationContext(),通知);
r.play();
}赶上(例外五){
e.printStackTrace();
}
您可以更改TYPE_NOTIFICATION到TYPE_ALARM,但你要保持跟踪你的铃声为r的以停止播放它......就是说,当用户点击一个按钮什么的。
I was wondering how I could play a notification sound without playing it over the media stream. Right now I can do this via the media player, however I don't want it to play as a media file, I want it to play as a notification or alert or ringtone. heres an example of what my code looks like right now:
MediaPlayer mp = new MediaPlayer();
mp.reset();
mp.setDataSource(notificationsPath+ (String) apptSounds.getSelectedItem());
mp.prepare();
mp.start();
解决方案
If anyone's still looking for a solution to this, I found an answer at How to play ringtone/alarm sound in Android
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
You can change TYPE_NOTIFICATION to TYPE_ALARM, but you'll want to keep track of your Ringtone r in order to stop playing it... say, when the user clicks a button or something.