Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to always resume from the last position #530

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Screenbox.Core/Services/ISettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface ISettingsService
string PersistentSubtitleLanguage { get; set; }
bool ShowRecent { get; set; }
bool EnqueueAllFilesInFolder { get; set; }
bool RestorePlaybackPosition { get; set; }
bool SearchRemovableStorage { get; set; }
int MaxVolume { get; set; }
string GlobalArguments { get; set; }
Expand Down
7 changes: 7 additions & 0 deletions Screenbox.Core/Services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public sealed class SettingsService : ISettingsService
private const string LibrariesSearchRemovableStorageKey = "Libraries/SearchRemovableStorage";
private const string GeneralShowRecent = "General/ShowRecent";
private const string GeneralEnqueueAllInFolder = "General/EnqueueAllInFolder";
private const string GeneralRestorePlaybackPosition = "General/RestorePlaybackPosition";
private const string AdvancedModeKey = "Advanced/IsEnabled";
private const string AdvancedMultipleInstancesKey = "Advanced/MultipleInstances";
private const string GlobalArgumentsKey = "Values/GlobalArguments";
Expand Down Expand Up @@ -92,6 +93,12 @@ public bool EnqueueAllFilesInFolder
set => SetValue(GeneralEnqueueAllInFolder, value);
}

public bool RestorePlaybackPosition
{
get => GetValue<bool>(GeneralRestorePlaybackPosition);
set => SetValue(GeneralRestorePlaybackPosition, value);
}

public bool PlayerShowControls
{
get => GetValue<bool>(PlayerShowControlsKey);
Expand Down
11 changes: 10 additions & 1 deletion Screenbox.Core/ViewModels/PlayerPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,16 @@ public void Receive(PlaylistCurrentItemChangedMessage message)
if (message.Value != null)
{
TimeSpan lastPosition = _lastPositionTracker.GetPosition(message.Value.Location);
Messenger.Send(new RaiseResumePositionNotificationMessage(lastPosition));
if (lastPosition <= TimeSpan.Zero) return;
if (_settingsService.RestorePlaybackPosition)
{
// TODO: Wait until playback starts then send time change message
Messenger.Send(new ChangeTimeRequestMessage(lastPosition, debounce: false));
}
else
{
Messenger.Send(new RaiseResumePositionNotificationMessage(lastPosition));
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions Screenbox.Core/ViewModels/SettingsPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public sealed partial class SettingsPageViewModel : ObservableRecipient
[ObservableProperty] private bool _useIndexer;
[ObservableProperty] private bool _showRecent;
[ObservableProperty] private bool _enqueueAllFilesInFolder;
[ObservableProperty] private bool _restorePlaybackPosition;
[ObservableProperty] private bool _searchRemovableStorage;
[ObservableProperty] private bool _advancedMode;
[ObservableProperty] private bool _useMultipleInstances;
Expand Down Expand Up @@ -78,6 +79,7 @@ public SettingsPageViewModel(ISettingsService settingsService, ILibraryService l
_useIndexer = _settingsService.UseIndexer;
_showRecent = _settingsService.ShowRecent;
_enqueueAllFilesInFolder = _settingsService.EnqueueAllFilesInFolder;
_restorePlaybackPosition = _settingsService.RestorePlaybackPosition;
_searchRemovableStorage = _settingsService.SearchRemovableStorage;
_advancedMode = _settingsService.AdvancedMode;
_useMultipleInstances = _settingsService.UseMultipleInstances;
Expand Down Expand Up @@ -145,6 +147,12 @@ partial void OnEnqueueAllFilesInFolderChanged(bool value)
Messenger.Send(new SettingsChangedMessage(nameof(EnqueueAllFilesInFolder), typeof(SettingsPageViewModel)));
}

partial void OnRestorePlaybackPositionChanged(bool value)
{
_settingsService.RestorePlaybackPosition = value;
Messenger.Send(new SettingsChangedMessage(nameof(RestorePlaybackPosition), typeof(SettingsPageViewModel)));
}

async partial void OnSearchRemovableStorageChanged(bool value)
{
_settingsService.SearchRemovableStorage = value;
Expand Down
7 changes: 7 additions & 0 deletions Screenbox/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@
<ToggleSwitch IsOn="{x:Bind ViewModel.EnqueueAllFilesInFolder, Mode=TwoWay}" />
</ctc:SettingsCard>

<ctc:SettingsCard
Margin="{StaticResource SettingsCardMargin}"
Description="Continue playing from where you last stopped when opening a file"
Header="Always resume from last position">
<ToggleSwitch IsOn="{x:Bind ViewModel.RestorePlaybackPosition, Mode=TwoWay}" />
</ctc:SettingsCard>

<!-- Player section -->
<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Text="{strings:Resources Key=SettingsCategoryPlayer}" />

Expand Down