Exemplo n.º 1
0
  @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;
  }
Exemplo n.º 2
0
  @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);
    }
  }