Skip to content

Commit 4ba91d4

Browse files
committed
fix: player being destroyed when skipping track
1 parent ae6bcb1 commit 4ba91d4

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

app/src/main/java/io/compactd/player/service/MediaPlayerService.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ public void nextTrack () {
624624
}
625625

626626
public CompactdTrack getCurrentTrack() {
627+
627628
if (playlist.isEmpty()) return null;
628629
return playlist.get(position);
629630
}
@@ -740,10 +741,15 @@ public void onBufferingUpdate(MediaPlayer mediaPlayer, int i) {
740741
public void onCompletion(MediaPlayer mediaPlayer) {
741742
Log.d(TAG, "onCompletion: " + mediaPlayer);
742743
stopMedia();
743-
stopSelf();
744+
if (position >= playlist.size()) {
745+
stopSelf();
744746

745-
firePlayerDestroyed();
746-
playerReady = false;
747+
firePlayerDestroyed();
748+
playerReady = false;
749+
} else {
750+
position = position + 1;
751+
updatePlaylist();
752+
}
747753
}
748754

749755
@Override

app/src/main/java/io/compactd/player/ui/activities/SlidingMusicActivity.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.os.Handler;
77
import android.support.annotation.Nullable;
88
import android.support.v7.app.AppCompatActivity;
9+
import android.util.Log;
910
import android.view.View;
1011
import android.widget.FrameLayout;
1112
import android.widget.ImageView;
@@ -133,6 +134,7 @@ protected void onResume() {
133134
remote.addPlaybackListener(this);
134135

135136
if (remote.isPlaying()) {
137+
showPlayer();
136138
onMediaLoaded(remote.getCurrent());
137139
} else {
138140
hidePlayer();
@@ -145,11 +147,19 @@ protected void onDestroy() {
145147
}
146148

147149
void hidePlayer () {
150+
Log.d(TAG, "hidePlayer: ");
151+
new Throwable().printStackTrace();
152+
SlidingUpPanelLayout.PanelState state = panelLayout.getPanelState();
148153
panelLayout.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN);
149154
}
150155

151156
void showPlayer () {
152-
panelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
157+
Log.d(TAG, "showPlayer: ");
158+
new Throwable().printStackTrace();
159+
SlidingUpPanelLayout.PanelState state = panelLayout.getPanelState();
160+
if (state == SlidingUpPanelLayout.PanelState.HIDDEN) {
161+
panelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
162+
}
153163
}
154164

155165
@Override

0 commit comments

Comments
 (0)