-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Keep current player when clicking on timestamp #12254
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
Merged
+290
−204
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
35c7f2f
Player: Remove unused IS_MUTED intent key
Profpatsch 32eb3af
Player/handleIntent: a few comments
Profpatsch 90e1ac5
NavigationHelper: inline getPlayerEnqueueIntent
Profpatsch b592403
NavigationHelper: push out resumePlayback one layer
Profpatsch e14ec3a
NavigationHelper: inline trivial getPlayerIntent use
Profpatsch fd24c08
Player/handleIntent: de morgan samePlayQueue
Profpatsch ab7d137
Player/handleIntent: always early return on ENQUEUE an ENQUEUE_NEXT
Profpatsch 5750ef6
Player/handleIntent: start converting intent data to enum
Profpatsch 8fb3e90
Player: remove unused REPEAT_MODE intent key
Profpatsch d534946
Player: inline repeat mode cycling
Profpatsch 25a4a9a
Player/handleIntent: move prefs parameters into initPlayback
Profpatsch 3803d49
Player/handleIntent: separate out the timestamp request into enum
Profpatsch 150649a
Player/handleIntent: Don’t delete queue when clicking on timestamp
Profpatsch 01f9a3d
Fix Checkstyle & remove unused fields
Profpatsch d77771a
Player/handleIntent: fix enqueue if player not running
Profpatsch eb277fe
Player/handleIntent: call handleIntentPost unconditionally
Profpatsch 1723bf0
Player/handleIntent: keep current player when clicking timestamp
Profpatsch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
217 changes: 161 additions & 56 deletions
217
app/src/main/java/org/schabi/newpipe/player/Player.java
Large diffs are not rendered by default.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
app/src/main/java/org/schabi/newpipe/player/PlayerIntentType.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.schabi.newpipe.player | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
|
||
// We model this as an enum class plus one struct for each enum value | ||
// so we can consume it from Java properly. After converting to Kotlin, | ||
// we could switch to a sealed enum class & a proper Kotlin `when` match. | ||
|
||
@Parcelize | ||
enum class PlayerIntentType : Parcelable { | ||
Enqueue, | ||
EnqueueNext, | ||
TimestampChange, | ||
AllOthers | ||
} | ||
|
||
/** | ||
* A timestamp on the given was clicked and we should switch the playing stream to it. | ||
*/ | ||
@Parcelize | ||
data class TimestampChangeData( | ||
val serviceId: Int, | ||
val url: String, | ||
val seconds: Int | ||
) : Parcelable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -9,6 +9,7 @@ | |||||
import android.content.Intent; | ||||||
import android.net.Uri; | ||||||
import android.os.Build; | ||||||
import android.os.Parcelable; | ||||||
import android.util.Log; | ||||||
import android.widget.Toast; | ||||||
|
||||||
|
@@ -57,8 +58,10 @@ | |||||
import org.schabi.newpipe.local.subscription.SubscriptionsImportFragment; | ||||||
import org.schabi.newpipe.player.PlayQueueActivity; | ||||||
import org.schabi.newpipe.player.Player; | ||||||
import org.schabi.newpipe.player.PlayerIntentType; | ||||||
import org.schabi.newpipe.player.PlayerService; | ||||||
import org.schabi.newpipe.player.PlayerType; | ||||||
import org.schabi.newpipe.player.TimestampChangeData; | ||||||
import org.schabi.newpipe.player.helper.PlayerHelper; | ||||||
import org.schabi.newpipe.player.helper.PlayerHolder; | ||||||
import org.schabi.newpipe.player.playqueue.PlayQueue; | ||||||
|
@@ -85,7 +88,7 @@ private NavigationHelper() { | |||||
public static <T> Intent getPlayerIntent(@NonNull final Context context, | ||||||
@NonNull final Class<T> targetClazz, | ||||||
@Nullable final PlayQueue playQueue, | ||||||
final boolean resumePlayback) { | ||||||
@NonNull final PlayerIntentType playerIntentType) { | ||||||
final Intent intent = new Intent(context, targetClazz); | ||||||
|
||||||
if (playQueue != null) { | ||||||
|
@@ -95,44 +98,31 @@ public static <T> Intent getPlayerIntent(@NonNull final Context context, | |||||
} | ||||||
} | ||||||
intent.putExtra(Player.PLAYER_TYPE, PlayerType.MAIN.valueForIntent()); | ||||||
intent.putExtra(Player.RESUME_PLAYBACK, resumePlayback); | ||||||
intent.putExtra(PlayerService.SHOULD_START_FOREGROUND_EXTRA, true); | ||||||
intent.putExtra(Player.PLAYER_INTENT_TYPE, (Parcelable) playerIntentType); | ||||||
|
||||||
return intent; | ||||||
} | ||||||
|
||||||
@NonNull | ||||||
public static <T> Intent getPlayerIntent(@NonNull final Context context, | ||||||
@NonNull final Class<T> targetClazz, | ||||||
@Nullable final PlayQueue playQueue, | ||||||
final boolean resumePlayback, | ||||||
final boolean playWhenReady) { | ||||||
return getPlayerIntent(context, targetClazz, playQueue, resumePlayback) | ||||||
.putExtra(Player.PLAY_WHEN_READY, playWhenReady); | ||||||
} | ||||||
public static Intent getPlayerTimestampIntent(@NonNull final Context context, | ||||||
@NonNull final TimestampChangeData | ||||||
timestampChangeData) { | ||||||
final Intent intent = new Intent(context, PlayerService.class); | ||||||
|
||||||
@NonNull | ||||||
public static <T> Intent getPlayerEnqueueIntent(@NonNull final Context context, | ||||||
@NonNull final Class<T> targetClazz, | ||||||
@Nullable final PlayQueue playQueue) { | ||||||
// when enqueueing `resumePlayback` is always `false` since: | ||||||
// - if there is a video already playing, the value of `resumePlayback` just doesn't make | ||||||
// any difference. | ||||||
// - if there is nothing already playing, it is useful for the enqueue action to have a | ||||||
// slightly different behaviour than the normal play action: the latter resumes playback, | ||||||
// the former doesn't. (note that enqueue can be triggered when nothing is playing only | ||||||
// by long pressing the video detail fragment, playlist or channel controls | ||||||
return getPlayerIntent(context, targetClazz, playQueue, false) | ||||||
.putExtra(Player.ENQUEUE, true); | ||||||
intent.putExtra(Player.PLAYER_INTENT_TYPE, (Parcelable) PlayerIntentType.TimestampChange); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
intent.putExtra(Player.PLAYER_INTENT_DATA, timestampChangeData); | ||||||
|
||||||
return intent; | ||||||
} | ||||||
|
||||||
@NonNull | ||||||
public static <T> Intent getPlayerEnqueueNextIntent(@NonNull final Context context, | ||||||
@NonNull final Class<T> targetClazz, | ||||||
@Nullable final PlayQueue playQueue) { | ||||||
// see comment in `getPlayerEnqueueIntent` as to why `resumePlayback` is false | ||||||
return getPlayerIntent(context, targetClazz, playQueue, false) | ||||||
.putExtra(Player.ENQUEUE_NEXT, true); | ||||||
return getPlayerIntent(context, targetClazz, playQueue, PlayerIntentType.EnqueueNext) | ||||||
// see comment in `getPlayerEnqueueIntent` as to why `resumePlayback` is false | ||||||
.putExtra(Player.RESUME_PLAYBACK, false); | ||||||
} | ||||||
|
||||||
/* PLAY */ | ||||||
|
@@ -166,8 +156,10 @@ public static void playOnPopupPlayer(final Context context, | |||||
|
||||||
Toast.makeText(context, R.string.popup_playing_toast, Toast.LENGTH_SHORT).show(); | ||||||
|
||||||
final Intent intent = getPlayerIntent(context, PlayerService.class, queue, resumePlayback); | ||||||
intent.putExtra(Player.PLAYER_TYPE, PlayerType.POPUP.valueForIntent()); | ||||||
final Intent intent = getPlayerIntent(context, PlayerService.class, queue, | ||||||
PlayerIntentType.AllOthers); | ||||||
intent.putExtra(Player.PLAYER_TYPE, PlayerType.POPUP.valueForIntent()) | ||||||
.putExtra(Player.RESUME_PLAYBACK, resumePlayback); | ||||||
ContextCompat.startForegroundService(context, intent); | ||||||
} | ||||||
|
||||||
|
@@ -177,8 +169,10 @@ public static void playOnBackgroundPlayer(final Context context, | |||||
Toast.makeText(context, R.string.background_player_playing_toast, Toast.LENGTH_SHORT) | ||||||
.show(); | ||||||
|
||||||
final Intent intent = getPlayerIntent(context, PlayerService.class, queue, resumePlayback); | ||||||
final Intent intent = getPlayerIntent(context, PlayerService.class, queue, | ||||||
PlayerIntentType.AllOthers); | ||||||
intent.putExtra(Player.PLAYER_TYPE, PlayerType.AUDIO.valueForIntent()); | ||||||
intent.putExtra(Player.RESUME_PLAYBACK, resumePlayback); | ||||||
ContextCompat.startForegroundService(context, intent); | ||||||
} | ||||||
|
||||||
|
@@ -191,7 +185,17 @@ public static void enqueueOnPlayer(final Context context, | |||||
} | ||||||
|
||||||
Toast.makeText(context, R.string.enqueued, Toast.LENGTH_SHORT).show(); | ||||||
final Intent intent = getPlayerEnqueueIntent(context, PlayerService.class, queue); | ||||||
|
||||||
// when enqueueing `resumePlayback` is always `false` since: | ||||||
// - if there is a video already playing, the value of `resumePlayback` just doesn't make | ||||||
// any difference. | ||||||
// - if there is nothing already playing, it is useful for the enqueue action to have a | ||||||
// slightly different behaviour than the normal play action: the latter resumes playback, | ||||||
// the former doesn't. (note that enqueue can be triggered when nothing is playing only | ||||||
// by long pressing the video detail fragment, playlist or channel controls | ||||||
final Intent intent = getPlayerIntent(context, PlayerService.class, queue, | ||||||
PlayerIntentType.Enqueue) | ||||||
.putExtra(Player.RESUME_PLAYBACK, false); | ||||||
|
||||||
intent.putExtra(Player.PLAYER_TYPE, playerType.valueForIntent()); | ||||||
ContextCompat.startForegroundService(context, intent); | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enums are serializable, so they can be passed to/retrieved from intents/bundles as serializable objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what’s the difference? I don’t see any.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some suggestions with the relevant changes, so the Parcelable implementation can be removed for this enum.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why? I don’t see a big difference and like Parcellable more than Serializable