diff --git a/chewie/lib/src/material_controls.dart b/chewie/lib/src/material_controls.dart index 7a41b0b37..ac0f16db2 100755 --- a/chewie/lib/src/material_controls.dart +++ b/chewie/lib/src/material_controls.dart @@ -359,7 +359,15 @@ class _MaterialControlsState extends State final List qualityTags = []; for (final YouTubeQualityOption quality in chewieController.streamData.videoQualities) { - qualityTags.add(quality.videoResolution); + String muxTag; + + if (quality.muxed) { + muxTag = "(seek-friendly)"; + } else { + muxTag = ""; + } + + qualityTags.add("${quality.videoResolution} $muxTag"); } final chosenOption = await showModalBottomSheet( @@ -374,10 +382,17 @@ class _MaterialControlsState extends State "lastPlayedQuality", qualityTags[chosenOption]); final Duration position = await controller.getPosition(); - chewieController.currentVideoQuality = + final YouTubeQualityOption chosenQuality = chewieController.streamData.videoQualities[chosenOption]; + + chewieController.currentVideoQuality = chosenQuality; + await controller.setMediaFromNetwork(chewieController .streamData.videoQualities[chosenOption].videoURL); + if (!chosenQuality.muxed) { + await controller + .addAudioFromNetwork(chewieController.streamData.audioURL); + } await controller.seekTo(position); } diff --git a/lib/preferences.dart b/lib/preferences.dart index 5bd81b7d8..469c0105e 100644 --- a/lib/preferences.dart +++ b/lib/preferences.dart @@ -269,12 +269,12 @@ YouTubeQualityOption getLastPlayedQuality( } // In this case, we know that they have set a quality that doesn't exist, // maybe it's a low quality video -- so we take the best quality. - return qualities.last; + return qualities.lastWhere((element) => element.muxed) ?? qualities.last; } else { // We don't know if we could abuse their mobile data, // let's try the average. - return qualities - .firstWhere((element) => element.videoResolution == "360p") ?? + return qualities.firstWhere( + (element) => element.videoResolution == "360p" || element.muxed) ?? qualities.first; } } diff --git a/lib/youtube.dart b/lib/youtube.dart index fefdc3a5c..071c34552 100644 --- a/lib/youtube.dart +++ b/lib/youtube.dart @@ -19,10 +19,12 @@ import 'package:jidoujisho/util.dart'; class YouTubeQualityOption { final String videoURL; final String videoResolution; + final bool muxed; YouTubeQualityOption({ this.videoURL, this.videoResolution, + this.muxed, }); } @@ -96,6 +98,27 @@ Future getPlayerYouTubeInfo(String webURL) async { List videoQualities = []; List videoResolutions = []; + for (var stream in streamManifest.muxed.sortByBitrate()) { + String resolutionLabel = stream.videoQualityLabel; + if (!stream.videoQualityLabel.contains("p")) { + resolutionLabel = stream.videoQualityLabel + "p"; + } + if (stream.videoQualityLabel.contains("p60")) { + resolutionLabel = stream.videoQualityLabel.replaceAll("p60", "p"); + } + + if (!videoResolutions.contains(resolutionLabel)) { + videoQualities.add( + YouTubeQualityOption( + videoURL: stream.url.toString(), + videoResolution: resolutionLabel, + muxed: true, + ), + ); + videoResolutions.add(resolutionLabel); + } + } + for (var stream in streamManifest.videoOnly.sortByBitrate()) { String resolutionLabel = stream.videoQualityLabel; if (!stream.videoQualityLabel.contains("p")) { @@ -110,12 +133,22 @@ Future getPlayerYouTubeInfo(String webURL) async { YouTubeQualityOption( videoURL: stream.url.toString(), videoResolution: resolutionLabel, + muxed: false, ), ); videoResolutions.add(resolutionLabel); } } + videoQualities.sort((a, b) { + int aHeight = int.parse( + a.videoResolution.substring(0, a.videoResolution.length - 1)); + int bHeight = int.parse( + b.videoResolution.substring(0, b.videoResolution.length - 1)); + + return aHeight.compareTo(bHeight); + }); + AudioStreamInfo streamAudioInfo = streamManifest.audioOnly.sortByBitrate().last; String audioURL = streamAudioInfo.url.toString(); diff --git a/pubspec.yaml b/pubspec.yaml index 359220e7e..cdb0c8bd5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: jidoujisho description: A mobile video player tailored for Japanese language learners. publish_to: none -version: 0.12.3+3 +version: 0.12.4+4 environment: sdk: ">=2.7.0 <3.0.0"