获取系统铃声选择表并播放选择的

来源:互联网 发布:校园打铃软件 编辑:程序博客网 时间:2024/05/14 21:54

获取默认铃声:

    Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);

@Override

public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);//声音类型 
startActivityForResult(intent, RESULTCODE_CHOOSE_RING);
}
return true;


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
         super.onActivityResult(requestCode, resultCode, data);
        
         if(requestCode==RESULTCODE_CHOOSE_RING && resultCode==RESULT_OK)
         {
        NotifyManager.voice_path = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); 
voicePath.setText(getFileName(getRealPathFromURI(NotifyManager.voice_path)));

NotifyManager.playNotifyRing(getApplicationContext()); 
         }
}


public static void playNotifyRing(Context context){

if(message_switch && voice_switch)
{
try{
mMediaPlayer.setDataSource(context, NotifyManager.voice_path);
final AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
mMediaPlayer.setLooping(false);
mMediaPlayer.prepare();
}
}catch (IllegalStateException e) {
e.printStackTrace(); 
} catch (IOException e) { 
e.printStackTrace(); 
}
mMediaPlayer.start();
}
}

0 0
原创粉丝点击