Skip to content

Commit

Permalink
Merge pull request #223 from lamarios/feature/save_playback_speed
Browse files Browse the repository at this point in the history
setting to save playback speed
  • Loading branch information
lamarios authored Jul 5, 2023
2 parents 13eabfb + ceccc52 commit 4c27521
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 10 deletions.
29 changes: 20 additions & 9 deletions lib/controllers/playerController.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,37 @@ class PlayerController extends GetxController {
saveProgress(video.lengthSeconds);
broadcastEvent(event);
break;

case BetterPlayerEventType.pipStart:
case BetterPlayerEventType.pipStop:
case BetterPlayerEventType.openFullscreen:
case BetterPlayerEventType.hideFullscreen:
case BetterPlayerEventType.overflowClosed:
case BetterPlayerEventType.overflowOpened:
case BetterPlayerEventType.initialized:
case BetterPlayerEventType.seekTo:
case BetterPlayerEventType.initialized:
case BetterPlayerEventType.bufferingEnd:
case BetterPlayerEventType.bufferingStart:
broadcastEvent(event);
break;
case BetterPlayerEventType.play:
double speed = 1.0;
if (db.getSettings(REMEMBER_PLAYBACK_SPEED)?.value == 'true') {
speed = double.parse(db.getSettings(LAST_SPEED)?.value ?? '1.0');

log.fine("Setting playback speed to $speed");
videoController?.setSpeed(speed);
}
broadcastEvent(event);
break;
case BetterPlayerEventType.changedSubtitles:
db.saveSetting(SettingsValue(LAST_SUBTITLE, videoController?.betterPlayerSubtitlesSource?.name ?? ''));
break;
case BetterPlayerEventType.setSpeed:
if (event.parameters?.containsKey("speed") ?? false) {
db.saveSetting(SettingsValue(LAST_SPEED, event.parameters?["speed"].toString() ?? '1.0'));
}
break;
default:
break;
}
Expand Down Expand Up @@ -219,14 +235,9 @@ class PlayerController extends GetxController {
BetterPlayerDataSource betterPlayerDataSource = BetterPlayerDataSource(BetterPlayerDataSourceType.network, videoUrl,
videoFormat: format,
liveStream: video.liveNow,
subtitles: video.captions.map((s) =>
BetterPlayerSubtitlesSource(
type: BetterPlayerSubtitlesSourceType.network,
urls: ['${baseUrl}${s.url}'],
name: s.label,
selectedByDefault: s.label == lastSubtitle
)
).toList(),
subtitles: video.captions
.map((s) => BetterPlayerSubtitlesSource(type: BetterPlayerSubtitlesSourceType.network, urls: ['${baseUrl}${s.url}'], name: s.label, selectedByDefault: s.label == lastSubtitle))
.toList(),
resolutions: resolutions.isNotEmpty ? resolutions : null,
// placeholder: VideoThumbnailView(videoId: video.videoId, thumbnailUrl: video.getBestThumbnail()?.url ?? ''),
notificationConfiguration: BetterPlayerNotificationConfiguration(
Expand Down
9 changes: 8 additions & 1 deletion lib/controllers/settingsController.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SettingsController extends GetxController {
double subtitleSize = double.parse(db.getSettings(SUBTITLE_SIZE)?.value ?? subtitleDefaultSize);
bool rememberSubtitles = db.getSettings(REMEMBER_LAST_SUBTITLE)?.value == 'true';
bool skipSslVerification = db.getSettings(SKIP_SSL_VERIFICATION)?.value == 'true';
bool rememberPlayBackSpeed = db.getSettings(REMEMBER_PLAYBACK_SPEED)?.value == 'true';
ThemeMode themeMode = ThemeMode.values.firstWhere((element) => element.name == db.getSettings(THEME_MODE)?.value, orElse: () => ThemeMode.system);
String? locale = db.getSettings(LOCALE)?.value;
bool useSearchHistory = db.getSettings(USE_SEARCH_HISTORY)?.value == 'true';
Expand Down Expand Up @@ -92,6 +93,12 @@ class SettingsController extends GetxController {
}
}

toggleRememberPlaybackSpeed(bool value) {
db.saveSetting(SettingsValue(REMEMBER_PLAYBACK_SPEED, value.toString()));
rememberPlayBackSpeed = value;
update();
}

selectOnOpen(String selected, List<String> categories) {
int selectedIndex = categories.indexOf(selected);
db.saveSetting(SettingsValue(ON_OPEN, selectedIndex.toString()));
Expand Down Expand Up @@ -207,7 +214,7 @@ class SettingsController extends GetxController {
updateApp();
}

updateApp(){
updateApp() {
AppController.to()?.update();
}

Expand Down
2 changes: 2 additions & 0 deletions lib/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const THEME_MODE = 'theme-mode';
const LOCALE = 'locale';
const USE_SEARCH_HISTORY = 'use-search-history';
const SEARCH_HISTORY_LIMIT = 'search-history-limit';
const REMEMBER_PLAYBACK_SPEED = 'remember-playback-speed';
const LAST_SPEED = 'last-speed';

const ON_OPEN = "on-open";
const MAX_LOGS = 1000;
Expand Down
8 changes: 8 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -642,5 +642,13 @@
"rememberSubtitleLanguageDescription": "Automatically set subtitles to last language selected, if available",
"@rememberSubtitleLanguageDescription": {
"description": "Settings description for remembering subtitle language"
},
"rememberPlaybackSpeed": "Remember playback speed",
"@rememberPlaybackSpeed": {
"description": "Setting label for remembering playback speed"
},
"rememberPlaybackSpeedDescription": "Automatically set playback speed to last speed selected",
"@rememberPlaybackSpeedDescription": {
"description": "Settings descrtiption for remembering playback speed"
}
}
6 changes: 6 additions & 0 deletions lib/views/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ class Settings extends StatelessWidget {
title: Text(locals.rememberSubtitleLanguage),
description: Text(locals.rememberSubtitleLanguageDescription),
),
SettingsTile.switchTile(
initialValue: _.rememberPlayBackSpeed,
onToggle: _.toggleRememberPlaybackSpeed,
title: Text(locals.rememberPlaybackSpeed),
description: Text(locals.rememberPlaybackSpeedDescription),
),
SettingsTile.navigation(
title: const Text('SponsorBlock'),
description: Text(locals.sponsorBlockDescription),
Expand Down
6 changes: 6 additions & 0 deletions lib/views/tv/tvSettings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ class TVSettings extends StatelessWidget {
onSelected: (context) => _.toggleRememberSubtitles(!_.rememberSubtitles),
trailing: Switch(onChanged: (value) {}, value: _.rememberSubtitles),
),
SettingsTile(
title: locals.rememberPlaybackSpeed,
description: locals.rememberPlaybackSpeedDescription,
onSelected: (context) => _.toggleRememberPlaybackSpeed(!_.rememberPlayBackSpeed),
trailing: Switch(onChanged: (value) {}, value: _.rememberPlayBackSpeed),
),
SettingsTile(
title: 'SponsorBlock',
description: locals.sponsorBlockDescription,
Expand Down

0 comments on commit 4c27521

Please sign in to comment.