99import android .content .Intent ;
1010import android .net .Uri ;
1111import android .os .Build ;
12+ import android .os .Parcelable ;
1213import android .util .Log ;
1314import android .widget .Toast ;
1415
5758import org .schabi .newpipe .local .subscription .SubscriptionsImportFragment ;
5859import org .schabi .newpipe .player .PlayQueueActivity ;
5960import org .schabi .newpipe .player .Player ;
61+ import org .schabi .newpipe .player .PlayerIntentType ;
6062import org .schabi .newpipe .player .PlayerService ;
6163import org .schabi .newpipe .player .PlayerType ;
64+ import org .schabi .newpipe .player .TimestampChangeData ;
6265import org .schabi .newpipe .player .helper .PlayerHelper ;
6366import org .schabi .newpipe .player .helper .PlayerHolder ;
6467import org .schabi .newpipe .player .playqueue .PlayQueue ;
@@ -85,7 +88,7 @@ private NavigationHelper() {
8588 public static <T > Intent getPlayerIntent (@ NonNull final Context context ,
8689 @ NonNull final Class <T > targetClazz ,
8790 @ Nullable final PlayQueue playQueue ,
88- final boolean resumePlayback ) {
91+ @ NonNull final PlayerIntentType playerIntentType ) {
8992 final Intent intent = new Intent (context , targetClazz );
9093
9194 if (playQueue != null ) {
@@ -95,44 +98,31 @@ public static <T> Intent getPlayerIntent(@NonNull final Context context,
9598 }
9699 }
97100 intent .putExtra (Player .PLAYER_TYPE , PlayerType .MAIN .valueForIntent ());
98- intent .putExtra (Player .RESUME_PLAYBACK , resumePlayback );
99101 intent .putExtra (PlayerService .SHOULD_START_FOREGROUND_EXTRA , true );
102+ intent .putExtra (Player .PLAYER_INTENT_TYPE , (Parcelable ) playerIntentType );
100103
101104 return intent ;
102105 }
103106
104107 @ NonNull
105- public static <T > Intent getPlayerIntent (@ NonNull final Context context ,
106- @ NonNull final Class <T > targetClazz ,
107- @ Nullable final PlayQueue playQueue ,
108- final boolean resumePlayback ,
109- final boolean playWhenReady ) {
110- return getPlayerIntent (context , targetClazz , playQueue , resumePlayback )
111- .putExtra (Player .PLAY_WHEN_READY , playWhenReady );
112- }
108+ public static Intent getPlayerTimestampIntent (@ NonNull final Context context ,
109+ @ NonNull final TimestampChangeData
110+ timestampChangeData ) {
111+ final Intent intent = new Intent (context , PlayerService .class );
113112
114- @ NonNull
115- public static <T > Intent getPlayerEnqueueIntent (@ NonNull final Context context ,
116- @ NonNull final Class <T > targetClazz ,
117- @ Nullable final PlayQueue playQueue ) {
118- // when enqueueing `resumePlayback` is always `false` since:
119- // - if there is a video already playing, the value of `resumePlayback` just doesn't make
120- // any difference.
121- // - if there is nothing already playing, it is useful for the enqueue action to have a
122- // slightly different behaviour than the normal play action: the latter resumes playback,
123- // the former doesn't. (note that enqueue can be triggered when nothing is playing only
124- // by long pressing the video detail fragment, playlist or channel controls
125- return getPlayerIntent (context , targetClazz , playQueue , false )
126- .putExtra (Player .ENQUEUE , true );
113+ intent .putExtra (Player .PLAYER_INTENT_TYPE , (Parcelable ) PlayerIntentType .TimestampChange );
114+ intent .putExtra (Player .PLAYER_INTENT_DATA , timestampChangeData );
115+
116+ return intent ;
127117 }
128118
129119 @ NonNull
130120 public static <T > Intent getPlayerEnqueueNextIntent (@ NonNull final Context context ,
131121 @ NonNull final Class <T > targetClazz ,
132122 @ Nullable final PlayQueue playQueue ) {
133- // see comment in `getPlayerEnqueueIntent` as to why `resumePlayback` is false
134- return getPlayerIntent ( context , targetClazz , playQueue , false )
135- .putExtra (Player .ENQUEUE_NEXT , true );
123+ return getPlayerIntent ( context , targetClazz , playQueue , PlayerIntentType . EnqueueNext )
124+ // see comment in `getPlayerEnqueueIntent` as to why `resumePlayback` is false
125+ .putExtra (Player .RESUME_PLAYBACK , false );
136126 }
137127
138128 /* PLAY */
@@ -166,8 +156,10 @@ public static void playOnPopupPlayer(final Context context,
166156
167157 Toast .makeText (context , R .string .popup_playing_toast , Toast .LENGTH_SHORT ).show ();
168158
169- final Intent intent = getPlayerIntent (context , PlayerService .class , queue , resumePlayback );
170- intent .putExtra (Player .PLAYER_TYPE , PlayerType .POPUP .valueForIntent ());
159+ final Intent intent = getPlayerIntent (context , PlayerService .class , queue ,
160+ PlayerIntentType .AllOthers );
161+ intent .putExtra (Player .PLAYER_TYPE , PlayerType .POPUP .valueForIntent ())
162+ .putExtra (Player .RESUME_PLAYBACK , resumePlayback );
171163 ContextCompat .startForegroundService (context , intent );
172164 }
173165
@@ -177,8 +169,10 @@ public static void playOnBackgroundPlayer(final Context context,
177169 Toast .makeText (context , R .string .background_player_playing_toast , Toast .LENGTH_SHORT )
178170 .show ();
179171
180- final Intent intent = getPlayerIntent (context , PlayerService .class , queue , resumePlayback );
172+ final Intent intent = getPlayerIntent (context , PlayerService .class , queue ,
173+ PlayerIntentType .AllOthers );
181174 intent .putExtra (Player .PLAYER_TYPE , PlayerType .AUDIO .valueForIntent ());
175+ intent .putExtra (Player .RESUME_PLAYBACK , resumePlayback );
182176 ContextCompat .startForegroundService (context , intent );
183177 }
184178
@@ -191,7 +185,17 @@ public static void enqueueOnPlayer(final Context context,
191185 }
192186
193187 Toast .makeText (context , R .string .enqueued , Toast .LENGTH_SHORT ).show ();
194- final Intent intent = getPlayerEnqueueIntent (context , PlayerService .class , queue );
188+
189+ // when enqueueing `resumePlayback` is always `false` since:
190+ // - if there is a video already playing, the value of `resumePlayback` just doesn't make
191+ // any difference.
192+ // - if there is nothing already playing, it is useful for the enqueue action to have a
193+ // slightly different behaviour than the normal play action: the latter resumes playback,
194+ // the former doesn't. (note that enqueue can be triggered when nothing is playing only
195+ // by long pressing the video detail fragment, playlist or channel controls
196+ final Intent intent = getPlayerIntent (context , PlayerService .class , queue ,
197+ PlayerIntentType .Enqueue )
198+ .putExtra (Player .RESUME_PLAYBACK , false );
195199
196200 intent .putExtra (Player .PLAYER_TYPE , playerType .valueForIntent ());
197201 ContextCompat .startForegroundService (context , intent );
0 commit comments