Code example for Ringtone

Methods: play, setStreamType

0
        try { 
            if (mRingerPlayer != null) {
                mRingerPlayer.stop();
            } 
            mRingerPlayer = RingtoneManager.getRingtone(mContext, uri);
            mRingerPlayer.setStreamType(streamType);
            mRingerPlayer.play();
        } catch (Exception e) {
            Log.e(TAG, "error ringing", e);
        } 
    } 
 
    private synchronized void ringOutgoing(Uri uri) {
        int streamType = AudioManager.STREAM_VOICE_CALL;
        ring(uri, streamType);
    } 
 
    /* 
     * private synchronized void playNotification() { Uri notification = 
     * RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     * ringOutgoing(notification); }