Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix NextUp not working without clearing old video queue items #1951

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public int getCurrentMediaPosition() {
}

public void setCurrentVideoQueue(List<BaseItemDto> items) {
if (items == null) {
if (items == null || items.size() < 1) {
clearVideoQueue();
return;
}
Expand Down Expand Up @@ -986,7 +986,9 @@ public void resumeAudio() {
}

public void setCurrentMediaPosition(int currentMediaPosition) {
this.mCurrentMediaPosition = currentMediaPosition;
if (!hasVideoQueueItems() || currentMediaPosition < 0 || currentMediaPosition > getCurrentVideoQueue().size())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks the old and new photo viewers (app crashes when trying to view a photo)

return;
mCurrentMediaPosition = currentMediaPosition;
}

public BaseRowItem getMediaItem(int pos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,6 @@ public void stop() {
public void endPlayback(Boolean closeActivity) {
if (closeActivity) mFragment.getActivity().finish();
stop();
removePreviousQueueItems();
if (mVideoManager != null)
mVideoManager.destroy();
mFragment = null;
Expand Down Expand Up @@ -1157,6 +1156,7 @@ public void next() {
stop();
resetPlayerErrors();
mCurrentIndex++;
mediaManager.getValue().setCurrentMediaPosition(mCurrentIndex);
Timber.d("Moving to index: %d out of %d total items.", mCurrentIndex, mItems.size());
spinnerOff = false;
play(0);
Expand All @@ -1169,6 +1169,7 @@ public void prev() {
stop();
resetPlayerErrors();
mCurrentIndex--;
mediaManager.getValue().setCurrentMediaPosition(mCurrentIndex);
Timber.d("Moving to index: %d out of %d total items.", mCurrentIndex, mItems.size());
spinnerOff = false;
play(0);
Expand Down Expand Up @@ -1394,56 +1395,29 @@ public void run() {
});
}

public void removePreviousQueueItems() {
DataRefreshService dataRefreshService = KoinJavaComponent.<DataRefreshService>get(DataRefreshService.class);
dataRefreshService.setLastVideoQueueChange(System.currentTimeMillis());
if (isLiveTv || !mediaManager.getValue().isVideoQueueModified()) {
mediaManager.getValue().clearVideoQueue();
return;
}

if (mCurrentIndex < 0) return;

// removing from mItems doesn't work properly when using remote control - modify via mediaManager instead
for (int i = 0; i < mCurrentIndex && i < mediaManager.getValue().getCurrentVideoQueue().size(); i++) {
mediaManager.getValue().getCurrentVideoQueue().remove(0);
}

//Now - look at last item played and, if beyond default resume point, remove it too
Long duration = mCurrentStreamInfo != null ? mCurrentStreamInfo.getRunTimeTicks() : null;
if (duration != null && mediaManager.getValue().getCurrentVideoQueue().size() > 0) {
if (duration < 300000 || mCurrentPosition * 10000 > Math.floor(.90 * duration))
mediaManager.getValue().getCurrentVideoQueue().remove(0);
} else if (duration == null) mediaManager.getValue().getCurrentVideoQueue().remove(0);
setItems(mediaManager.getValue().getCurrentVideoQueue());
}

private void itemComplete() {
stop();
resetPlayerErrors();

BaseItemDto nextItem = getNextItem();
if (nextItem != null) {
Timber.d("Moving to next queue item. Index: %s", (mCurrentIndex + 1));

BaseItemDto curItem = getCurrentlyPlayingItem();

if (userPreferences.getValue().get(UserPreferences.Companion.getNextUpBehavior()) != NextUpBehavior.DISABLED
&& (curItem == null || curItem.getBaseItemType() != BaseItemType.Trailer)) {
// Show "Next Up" fragment
spinnerOff = false;
mediaManager.getValue().setCurrentVideoQueue(mItems);
mediaManager.getValue().setVideoQueueModified(true);
if (mFragment != null) mFragment.showNextUp(nextItem.getId());
endPlayback();
} else {
mCurrentIndex++;
play(0);
}
BaseItemDto curItem = getCurrentlyPlayingItem();
if (nextItem == null || curItem == null) {
endPlayback(true);
return;
}

Timber.d("Moving to next queue item. Index: %s", (mCurrentIndex + 1));
if (userPreferences.getValue().get(UserPreferences.Companion.getNextUpBehavior()) != NextUpBehavior.DISABLED
&& curItem.getBaseItemType() != BaseItemType.Trailer) {
mCurrentIndex++;
mediaManager.getValue().setCurrentMediaPosition(mCurrentIndex);
spinnerOff = false;

// Show "Next Up" fragment
if (mFragment != null) mFragment.showNextUp(nextItem.getId());
endPlayback();
} else {
// exit activity
Timber.d("Last item completed. Finishing activity.");
if (mFragment != null) mFragment.finish();
next();
}
}

Expand Down