play Ringtone - Android Phone

Android examples for Phone:Sound

Description

play Ringtone

Demo Code


//package com.java2s;
import android.content.Context;
import android.media.MediaPlayer;

import android.media.RingtoneManager;
import android.net.Uri;

public class Main {
    private static MediaPlayer mediaPlayer = null;

    public static void playRingtone(Context context, int type) {
        mediaPlayer = MediaPlayer.create(context,
                getDefaultRingtoneUri(context, type));
        mediaPlayer.setLooping(true);/*w  ww .j a  v  a 2 s  .  c  o m*/
        mediaPlayer.start();
    }

    public static Uri getDefaultRingtoneUri(Context context, int type) {
        return RingtoneManager.getActualDefaultRingtoneUri(context, type);
    }
}

Related Tutorials