Code example for MediaPlayer

Methods: isPlayingsetDataSourcesetLoopingsetOnErrorListener

0
 
    if (player != null && ringerMode == AudioManager.RINGER_MODE_NORMAL ) {
      audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
      audioManager.setMode(AudioManager.MODE_RINGTONE);
      try { 
        if(!player.isPlaying()) {
          player.prepare();
          player.start();
          Log.d(TAG, "Playing ringtone now...");
        } else { 
          Log.d(TAG, "Ringtone is already playing, declining to restart.");
        } 
      } catch (IllegalStateException e) {
        Log.w(TAG, e);
        player = null;
      } catch (IOException e) {
        Log.w(TAG, e);
        player = null;
      } 
    } else { 
      Log.d(TAG, " mode: " + ringerMode);