Ejemplo n.º 1
0
  @Override
  public void onReceive(Context context, Intent intent) {

    String action = intent.getAction();
    layout = new RemoteViews(context.getPackageName(), R.layout.notification);

    IBinder binder = peekService(context, new Intent(context, PlayerService.class));
    if (binder == null) return;
    PlayerService playerService = ((PlayerService.PlayerBinder) binder).getService();

    if (action.equals(nextAction)) {
      playerService.playNext();
      return;
    }

    if (action.equals(clearAction)) {
      playerService.halt();
      return;
    }

    if (action.equals(toggleAction)) {

      SoundWavesPlayer player = playerService.getPlayer();
      if (!player.isInitialized()) {
        return;
      }

      Boolean isPlaying = false;
      if (playerService.isPlaying()) {
        playerService.pause();
      } else {
        playerService.start();
        isPlaying = true;
      }

      IEpisode currentItem = playerService.getCurrentItem();
      if (currentItem != null) {
        np = new NotificationPlayer(playerService, playerService.getCurrentItem());
        np.setmPlayerService(playerService);
        np.show(isPlaying);
      }
    }
  }