@Override public void onUpdate() { Song nowPlaying = PlayerController.getNowPlaying(); if (nowPlaying != null) { songTitle.setText(nowPlaying.getSongName()); songArtist.setText(nowPlaying.getArtistName()); songAlbum.setText(nowPlaying.getAlbumName()); int duration = PlayerController.getDuration(); timeDuration.setTime(duration); seekBar.setMax(duration); if (!observer.isRunning()) { observerThread = new Thread(observer); observerThread.start(); } } else { songTitle.setText(R.string.nothing_playing); songArtist.setText(R.string.unknown_artist); songAlbum.setText(R.string.unknown_album); } seekBar.setEnabled(nowPlaying != null); if (PlayerController.isPlaying()) { playPauseButton.setImageResource(R.drawable.ic_pause_36dp); } else { playPauseButton.setImageResource(R.drawable.ic_play_arrow_36dp); } }
@Override public void onPause() { super.onPause(); PlayerController.unregisterUpdateListener(this); observer.stop(); observerThread = null; }
@Override public boolean onMenuItemClick(MenuItem item) { final Song nowPlaying = PlayerController.getNowPlaying(); if (nowPlaying == null) { return false; } switch (item.getItemId()) { case 0: // Go to artist Artist artist = Library.findArtistById(nowPlaying.getArtistId()); Navigate.to(getContext(), ArtistActivity.class, ArtistActivity.ARTIST_EXTRA, artist); return true; case 1: // Go to album Album album = Library.findAlbumById(nowPlaying.getAlbumId()); Navigate.to(getContext(), AlbumActivity.class, AlbumActivity.ALBUM_EXTRA, album); return true; case 2: // Add to playlist PlaylistDialog.AddToNormal.alert( getView(), nowPlaying, getString(R.string.header_add_song_name_to_playlist, nowPlaying.getSongName())); return true; } return false; }
@Override public void onUpdate() { final boolean wasRunning = run; run = PlayerController.isPlaying(); if (!wasRunning && run) { parent.observerThread.run(); } }
@Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case 0: // Queue this genre next PlayerController.queueNext(Library.getGenreEntries(reference)); return true; case 1: // Queue this genre last PlayerController.queueLast(Library.getGenreEntries(reference)); return true; case 2: // Add to playlist PlaylistDialog.AddToNormal.alert( itemView, Library.getGenreEntries(reference), itemView.getContext().getString(R.string.header_add_song_name_to_playlist, reference)); return true; } return false; }
@Override public void onClick(View v) { if (v == playPauseButton) { PlayerController.togglePlay(); } else if (v == skipPrevButton) { PlayerController.previous(); } else if (v == skipNextButton) { PlayerController.skip(); } else if (v == moreInfoButton) { // Song info final Song nowPlaying = PlayerController.getNowPlaying(); if (nowPlaying != null) { final PopupMenu menu = new PopupMenu(getContext(), v, Gravity.END); String[] options = getResources().getStringArray(R.array.now_playing_options); for (int i = 0; i < options.length; i++) { menu.getMenu().add(Menu.NONE, i, i, options[i]); } menu.setOnMenuItemClickListener(this); menu.show(); } } }
@Override public void onResume() { super.onResume(); PlayerController.registerUpdateListener(this); onUpdate(); }
@Override public void onStopTrackingTouch(SeekBar seekBar) { PlayerController.seek(seekBar.getProgress()); userTouchingProgressBar = false; hideSeekThumb(); }