Code example for MediaPlayer: Playing audio and video

Methods: preparestart

0
    public boolean ring(Context c) {
        boolean res = false;
        final AudioManager audioManager = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE);
        if (canRing && audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
            try { 
                mMediaPlayer.prepare();
            } catch (Exception e) {
                canRing = false;
            } 
            mMediaPlayer.start();
             
            res = true;
        } 
        return res;
    } 
 
    /** Stops the phone from ringing */ 
    public void stopRinging() { 
        if (canRing) {
            mMediaPlayer.stop();
        }