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

Code changes to enable player thumbnail seekbar preview in NewPipe #647

Merged
merged 8 commits into from
Jul 17, 2021
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 @@ -1049,7 +1049,16 @@ public List<Frameset> getFrames() throws ExtractionException {
storyboardsRenderer = storyboards.getObject("playerStoryboardSpecRenderer");
}

final String[] spec = storyboardsRenderer.getString("spec").split("\\|");
if (storyboardsRenderer == null) {
return Collections.emptyList();
}

final String storyboardsRendererSpec = storyboardsRenderer.getString("spec");
if (storyboardsRendererSpec == null) {
return Collections.emptyList();
}

final String[] spec = storyboardsRendererSpec.split("\\|");
final String url = spec[0];
final ArrayList<Frameset> result = new ArrayList<>(spec.length - 1);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package org.schabi.newpipe.extractor.stream;

import java.io.Serializable;
import java.util.List;

public final class Frameset {

private List<String> urls;
private int frameWidth;
private int frameHeight;
private int totalCount;
private int durationPerFrame;
private int framesPerPageX;
private int framesPerPageY;

public Frameset(List<String> urls, int frameWidth, int frameHeight, int totalCount, int durationPerFrame, int framesPerPageX, int framesPerPageY) {
public final class Frameset implements Serializable {

private final List<String> urls;
private final int frameWidth;
private final int frameHeight;
private final int totalCount;
private final int durationPerFrame;
private final int framesPerPageX;
private final int framesPerPageY;

public Frameset(
final List<String> urls,
final int frameWidth,
final int frameHeight,
final int totalCount,
final int durationPerFrame,
final int framesPerPageX,
final int framesPerPageY) {

this.urls = urls;
this.totalCount = totalCount;
this.durationPerFrame = durationPerFrame;
Expand Down Expand Up @@ -86,7 +95,7 @@ public int getDurationPerFrame() {
* <li><code>4</code>: Bottom bound</li>
* </ul>
*/
public int[] getFrameBoundsAt(long position) {
public int[] getFrameBoundsAt(final long position) {
if (position < 0 || position > ((totalCount + 1) * durationPerFrame)) {
// Return the first frame as fallback
return new int[] { 0, 0, 0, frameWidth, frameHeight };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ private static StreamInfo extractOptionalData(StreamInfo streamInfo, StreamExtra
streamInfo.addError(e);
}

try {
streamInfo.setPreviewFrames(extractor.getFrames());
} catch (Exception e) {
streamInfo.addError(e);
}

streamInfo.setRelatedItems(ExtractorHelper.getRelatedItemsOrLogError(streamInfo, extractor));

return streamInfo;
Expand Down Expand Up @@ -386,6 +392,11 @@ private static StreamInfo extractOptionalData(StreamInfo streamInfo, StreamExtra
private List<StreamSegment> streamSegments = new ArrayList<>();
private List<MetaInfo> metaInfo = new ArrayList<>();

/**
* Preview frames, e.g. for the storyboard / seekbar thumbnail preview
*/
private List<Frameset> previewFrames = Collections.emptyList();

/**
* Get the stream type
*
Expand Down Expand Up @@ -711,6 +722,14 @@ public void setMetaInfo(final List<MetaInfo> metaInfo) {
this.metaInfo = metaInfo;
}

public List<Frameset> getPreviewFrames() {
return previewFrames;
}

public void setPreviewFrames(final List<Frameset> previewFrames) {
this.previewFrames = previewFrames;
}

@Nonnull
public List<MetaInfo> getMetaInfo() {
return this.metaInfo;
Expand Down