seek on clicking timestamp links in comments
This commit is contained in:
parent
f9e771f8f7
commit
6421d3017e
4 changed files with 28 additions and 8 deletions
|
@ -45,7 +45,7 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder {
|
||||||
if(hours != null) timestamp += (Integer.parseInt(hours.replace(":", ""))*3600);
|
if(hours != null) timestamp += (Integer.parseInt(hours.replace(":", ""))*3600);
|
||||||
if(minutes != null) timestamp += (Integer.parseInt(minutes.replace(":", ""))*60);
|
if(minutes != null) timestamp += (Integer.parseInt(minutes.replace(":", ""))*60);
|
||||||
if(seconds != null) timestamp += (Integer.parseInt(seconds));
|
if(seconds != null) timestamp += (Integer.parseInt(seconds));
|
||||||
return streamUrl + url.replace(match.group(0), "&t=" + String.valueOf(timestamp));
|
return streamUrl + url.replace(match.group(0), "#timestamp=" + String.valueOf(timestamp));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -269,6 +269,18 @@ public abstract class BasePlayer implements
|
||||||
final boolean playbackSkipSilence = intent.getBooleanExtra(PLAYBACK_SKIP_SILENCE,
|
final boolean playbackSkipSilence = intent.getBooleanExtra(PLAYBACK_SKIP_SILENCE,
|
||||||
getPlaybackSkipSilence());
|
getPlaybackSkipSilence());
|
||||||
|
|
||||||
|
// seek to timestamp if stream is already playing
|
||||||
|
if (simpleExoPlayer != null
|
||||||
|
&& queue.size() == 1
|
||||||
|
&& playQueue != null
|
||||||
|
&& playQueue.getItem() != null
|
||||||
|
&& queue.getItem().getUrl().equals(playQueue.getItem().getUrl())
|
||||||
|
&& queue.getItem().getRecoveryPosition() != PlayQueueItem.RECOVERY_UNSET
|
||||||
|
) {
|
||||||
|
simpleExoPlayer.seekTo(playQueue.getIndex(), queue.getItem().getRecoveryPosition());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Good to go...
|
// Good to go...
|
||||||
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
|
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
|
||||||
/*playOnInit=*/true);
|
/*playOnInit=*/true);
|
||||||
|
|
|
@ -16,6 +16,11 @@ public final class SinglePlayQueue extends PlayQueue {
|
||||||
super(0, Collections.singletonList(new PlayQueueItem(info)));
|
super(0, Collections.singletonList(new PlayQueueItem(info)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SinglePlayQueue(final StreamInfo info, final long startPosition) {
|
||||||
|
super(0, Collections.singletonList(new PlayQueueItem(info)));
|
||||||
|
getItem().setRecoveryPosition(startPosition);
|
||||||
|
}
|
||||||
|
|
||||||
public SinglePlayQueue(final List<StreamInfoItem> items, final int index) {
|
public SinglePlayQueue(final List<StreamInfoItem> items, final int index) {
|
||||||
super(index, playQueueItemsOf(items));
|
super(index, playQueueItemsOf(items));
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
|
||||||
|
|
||||||
public static final CommentTextOnTouchListener INSTANCE = new CommentTextOnTouchListener();
|
public static final CommentTextOnTouchListener INSTANCE = new CommentTextOnTouchListener();
|
||||||
|
|
||||||
private static final Pattern timestampPattern = Pattern.compile(".*&t=(\\d+)");
|
private static final Pattern timestampPattern = Pattern.compile("(.*)#timestamp=(\\d+)");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
|
@ -86,6 +86,12 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
|
||||||
|
|
||||||
private boolean handleUrl(Context context, URLSpan urlSpan) {
|
private boolean handleUrl(Context context, URLSpan urlSpan) {
|
||||||
String url = urlSpan.getURL();
|
String url = urlSpan.getURL();
|
||||||
|
int seconds = -1;
|
||||||
|
Matcher matcher = timestampPattern.matcher(url);
|
||||||
|
if(matcher.matches()){
|
||||||
|
url = matcher.group(1);
|
||||||
|
seconds = Integer.parseInt(matcher.group(2));
|
||||||
|
}
|
||||||
StreamingService service;
|
StreamingService service;
|
||||||
StreamingService.LinkType linkType;
|
StreamingService.LinkType linkType;
|
||||||
try {
|
try {
|
||||||
|
@ -97,9 +103,7 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
|
||||||
if(linkType == StreamingService.LinkType.NONE){
|
if(linkType == StreamingService.LinkType.NONE){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Matcher matcher = timestampPattern.matcher(url);
|
if(linkType == StreamingService.LinkType.STREAM && seconds != -1){
|
||||||
if(linkType == StreamingService.LinkType.STREAM && matcher.matches()){
|
|
||||||
int seconds = Integer.parseInt(matcher.group(1));
|
|
||||||
return playOnPopup(context, url, service, seconds);
|
return playOnPopup(context, url, service, seconds);
|
||||||
}else{
|
}else{
|
||||||
NavigationHelper.openRouterActivity(context, url);
|
NavigationHelper.openRouterActivity(context, url);
|
||||||
|
@ -119,9 +123,8 @@ public class CommentTextOnTouchListener implements View.OnTouchListener {
|
||||||
single.subscribeOn(Schedulers.io())
|
single.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(info -> {
|
.subscribe(info -> {
|
||||||
PlayQueue playQueue = new SinglePlayQueue((StreamInfo) info);
|
PlayQueue playQueue = new SinglePlayQueue((StreamInfo) info, seconds*1000);
|
||||||
((StreamInfo) info).setStartPosition(seconds);
|
NavigationHelper.playOnPopupPlayer(context, playQueue);
|
||||||
NavigationHelper.enqueueOnPopupPlayer(context, playQueue, true);
|
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue