diff --git a/app/src/main/java/org/schabi/newpipe/RouterActivity.java b/app/src/main/java/org/schabi/newpipe/RouterActivity.java index ca145bb9a..4f563a1d1 100644 --- a/app/src/main/java/org/schabi/newpipe/RouterActivity.java +++ b/app/src/main/java/org/schabi/newpipe/RouterActivity.java @@ -40,7 +40,9 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.playlist.PlaylistInfo; import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.VideoStream; +import org.schabi.newpipe.player.MainPlayer; import org.schabi.newpipe.player.helper.PlayerHelper; +import org.schabi.newpipe.player.helper.PlayerHolder; import org.schabi.newpipe.player.playqueue.ChannelPlayQueue; import org.schabi.newpipe.player.playqueue.PlayQueue; import org.schabi.newpipe.player.playqueue.PlaylistPlayQueue; @@ -394,14 +396,22 @@ public class RouterActivity extends AppCompatActivity { // show both "show info" and "video player", they are two different activities returnList.add(showInfo); returnList.add(videoPlayer); - } else if (capabilities.contains(VIDEO) - && PlayerHelper.isAutoplayAllowedByUser(context)) { - // show only "video player" since the details activity will be opened and the video - // will be autoplayed there and "show info" would do the exact same thing - returnList.add(videoPlayer); } else { - // show only "show info" if video player is not applicable or autoplay is disabled - returnList.add(showInfo); + final MainPlayer.PlayerType playerType = PlayerHolder.getType(); + if (capabilities.contains(VIDEO) + && PlayerHelper.isAutoplayAllowedByUser(context) + && playerType == null || playerType == MainPlayer.PlayerType.VIDEO) { + // show only "video player" since the details activity will be opened and the + // video will be auto played there. Since "show info" would do the exact same + // thing, use that as a key to let VideoDetailFragment load the stream instead + // of using FetcherService (see comment in handleChoice()) + returnList.add(new AdapterChoiceItem( + showInfo.key, videoPlayer.description, videoPlayer.icon)); + } else { + // show only "show info" if video player is not applicable, auto play is + // disabled or a video is playing in a player different than the main one + returnList.add(showInfo); + } } if (capabilities.contains(VIDEO)) { @@ -489,7 +499,6 @@ public class RouterActivity extends AppCompatActivity { .observeOn(AndroidSchedulers.mainThread()) .subscribe(intent -> { startActivity(intent); - finish(); }, throwable -> handleError(throwable, currentUrl)) ); @@ -657,41 +666,30 @@ public class RouterActivity extends AppCompatActivity { final boolean isExtAudioEnabled = preferences.getBoolean( getString(R.string.use_external_audio_player_key), false); - PlayQueue playQueue; - final String playerChoice = choice.playerChoice; - + final PlayQueue playQueue; if (info instanceof StreamInfo) { - if (playerChoice.equals(backgroundPlayerKey) && isExtAudioEnabled) { + if (choice.playerChoice.equals(backgroundPlayerKey) && isExtAudioEnabled) { NavigationHelper.playOnExternalAudioPlayer(this, (StreamInfo) info); - - } else if (playerChoice.equals(videoPlayerKey) && isExtVideoEnabled) { + return; + } else if (choice.playerChoice.equals(videoPlayerKey) && isExtVideoEnabled) { NavigationHelper.playOnExternalVideoPlayer(this, (StreamInfo) info); - - } else { - playQueue = new SinglePlayQueue((StreamInfo) info); - - if (playerChoice.equals(videoPlayerKey)) { - NavigationHelper.playOnMainPlayer(this, playQueue); - } else if (playerChoice.equals(backgroundPlayerKey)) { - NavigationHelper.playOnBackgroundPlayer(this, playQueue, true); - } else if (playerChoice.equals(popupPlayerKey)) { - NavigationHelper.playOnPopupPlayer(this, playQueue, true); - } + return; } + playQueue = new SinglePlayQueue((StreamInfo) info); + } else if (info instanceof ChannelInfo) { + playQueue = new ChannelPlayQueue((ChannelInfo) info); + } else if (info instanceof PlaylistInfo) { + playQueue = new PlaylistPlayQueue((PlaylistInfo) info); + } else { + return; } - if (info instanceof ChannelInfo || info instanceof PlaylistInfo) { - playQueue = info instanceof ChannelInfo - ? new ChannelPlayQueue((ChannelInfo) info) - : new PlaylistPlayQueue((PlaylistInfo) info); - - if (playerChoice.equals(videoPlayerKey)) { - NavigationHelper.playOnMainPlayer(this, playQueue); - } else if (playerChoice.equals(backgroundPlayerKey)) { - NavigationHelper.playOnBackgroundPlayer(this, playQueue, true); - } else if (playerChoice.equals(popupPlayerKey)) { - NavigationHelper.playOnPopupPlayer(this, playQueue, true); - } + if (choice.playerChoice.equals(videoPlayerKey)) { + NavigationHelper.playOnMainPlayer(this, playQueue); + } else if (choice.playerChoice.equals(backgroundPlayerKey)) { + NavigationHelper.playOnBackgroundPlayer(this, playQueue, true); + } else if (choice.playerChoice.equals(popupPlayerKey)) { + NavigationHelper.playOnPopupPlayer(this, playQueue, true); } }; }