Пример #1
0
  // Play file
  public void play(int pos) {
    if (tracks == null) return;
    startUpdateProgress();

    this.position = pos;

    // Play File
    String path = "";
    if (tracks != null && tracks.size() > position) {
      currentTrack = tracks.get(position);
      path = currentTrack.getPath();
    }
    if (path.equals("")) {
      onPlayError("empty");
      return;
    }

    BASS.BASS_StreamFree(chan);
    if ((chan = BASS.BASS_StreamCreateFile(path, 0, 0, 0)) == 0) {
      onPlayError(path);

      // Stop Foreground
      stopForeground(true);

      return;
    }
    // Play File
    int result = BASS.BASS_ChannelSetSync(chan, BASS.BASS_SYNC_END, 0, EndSync, 0);
    // ByteBuffer byteBuffer = (ByteBuffer)BASS.BASS_ChannelGetTags(chan, BASS.BASS_TAG_ID3V2);

    BASS.BASS_ChannelPlay(chan, false);

    // Update Properties
    this.duration =
        BASS.BASS_ChannelBytes2Seconds(chan, BASS.BASS_ChannelGetLength(chan, BASS.BASS_POS_BYTE));
    this.progress = 0.0;

    // Notify Activity
    if (activity != null) {
      activity.onFileLoaded(
          currentTrack,
          this.duration,
          currentTrack.getArtist(),
          currentTrack.getTitle(),
          position,
          currentTrack.getAlbumId());
      activity.onProgressChanged(progress);
      activity.onUpdatePlayPause();
    }

    // Start foreground
    fireNotification();

    // Remote control
    if (Build.VERSION.SDK_INT >= 14 && remoteControlClient != null) {
      updateRemoteControl();
    }
  }
Пример #2
0
 public void playFromPause() {
   BASS.BASS_ChannelPlay(chan, false);
   startUpdateProgress();
   // Notify activity
   if (activity != null) {
     activity.onUpdatePlayPause();
   }
   if (remoteControlClient != null) {
     updateRemoteControlState(RemoteControlClient.PLAYSTATE_PLAYING);
   }
   fireNotification();
 }