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(); } } }
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); } }
private void notifyPlaylistHasChanged() { if (mSongSelector.getCurrentSong() != null) { Intent intent = new Intent(BROADCAST_PLAYLIST_CHANGED); LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent); } }
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(); } }
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(); } }
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(); } }
public void addSong(long idSong, AddMode enqueue) { if (idSong != PlayerService.INVALID_ID_OR_POSITION) mSongSelector.addSong(idSong, enqueue); }
public void addAlbum(long idAlbum, AddMode enqueue) { if (idAlbum != PlayerService.INVALID_ID_OR_POSITION) mSongSelector.addAlbum(idAlbum, enqueue); }
public void addArtist(long idArtist, AddMode enqueue) { if (idArtist != PlayerService.INVALID_ID_OR_POSITION) mSongSelector.addArtist(idArtist, enqueue); }
public void addGenre(long idGenre, AddMode enqueue) { if (idGenre != PlayerService.INVALID_ID_OR_POSITION) mSongSelector.addGenre(idGenre, enqueue); }
public Song getNextSong() { if (mSongSelector != null) return mSongSelector.getNextSong(); return null; }
public Song getSongAtPosition(int position) { if (mSongSelector != null) return mSongSelector.getSongAtPosition(position); return null; }
public int getCurrentPosition() { return mSongSelector.getCurrentPosition(); }
public Song getPreviousSong() { if (mSongSelector != null) return mSongSelector.getPreviousSong(); return null; }
public void toggleSelectionMode() { mSongSelector.toggleSelectionMode(); }
public void addPlaylist(Playlist playlist, AddMode enqueue) { mSongSelector.addPlaylist(playlist, enqueue); }
/* OnSeekCompleteListener implementation section */ @Override public void onSeekComplete(MediaPlayer mp) { Log.d(TAG, "Song " + mSongSelector.getCurrentSong().title + " modified"); mIsModified = true; }
public void setCurrentTime(int position) { if (mSongSelector.getCurrentSong() != null) mPlayer.seekTo(position); }
public int getCurrentTime() { if (mSongSelector.getCurrentSong() != null) return mPlayer.getCurrentPosition(); else return 0; }
public void setCurrentPosition(int position) { mSongSelector.setCurrentPosition(position); }
public void addBatchSongs(List<Song> songs, AddMode enqueue) { mSongSelector.addBatchSongs(songs, enqueue); }
private void stop() { mSongSelector.clearPlaylist(); mPlayer.stop(); playerState = PlayerState.STOPPED; }
public void togglePlayMode() { mSongSelector.togglePlayMode(); }
public List<Song> getCurrentPlaylist() { return mSongSelector.getCurrentPlaylist(); }