Skip to content

Commit

Permalink
Merge pull request #396 from lamarios/fix/audio_playback_when_using_p…
Browse files Browse the repository at this point in the history
…roxy

Fix/audio playback when using proxy
  • Loading branch information
lamarios authored Dec 6, 2023
2 parents c5ec466 + 3da3144 commit da35696
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions lib/player/states/audio_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,26 @@ class AudioPlayerCubit extends MediaPlayerCubit<AudioPlayerState> {
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;
Expand Down

0 comments on commit da35696

Please sign in to comment.