我一直在寻找如何在Android中播放铃声/闹钟声的方法。
我按下一个按钮,想要播放一个铃声/闹钟声。我找不到一个简单、直接的示例。是的,我已经查看了闹钟源代码……但它并不直观,而且我无法编译它。
我无法让这个工作:
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();
}
我得到了这个错误:
04-11 17:15:27.638: ERROR/MediaPlayerService(30): Couldn't open fd for
content://settings/system/ringtone
所以...如果有人知道如何播放默认的铃声/闹钟,请告诉我。
我更喜欢不上传任何文件。只需播放默认的铃声即可。
Ringtone
实例,例如作为类变量。然后稍后可以执行myRingtone.stop()
之类的操作。 - wildcat12