fix: Disable media tunneling by default with the option to enable it (#515)

Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
PartyDonut 2025-10-04 13:29:55 +02:00 committed by GitHub
parent 3ce0ed6dbc
commit 1942738fe4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 256 additions and 199 deletions

View file

@ -2,6 +2,9 @@ import 'package:freezed_annotation/freezed_annotation.dart';
part 'arguments_model.freezed.dart';
/// Prefer using the arguments provider over this boolean
bool leanBackMode = false;
@freezed
abstract class ArgumentsModel with _$ArgumentsModel {
const ArgumentsModel._();
@ -13,6 +16,7 @@ abstract class ArgumentsModel with _$ArgumentsModel {
factory ArgumentsModel.fromArguments(List<String> arguments, bool leanBackEnabled) {
arguments = arguments.map((e) => e.trim()).toList();
leanBackMode = leanBackEnabled;
return ArgumentsModel(
htpcMode: arguments.contains('--htpc') || leanBackEnabled,
leanBackMode: leanBackEnabled,

View file

@ -6,6 +6,7 @@ import 'package:flutter/widgets.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:fladder/models/items/media_segments_model.dart';
import 'package:fladder/models/settings/arguments_model.dart';
import 'package:fladder/models/settings/key_combinations.dart';
import 'package:fladder/util/bitrate_helper.dart';
import 'package:fladder/util/localization_helper.dart';
@ -63,6 +64,7 @@ abstract class VideoPlayerSettingsModel with _$VideoPlayerSettingsModel {
@Default(false) bool fillScreen,
@Default(true) bool hardwareAccel,
@Default(false) bool useLibass,
@Default(false) bool enableTunneling,
@Default(32) int bufferSize,
PlayerOptions? playerOptions,
@Default(100) double internalVolume,
@ -82,7 +84,8 @@ abstract class VideoPlayerSettingsModel with _$VideoPlayerSettingsModel {
factory VideoPlayerSettingsModel.fromJson(Map<String, dynamic> json) => _$VideoPlayerSettingsModelFromJson(json);
PlayerOptions get wantedPlayer => playerOptions ?? PlayerOptions.platformDefaults;
PlayerOptions get wantedPlayer =>
leanBackMode ? PlayerOptions.nativePlayer : playerOptions ?? PlayerOptions.platformDefaults;
Map<VideoHotKeys, KeyCombination> get currentShortcuts =>
_defaultVideoHotKeys.map((key, value) => MapEntry(key, hotKeys[key] ?? value));
@ -91,6 +94,7 @@ abstract class VideoPlayerSettingsModel with _$VideoPlayerSettingsModel {
bool playerSame(VideoPlayerSettingsModel other) {
return other.hardwareAccel == hardwareAccel &&
other.enableTunneling == enableTunneling &&
other.useLibass == useLibass &&
other.bufferSize == bufferSize &&
other.wantedPlayer == wantedPlayer;
@ -106,6 +110,7 @@ abstract class VideoPlayerSettingsModel with _$VideoPlayerSettingsModel {
other.fillScreen == fillScreen &&
other.hardwareAccel == hardwareAccel &&
other.useLibass == useLibass &&
other.enableTunneling == enableTunneling &&
other.bufferSize == bufferSize &&
other.internalVolume == internalVolume &&
other.playerOptions == playerOptions &&
@ -119,6 +124,7 @@ abstract class VideoPlayerSettingsModel with _$VideoPlayerSettingsModel {
fillScreen.hashCode ^
hardwareAccel.hashCode ^
useLibass.hashCode ^
enableTunneling.hashCode ^
bufferSize.hashCode ^
internalVolume.hashCode ^
audioDevice.hashCode;
@ -132,14 +138,17 @@ enum PlayerOptions {
const PlayerOptions();
static Iterable<PlayerOptions> get available => kIsWeb
? {PlayerOptions.libMPV}
: switch (defaultTargetPlatform) {
TargetPlatform.android => PlayerOptions.values,
_ => {PlayerOptions.libMDK, PlayerOptions.libMPV},
};
static Iterable<PlayerOptions> get available => leanBackMode
? {PlayerOptions.nativePlayer, PlayerOptions.libMPV}
: kIsWeb
? {PlayerOptions.libMPV}
: switch (defaultTargetPlatform) {
TargetPlatform.android => PlayerOptions.values,
_ => {PlayerOptions.libMDK, PlayerOptions.libMPV},
};
static PlayerOptions get platformDefaults {
if (leanBackMode) return PlayerOptions.nativePlayer;
if (kIsWeb) return PlayerOptions.libMPV;
return switch (defaultTargetPlatform) {
_ => PlayerOptions.libMPV,
@ -191,8 +200,10 @@ Map<VideoHotKeys, KeyCombination> get _defaultVideoHotKeys => {
VideoHotKeys.mute => KeyCombination(key: LogicalKeyboardKey.keyM),
VideoHotKeys.volumeUp => KeyCombination(key: LogicalKeyboardKey.arrowUp),
VideoHotKeys.volumeDown => KeyCombination(key: LogicalKeyboardKey.arrowDown),
VideoHotKeys.speedUp => KeyCombination(key: LogicalKeyboardKey.arrowUp, modifier: LogicalKeyboardKey.controlLeft),
VideoHotKeys.speedDown => KeyCombination(key: LogicalKeyboardKey.arrowDown, modifier: LogicalKeyboardKey.controlLeft),
VideoHotKeys.speedUp =>
KeyCombination(key: LogicalKeyboardKey.arrowUp, modifier: LogicalKeyboardKey.controlLeft),
VideoHotKeys.speedDown =>
KeyCombination(key: LogicalKeyboardKey.arrowDown, modifier: LogicalKeyboardKey.controlLeft),
VideoHotKeys.prevVideo =>
KeyCombination(key: LogicalKeyboardKey.keyP, modifier: LogicalKeyboardKey.shiftLeft),
VideoHotKeys.nextVideo =>

View file

@ -19,6 +19,7 @@ mixin _$VideoPlayerSettingsModel implements DiagnosticableTreeMixin {
bool get fillScreen;
bool get hardwareAccel;
bool get useLibass;
bool get enableTunneling;
int get bufferSize;
PlayerOptions? get playerOptions;
double get internalVolume;
@ -50,6 +51,7 @@ mixin _$VideoPlayerSettingsModel implements DiagnosticableTreeMixin {
..add(DiagnosticsProperty('fillScreen', fillScreen))
..add(DiagnosticsProperty('hardwareAccel', hardwareAccel))
..add(DiagnosticsProperty('useLibass', useLibass))
..add(DiagnosticsProperty('enableTunneling', enableTunneling))
..add(DiagnosticsProperty('bufferSize', bufferSize))
..add(DiagnosticsProperty('playerOptions', playerOptions))
..add(DiagnosticsProperty('internalVolume', internalVolume))
@ -64,7 +66,7 @@ mixin _$VideoPlayerSettingsModel implements DiagnosticableTreeMixin {
@override
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
return 'VideoPlayerSettingsModel(screenBrightness: $screenBrightness, videoFit: $videoFit, fillScreen: $fillScreen, hardwareAccel: $hardwareAccel, useLibass: $useLibass, bufferSize: $bufferSize, playerOptions: $playerOptions, internalVolume: $internalVolume, allowedOrientations: $allowedOrientations, nextVideoType: $nextVideoType, maxHomeBitrate: $maxHomeBitrate, maxInternetBitrate: $maxInternetBitrate, audioDevice: $audioDevice, segmentSkipSettings: $segmentSkipSettings, hotKeys: $hotKeys)';
return 'VideoPlayerSettingsModel(screenBrightness: $screenBrightness, videoFit: $videoFit, fillScreen: $fillScreen, hardwareAccel: $hardwareAccel, useLibass: $useLibass, enableTunneling: $enableTunneling, bufferSize: $bufferSize, playerOptions: $playerOptions, internalVolume: $internalVolume, allowedOrientations: $allowedOrientations, nextVideoType: $nextVideoType, maxHomeBitrate: $maxHomeBitrate, maxInternetBitrate: $maxInternetBitrate, audioDevice: $audioDevice, segmentSkipSettings: $segmentSkipSettings, hotKeys: $hotKeys)';
}
}
@ -80,6 +82,7 @@ abstract mixin class $VideoPlayerSettingsModelCopyWith<$Res> {
bool fillScreen,
bool hardwareAccel,
bool useLibass,
bool enableTunneling,
int bufferSize,
PlayerOptions? playerOptions,
double internalVolume,
@ -110,6 +113,7 @@ class _$VideoPlayerSettingsModelCopyWithImpl<$Res>
Object? fillScreen = null,
Object? hardwareAccel = null,
Object? useLibass = null,
Object? enableTunneling = null,
Object? bufferSize = null,
Object? playerOptions = freezed,
Object? internalVolume = null,
@ -142,6 +146,10 @@ class _$VideoPlayerSettingsModelCopyWithImpl<$Res>
? _self.useLibass
: useLibass // ignore: cast_nullable_to_non_nullable
as bool,
enableTunneling: null == enableTunneling
? _self.enableTunneling
: enableTunneling // ignore: cast_nullable_to_non_nullable
as bool,
bufferSize: null == bufferSize
? _self.bufferSize
: bufferSize // ignore: cast_nullable_to_non_nullable
@ -285,6 +293,7 @@ extension VideoPlayerSettingsModelPatterns on VideoPlayerSettingsModel {
bool fillScreen,
bool hardwareAccel,
bool useLibass,
bool enableTunneling,
int bufferSize,
PlayerOptions? playerOptions,
double internalVolume,
@ -307,6 +316,7 @@ extension VideoPlayerSettingsModelPatterns on VideoPlayerSettingsModel {
_that.fillScreen,
_that.hardwareAccel,
_that.useLibass,
_that.enableTunneling,
_that.bufferSize,
_that.playerOptions,
_that.internalVolume,
@ -343,6 +353,7 @@ extension VideoPlayerSettingsModelPatterns on VideoPlayerSettingsModel {
bool fillScreen,
bool hardwareAccel,
bool useLibass,
bool enableTunneling,
int bufferSize,
PlayerOptions? playerOptions,
double internalVolume,
@ -364,6 +375,7 @@ extension VideoPlayerSettingsModelPatterns on VideoPlayerSettingsModel {
_that.fillScreen,
_that.hardwareAccel,
_that.useLibass,
_that.enableTunneling,
_that.bufferSize,
_that.playerOptions,
_that.internalVolume,
@ -399,6 +411,7 @@ extension VideoPlayerSettingsModelPatterns on VideoPlayerSettingsModel {
bool fillScreen,
bool hardwareAccel,
bool useLibass,
bool enableTunneling,
int bufferSize,
PlayerOptions? playerOptions,
double internalVolume,
@ -420,6 +433,7 @@ extension VideoPlayerSettingsModelPatterns on VideoPlayerSettingsModel {
_that.fillScreen,
_that.hardwareAccel,
_that.useLibass,
_that.enableTunneling,
_that.bufferSize,
_that.playerOptions,
_that.internalVolume,
@ -446,6 +460,7 @@ class _VideoPlayerSettingsModel extends VideoPlayerSettingsModel
this.fillScreen = false,
this.hardwareAccel = true,
this.useLibass = false,
this.enableTunneling = false,
this.bufferSize = 32,
this.playerOptions,
this.internalVolume = 100,
@ -480,6 +495,9 @@ class _VideoPlayerSettingsModel extends VideoPlayerSettingsModel
final bool useLibass;
@override
@JsonKey()
final bool enableTunneling;
@override
@JsonKey()
final int bufferSize;
@override
final PlayerOptions? playerOptions;
@ -552,6 +570,7 @@ class _VideoPlayerSettingsModel extends VideoPlayerSettingsModel
..add(DiagnosticsProperty('fillScreen', fillScreen))
..add(DiagnosticsProperty('hardwareAccel', hardwareAccel))
..add(DiagnosticsProperty('useLibass', useLibass))
..add(DiagnosticsProperty('enableTunneling', enableTunneling))
..add(DiagnosticsProperty('bufferSize', bufferSize))
..add(DiagnosticsProperty('playerOptions', playerOptions))
..add(DiagnosticsProperty('internalVolume', internalVolume))
@ -566,7 +585,7 @@ class _VideoPlayerSettingsModel extends VideoPlayerSettingsModel
@override
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
return 'VideoPlayerSettingsModel(screenBrightness: $screenBrightness, videoFit: $videoFit, fillScreen: $fillScreen, hardwareAccel: $hardwareAccel, useLibass: $useLibass, bufferSize: $bufferSize, playerOptions: $playerOptions, internalVolume: $internalVolume, allowedOrientations: $allowedOrientations, nextVideoType: $nextVideoType, maxHomeBitrate: $maxHomeBitrate, maxInternetBitrate: $maxInternetBitrate, audioDevice: $audioDevice, segmentSkipSettings: $segmentSkipSettings, hotKeys: $hotKeys)';
return 'VideoPlayerSettingsModel(screenBrightness: $screenBrightness, videoFit: $videoFit, fillScreen: $fillScreen, hardwareAccel: $hardwareAccel, useLibass: $useLibass, enableTunneling: $enableTunneling, bufferSize: $bufferSize, playerOptions: $playerOptions, internalVolume: $internalVolume, allowedOrientations: $allowedOrientations, nextVideoType: $nextVideoType, maxHomeBitrate: $maxHomeBitrate, maxInternetBitrate: $maxInternetBitrate, audioDevice: $audioDevice, segmentSkipSettings: $segmentSkipSettings, hotKeys: $hotKeys)';
}
}
@ -584,6 +603,7 @@ abstract mixin class _$VideoPlayerSettingsModelCopyWith<$Res>
bool fillScreen,
bool hardwareAccel,
bool useLibass,
bool enableTunneling,
int bufferSize,
PlayerOptions? playerOptions,
double internalVolume,
@ -614,6 +634,7 @@ class __$VideoPlayerSettingsModelCopyWithImpl<$Res>
Object? fillScreen = null,
Object? hardwareAccel = null,
Object? useLibass = null,
Object? enableTunneling = null,
Object? bufferSize = null,
Object? playerOptions = freezed,
Object? internalVolume = null,
@ -646,6 +667,10 @@ class __$VideoPlayerSettingsModelCopyWithImpl<$Res>
? _self.useLibass
: useLibass // ignore: cast_nullable_to_non_nullable
as bool,
enableTunneling: null == enableTunneling
? _self.enableTunneling
: enableTunneling // ignore: cast_nullable_to_non_nullable
as bool,
bufferSize: null == bufferSize
? _self.bufferSize
: bufferSize // ignore: cast_nullable_to_non_nullable

View file

@ -15,6 +15,7 @@ _VideoPlayerSettingsModel _$VideoPlayerSettingsModelFromJson(
fillScreen: json['fillScreen'] as bool? ?? false,
hardwareAccel: json['hardwareAccel'] as bool? ?? true,
useLibass: json['useLibass'] as bool? ?? false,
enableTunneling: json['enableTunneling'] as bool? ?? false,
bufferSize: (json['bufferSize'] as num?)?.toInt() ?? 32,
playerOptions:
$enumDecodeNullable(_$PlayerOptionsEnumMap, json['playerOptions']),
@ -53,6 +54,7 @@ Map<String, dynamic> _$VideoPlayerSettingsModelToJson(
'fillScreen': instance.fillScreen,
'hardwareAccel': instance.hardwareAccel,
'useLibass': instance.useLibass,
'enableTunneling': instance.enableTunneling,
'bufferSize': instance.bufferSize,
'playerOptions': _$PlayerOptionsEnumMap[instance.playerOptions],
'internalVolume': instance.internalVolume,