@@ -201,7 +201,7 @@ public final class VideoDetailFragment
201
201
@ Nullable
202
202
private MainPlayer playerService ;
203
203
private Player player ;
204
- private PlayerHolder playerHolder = PlayerHolder .getInstance ();
204
+ private final PlayerHolder playerHolder = PlayerHolder .getInstance ();
205
205
206
206
/*//////////////////////////////////////////////////////////////////////////
207
207
// Service management
@@ -762,7 +762,7 @@ public boolean onBackPressed() {
762
762
763
763
private void setupFromHistoryItem (final StackItem item ) {
764
764
setAutoPlay (false );
765
- hideMainPlayer ();
765
+ hideMainPlayerOnLoadingNewStream ();
766
766
767
767
setInitialData (item .getServiceId (), item .getUrl (),
768
768
item .getTitle () == null ? "" : item .getTitle (), item .getPlayQueue ());
@@ -882,7 +882,7 @@ private void runWorker(final boolean forceLoad, final boolean addToBackStack) {
882
882
.observeOn (AndroidSchedulers .mainThread ())
883
883
.subscribe (result -> {
884
884
isLoading .set (false );
885
- hideMainPlayer ();
885
+ hideMainPlayerOnLoadingNewStream ();
886
886
if (result .getAgeLimit () != NO_AGE_LIMIT && !prefs .getBoolean (
887
887
getString (R .string .show_age_restricted_content ), false )) {
888
888
hideAgeRestrictedContent ();
@@ -1174,16 +1174,27 @@ private void openMainPlayer() {
1174
1174
ContextCompat .startForegroundService (activity , playerIntent );
1175
1175
}
1176
1176
1177
- private void hideMainPlayer () {
1177
+ /**
1178
+ * When the video detail fragment is already showing details for a video and the user opens a
1179
+ * new one, the video detail fragment changes all of its old data to the new stream, so if there
1180
+ * is a video player currently open it should be hidden. This method does exactly that. If
1181
+ * autoplay is enabled, the underlying player is not stopped completely, since it is going to
1182
+ * be reused in a few milliseconds and the flickering would be annoying.
1183
+ */
1184
+ private void hideMainPlayerOnLoadingNewStream () {
1178
1185
if (!isPlayerServiceAvailable ()
1179
1186
|| playerService .getView () == null
1180
1187
|| !player .videoPlayerSelected ()) {
1181
1188
return ;
1182
1189
}
1183
1190
1184
1191
removeVideoPlayerView ();
1185
- playerService .stop (isAutoplayEnabled ());
1186
- playerService .getView ().setVisibility (View .GONE );
1192
+ if (isAutoplayEnabled ()) {
1193
+ playerService .stopForImmediateReusing ();
1194
+ playerService .getView ().setVisibility (View .GONE );
1195
+ } else {
1196
+ playerHolder .stopService ();
1197
+ }
1187
1198
}
1188
1199
1189
1200
private PlayQueue setupPlayQueueForIntent (final boolean append ) {
@@ -1832,7 +1843,7 @@ public void onPlayerError(final ExoPlaybackException error) {
1832
1843
|| error .type == ExoPlaybackException .TYPE_UNEXPECTED ) {
1833
1844
// Properly exit from fullscreen
1834
1845
toggleFullscreenIfInFullscreenMode ();
1835
- hideMainPlayer ();
1846
+ hideMainPlayerOnLoadingNewStream ();
1836
1847
}
1837
1848
}
1838
1849
0 commit comments