@Override
 public synchronized void seekTo(int position) {
   try {
     if (jukeboxEnabled) {
       jukeboxService.skip(getCurrentPlayingIndex(), position / 1000);
     } else {
       mediaPlayer.seekTo(position);
     }
   } catch (Exception x) {
     handleError(x);
   }
 }
  @Override
  public void setJukeboxEnabled(boolean jukeboxEnabled) {
    this.jukeboxEnabled = jukeboxEnabled;
    jukeboxService.setEnabled(jukeboxEnabled);
    if (jukeboxEnabled) {
      reset();

      // Cancel current download, if necessary.
      if (currentDownloading != null) {
        currentDownloading.cancelDownload();
      }
    }
  }
 @Override
 public synchronized void start() {
   try {
     if (jukeboxEnabled) {
       jukeboxService.start();
     } else {
       mediaPlayer.start();
     }
     setPlayerState(STARTED);
   } catch (Exception x) {
     handleError(x);
   }
 }
 @Override
 public synchronized void pause() {
   try {
     if (playerState == STARTED) {
       if (jukeboxEnabled) {
         jukeboxService.stop();
       } else {
         mediaPlayer.pause();
       }
       setPlayerState(PAUSED);
     }
   } catch (Exception x) {
     handleError(x);
   }
 }
 @Override
 public synchronized int getPlayerPosition() {
   try {
     if (playerState == IDLE || playerState == DOWNLOADING || playerState == PREPARING) {
       return 0;
     }
     if (jukeboxEnabled) {
       return jukeboxService.getPositionSeconds() * 1000;
     } else {
       return mediaPlayer.getCurrentPosition();
     }
   } catch (Exception x) {
     handleError(x);
     return 0;
   }
 }
 private synchronized void play(int index, boolean start) {
   if (index < 0 || index >= size()) {
     reset();
     setCurrentPlaying(null);
   } else {
     setCurrentPlaying(index);
     checkDownloads();
     if (start) {
       if (jukeboxEnabled) {
         jukeboxService.skip(getCurrentPlayingIndex(), 0);
         setPlayerState(STARTED);
       } else {
         bufferAndPlay();
       }
     }
   }
 }
 @Override
 public void adjustJukeboxVolume(boolean up) {
   jukeboxService.adjustVolume(up);
 }
 private void updateJukeboxPlaylist() {
   if (jukeboxEnabled) {
     jukeboxService.updatePlaylist();
   }
 }