Skip to content

Commit

Permalink
Merge pull request #647 from litetex/playerSeekbarPreview
Browse files Browse the repository at this point in the history
Code changes to enable player thumbnail seekbar preview in NewPipe
  • Loading branch information
TobiGr authored Jul 17, 2021
2 parents c38a06e + 0c12b39 commit ada67d1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
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

0 comments on commit ada67d1

Please sign in to comment.