Example #1
0
  private void setSong() {
    if (mSongSelector.getCurrentSong() != null) {
      if (mPlayer == null) {
        createPlayer();
        mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      }
      mPlayer.reset();

      try {
        mPlayer.setDataSource(getApplicationContext(), mSongSelector.getCurrentSong().getUri());
      } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
Example #2
0
  private void sendLocalBroadcast() {
    if (mSongSelector.getCurrentSong() != null) {
      Intent intent = new Intent(BROADCAST_PLAY_FILTER);

      intent.putExtra(EXTRA_CURRENT_SONG, mSongSelector.getCurrentSong());
      intent.putExtra(EXTRA_SONG_NUMBER, mSongSelector.getCurrentPosition());
      intent.putExtra(EXTRA_PLAYER_STATE, (Parcelable) playerState);

      LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);
    }
  }
Example #3
0
  private void notifyPlaylistHasChanged() {
    if (mSongSelector.getCurrentSong() != null) {
      Intent intent = new Intent(BROADCAST_PLAYLIST_CHANGED);

      LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);
    }
  }
Example #4
0
 private void forward() {
   try {
     mIsModified = false;
     if (mSongSelector.forward()) {
       setSong();
       mPlayer.prepareAsync();
     }
   } catch (IllegalStateException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Example #5
0
 private void rewind() {
   try {
     if (mPlayer.getCurrentPosition() > REWIND_SPAN) {
       mPlayer.seekTo(0);
     } else {
       mIsModified = false;
       mSongSelector.rewind();
       setSong();
       mPlayer.prepareAsync();
     }
   } catch (IllegalStateException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Example #6
0
  private void play() {
    try {
      if (mSongSelector == null) mSongSelector = new SongSelector(getContentResolver(), this);

      if (getCurrentPlaylist().size() == 0) {
        mSongSelector.playAll();
      } else {
        if (playerState == PlayerState.PAUSED) {
          playerState = PlayerState.PLAYING;
          mPlayer.start();
          setForeground();
        } else if (playerState == PlayerState.STOPPED) {
          forward();
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Example #7
0
 public void addSong(long idSong, AddMode enqueue) {
   if (idSong != PlayerService.INVALID_ID_OR_POSITION) mSongSelector.addSong(idSong, enqueue);
 }
Example #8
0
 public void addAlbum(long idAlbum, AddMode enqueue) {
   if (idAlbum != PlayerService.INVALID_ID_OR_POSITION) mSongSelector.addAlbum(idAlbum, enqueue);
 }
Example #9
0
 public void addArtist(long idArtist, AddMode enqueue) {
   if (idArtist != PlayerService.INVALID_ID_OR_POSITION)
     mSongSelector.addArtist(idArtist, enqueue);
 }
Example #10
0
 public void addGenre(long idGenre, AddMode enqueue) {
   if (idGenre != PlayerService.INVALID_ID_OR_POSITION) mSongSelector.addGenre(idGenre, enqueue);
 }
Example #11
0
  public Song getNextSong() {
    if (mSongSelector != null) return mSongSelector.getNextSong();

    return null;
  }
Example #12
0
  public Song getSongAtPosition(int position) {
    if (mSongSelector != null) return mSongSelector.getSongAtPosition(position);

    return null;
  }
Example #13
0
 public int getCurrentPosition() {
   return mSongSelector.getCurrentPosition();
 }
Example #14
0
  public Song getPreviousSong() {
    if (mSongSelector != null) return mSongSelector.getPreviousSong();

    return null;
  }
Example #15
0
 public void toggleSelectionMode() {
   mSongSelector.toggleSelectionMode();
 }
Example #16
0
 public void addPlaylist(Playlist playlist, AddMode enqueue) {
   mSongSelector.addPlaylist(playlist, enqueue);
 }
Example #17
0
  /* OnSeekCompleteListener implementation section */
  @Override
  public void onSeekComplete(MediaPlayer mp) {
    Log.d(TAG, "Song " + mSongSelector.getCurrentSong().title + " modified");

    mIsModified = true;
  }
Example #18
0
 public void setCurrentTime(int position) {
   if (mSongSelector.getCurrentSong() != null) mPlayer.seekTo(position);
 }
Example #19
0
 public int getCurrentTime() {
   if (mSongSelector.getCurrentSong() != null) return mPlayer.getCurrentPosition();
   else return 0;
 }
Example #20
0
 public void setCurrentPosition(int position) {
   mSongSelector.setCurrentPosition(position);
 }
Example #21
0
 public void addBatchSongs(List<Song> songs, AddMode enqueue) {
   mSongSelector.addBatchSongs(songs, enqueue);
 }
Example #22
0
  private void stop() {
    mSongSelector.clearPlaylist();
    mPlayer.stop();

    playerState = PlayerState.STOPPED;
  }
Example #23
0
 public void togglePlayMode() {
   mSongSelector.togglePlayMode();
 }
Example #24
0
 public List<Song> getCurrentPlaylist() {
   return mSongSelector.getCurrentPlaylist();
 }