Skip to content

Commit ada67d1

Browse files
authored
Merge pull request #647 from litetex/playerSeekbarPreview
Code changes to enable player thumbnail seekbar preview in NewPipe
2 parents c38a06e + 0c12b39 commit ada67d1

3 files changed

Lines changed: 50 additions & 13 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,16 @@ public List<Frameset> getFrames() throws ExtractionException {
10491049
storyboardsRenderer = storyboards.getObject("playerStoryboardSpecRenderer");
10501050
}
10511051

1052-
final String[] spec = storyboardsRenderer.getString("spec").split("\\|");
1052+
if (storyboardsRenderer == null) {
1053+
return Collections.emptyList();
1054+
}
1055+
1056+
final String storyboardsRendererSpec = storyboardsRenderer.getString("spec");
1057+
if (storyboardsRendererSpec == null) {
1058+
return Collections.emptyList();
1059+
}
1060+
1061+
final String[] spec = storyboardsRendererSpec.split("\\|");
10531062
final String url = spec[0];
10541063
final ArrayList<Frameset> result = new ArrayList<>(spec.length - 1);
10551064

extractor/src/main/java/org/schabi/newpipe/extractor/stream/Frameset.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
package org.schabi.newpipe.extractor.stream;
22

3+
import java.io.Serializable;
34
import java.util.List;
45

5-
public final class Frameset {
6-
7-
private List<String> urls;
8-
private int frameWidth;
9-
private int frameHeight;
10-
private int totalCount;
11-
private int durationPerFrame;
12-
private int framesPerPageX;
13-
private int framesPerPageY;
14-
15-
public Frameset(List<String> urls, int frameWidth, int frameHeight, int totalCount, int durationPerFrame, int framesPerPageX, int framesPerPageY) {
6+
public final class Frameset implements Serializable {
7+
8+
private final List<String> urls;
9+
private final int frameWidth;
10+
private final int frameHeight;
11+
private final int totalCount;
12+
private final int durationPerFrame;
13+
private final int framesPerPageX;
14+
private final int framesPerPageY;
15+
16+
public Frameset(
17+
final List<String> urls,
18+
final int frameWidth,
19+
final int frameHeight,
20+
final int totalCount,
21+
final int durationPerFrame,
22+
final int framesPerPageX,
23+
final int framesPerPageY) {
24+
1625
this.urls = urls;
1726
this.totalCount = totalCount;
1827
this.durationPerFrame = durationPerFrame;
@@ -86,7 +95,7 @@ public int getDurationPerFrame() {
8695
* <li><code>4</code>: Bottom bound</li>
8796
* </ul>
8897
*/
89-
public int[] getFrameBoundsAt(long position) {
98+
public int[] getFrameBoundsAt(final long position) {
9099
if (position < 0 || position > ((totalCount + 1) * durationPerFrame)) {
91100
// Return the first frame as fallback
92101
return new int[] { 0, 0, 0, frameWidth, frameHeight };

extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ private static StreamInfo extractOptionalData(StreamInfo streamInfo, StreamExtra
335335
streamInfo.addError(e);
336336
}
337337

338+
try {
339+
streamInfo.setPreviewFrames(extractor.getFrames());
340+
} catch (Exception e) {
341+
streamInfo.addError(e);
342+
}
343+
338344
streamInfo.setRelatedItems(ExtractorHelper.getRelatedItemsOrLogError(streamInfo, extractor));
339345

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

395+
/**
396+
* Preview frames, e.g. for the storyboard / seekbar thumbnail preview
397+
*/
398+
private List<Frameset> previewFrames = Collections.emptyList();
399+
389400
/**
390401
* Get the stream type
391402
*
@@ -711,6 +722,14 @@ public void setMetaInfo(final List<MetaInfo> metaInfo) {
711722
this.metaInfo = metaInfo;
712723
}
713724

725+
public List<Frameset> getPreviewFrames() {
726+
return previewFrames;
727+
}
728+
729+
public void setPreviewFrames(final List<Frameset> previewFrames) {
730+
this.previewFrames = previewFrames;
731+
}
732+
714733
@Nonnull
715734
public List<MetaInfo> getMetaInfo() {
716735
return this.metaInfo;

0 commit comments

Comments
 (0)