本文介绍了如何在Android的播放铃声/报警声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在到处找如何在Android的播放铃声/报警声。

I have been looking everywhere how to play a ringtone/alarm sound in Android.

我preSS一个按钮,我想打一个铃声/报警声。我无法找到一个简单,直接的样本。是的,我已经看了看闹钟源$ C ​​$ C ...但它并不简单,我不能编译。

I press a button and I want to play a ringtone/alarm sound. I could not find an easy, straightforward sample. Yes, I already looked at Alarm clock source code... but it is not straightforward and I cannot compile it.

我无法使这项工作:

Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); 
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(this, alert);
final AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);

if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
    player.setAudioStreamType(AudioManager.STREAM_ALARM);
    player.setLooping(true);
    player.prepare();
    player.start();
}

我得到这个错误:

I get this error:

04-11 17:15:27.638: ERROR/MediaPlayerService(30): Couldn't open fd for
content://settings/system/ringtone

所以..请如果有人知道如何发挥默认铃声/报警让我知道。

So.. please if somebody knows how to play a default ringtone/alarm let me know.

我preFER不能上传任何文件。刚玩一个默认的铃声。

I prefer not to upload any file. Just play a default ringtone.

推荐答案

您可以简单地播放设置好的铃声与这样的:

You can simply play a setted ringtone with this:

Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();

这篇关于如何在Android的播放铃声/报警声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 07:54