From e70c8a3aa7369d44f18e95096062c88cbb3469fe Mon Sep 17 00:00:00 2001 From: Paul Fauchon Date: Tue, 5 Dec 2023 17:30:59 +0800 Subject: [PATCH 1/2] switch audio player to use formatted stream when using local proxy, might not be the most efficient way but at least it works. --- lib/player/states/audio_player.dart | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/player/states/audio_player.dart b/lib/player/states/audio_player.dart index ce1081ed..e6c51338 100644 --- a/lib/player/states/audio_player.dart +++ b/lib/player/states/audio_player.dart @@ -108,19 +108,26 @@ class AudioPlayerCubit extends MediaPlayerCubit { AudioSource? source; if (!offline) { - AdaptiveFormat? audio = state.video?.adaptiveFormats - .where((element) => element.type.contains("audio")) - .sortByReversed((e) => int.parse(e.bitrate ?? "0")) - .first; - if (audio != null) { - if (startAt == null) { - double progress = db.getVideoProgress(state.video!.videoId); - if (progress > 0 && progress < 0.90) { - startAt = Duration(seconds: (state.video!.lengthSeconds * progress).floor()); + if (service.useProxy()) { + // audio only streams don't seem to work when using proxy mode, using formatted streams when proxy is enabled + var formatStream = state.video!.formatStreams[state.video!.formatStreams.length - 1]; + source = AudioSource.uri(Uri.parse(formatStream.url)); + } else { + AdaptiveFormat? audio = state.video?.adaptiveFormats + .where((element) => element.type.contains("audio")) + .sortByReversed((e) => int.parse(e.bitrate ?? "0")) + .first; + if (audio != null) { + if (startAt == null) { + double progress = db.getVideoProgress(state.video!.videoId); + if (progress > 0 && progress < 0.90) { + startAt = Duration(seconds: (state.video!.lengthSeconds * progress).floor()); + } } + emit(state); + + source = AudioSource.uri(Uri.parse(audio.url)); } - emit(state); - source = AudioSource.uri(Uri.parse(audio.url)); } } else { String path = await state.offlineVideo!.mediaPath; From b38cce2dc5e1227096356b138613dda4a43151f2 Mon Sep 17 00:00:00 2001 From: Paul Fauchon Date: Tue, 5 Dec 2023 17:31:36 +0800 Subject: [PATCH 2/2] fix #392