播放ringtone/alarm 声音

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(); 
 
}

 

你会发现 播放默认铃声

出现ERROR/MediaPlayerService(30): Couldn't open fd for content://settings/system/ringtone

我找了好久没找到答案   后来换了一个铃声可以了

 

后来有人测试真机上是可以的,或许模拟机上没有那个content://settings/system/ringtone

你可能感兴趣的:(ARM)