mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-07 21:48:14 -08:00
feat: Videoplayer remember subtitle and audio selection(#339)
This commit is contained in:
parent
93a38a0b6b
commit
b1491b0ada
10 changed files with 247 additions and 39 deletions
56
lib/util/streams_selection.dart
Normal file
56
lib/util/streams_selection.dart
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
|
||||
import 'package:fladder/models/items/media_streams_model.dart';
|
||||
|
||||
int? selectAudioStream(bool rememberAudioSelection, AudioAndSubStreamModel? previousStream, List<AudioAndSubStreamModel>? currentStream, int? defaultStream) {
|
||||
if (!rememberAudioSelection){
|
||||
return defaultStream;
|
||||
}
|
||||
return _selectStream(previousStream, currentStream, defaultStream);
|
||||
}
|
||||
|
||||
int? selectSubStream(bool rememberSubSelection, AudioAndSubStreamModel? previousStream, List<AudioAndSubStreamModel>? currentStream, int? defaultStream) {
|
||||
if (!rememberSubSelection){
|
||||
return defaultStream;
|
||||
}
|
||||
return _selectStream(previousStream, currentStream, defaultStream);
|
||||
}
|
||||
|
||||
int? _selectStream(AudioAndSubStreamModel? previousStream, List<AudioAndSubStreamModel>? currentStream, int? defaultStream) {
|
||||
if (currentStream == null || previousStream == null){
|
||||
return defaultStream;
|
||||
}
|
||||
|
||||
int? bestStreamIndex;
|
||||
int bestStreamScore = 0;
|
||||
|
||||
// Find the relative index of the previous stream
|
||||
int prevRelIndex = 0;
|
||||
for (var stream in currentStream) {
|
||||
if (stream.index == previousStream.index) break;
|
||||
prevRelIndex += 1;
|
||||
}
|
||||
|
||||
int newRelIndex = 0;
|
||||
for (var stream in currentStream) {
|
||||
int score = 0;
|
||||
|
||||
if (previousStream.codec == stream.codec) score += 1;
|
||||
if (prevRelIndex == newRelIndex) score += 1;
|
||||
if (previousStream.displayTitle == stream.displayTitle) {
|
||||
score += 2;
|
||||
}
|
||||
if (previousStream.language != 'und' &&
|
||||
previousStream.language == stream.language) {
|
||||
score += 2;
|
||||
}
|
||||
|
||||
if (score > bestStreamScore && score >= 3) {
|
||||
bestStreamScore = score;
|
||||
bestStreamIndex = stream.index;
|
||||
}
|
||||
|
||||
newRelIndex += 1;
|
||||
}
|
||||
return bestStreamIndex ?? defaultStream;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue