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 an option to change the SMTC update interval #529

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 @@ -19,6 +19,7 @@ public interface ISettingsService
string GlobalArguments { get; set; }
bool AdvancedMode { get; set; }
bool UseMultipleInstances { get; set; }
double SmtcUpdateInterval { get; set; }
string LivelyActivePath { get; set; }
MediaPlaybackAutoRepeatMode PersistentRepeatMode { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface ISystemMediaTransportControlsService
{
SystemMediaTransportControls TransportControls { get; }
Task UpdateTransportControlsDisplayAsync(MediaViewModel? item);
void UpdatePlaybackPosition(TimeSpan position, TimeSpan startTime, TimeSpan endTime);
void UpdatePlaybackPosition(TimeSpan position, TimeSpan startTime, TimeSpan endTime, TimeSpan updateInterval = default);
void UpdatePlaybackStatus(MediaPlaybackState state);
void ClosePlayback();
}
Expand Down
8 changes: 8 additions & 0 deletions Screenbox.Core/Services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public sealed class SettingsService : ISettingsService
private const string GeneralEnqueueAllInFolder = "General/EnqueueAllInFolder";
private const string AdvancedModeKey = "Advanced/IsEnabled";
private const string AdvancedMultipleInstancesKey = "Advanced/MultipleInstances";
private const string AdvancedSmtcUpdateIntervalKey = "Advanced/SMTCUpdateInterval";
private const string GlobalArgumentsKey = "Values/GlobalArguments";
private const string PersistentVolumeKey = "Values/Volume";
private const string MaxVolumeKey = "Values/MaxVolume";
Expand Down Expand Up @@ -127,6 +128,12 @@ public string LivelyActivePath
set => SetValue(PlayerLivelyPathKey, value);
}

public double SmtcUpdateInterval
{
get => GetValue<double>(AdvancedSmtcUpdateIntervalKey);
set => SetValue(AdvancedSmtcUpdateIntervalKey, value);
}

public SettingsService()
{
SetDefault(PlayerAutoResizeKey, (int)PlayerAutoResizeOption.Always);
Expand All @@ -142,6 +149,7 @@ public SettingsService()
SetDefault(PersistentRepeatModeKey, (int)MediaPlaybackAutoRepeatMode.None);
SetDefault(AdvancedModeKey, false);
SetDefault(AdvancedMultipleInstancesKey, false);
SetDefault(AdvancedSmtcUpdateIntervalKey, 5.0);
SetDefault(GlobalArgumentsKey, string.Empty);

// Device family specific overrides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ public async Task UpdateTransportControlsDisplayAsync(MediaViewModel? item)
}
}

public void UpdatePlaybackPosition(TimeSpan position, TimeSpan startTime, TimeSpan endTime)
public void UpdatePlaybackPosition(TimeSpan position, TimeSpan startTime, TimeSpan endTime, TimeSpan updateInterval = default)
{
if (DateTime.Now - _lastUpdated < TimeSpan.FromSeconds(5)) return;
if (updateInterval < TimeSpan.FromSeconds(1)) updateInterval = TimeSpan.FromSeconds(5);
if (DateTime.Now - _lastUpdated < updateInterval) return;
_lastUpdated = DateTime.Now;
SystemMediaTransportControlsTimelineProperties timelineProps = new()
{
Expand Down
4 changes: 3 additions & 1 deletion Screenbox.Core/ViewModels/PlayerElementViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public sealed partial class PlayerElementViewModel : ObservableRecipient,
private VlcMediaPlayer? _mediaPlayer;
private ManipulationLock _manipulationLock;
private TimeSpan _timeBeforeManipulation;
private TimeSpan _smtcUpdateInterval;
private bool _playerSeekGesture;
private bool _playerVolumeGesture;

Expand Down Expand Up @@ -209,7 +210,7 @@ private void OnMediaFailed(IMediaPlayer sender, object? args)

private void OnPositionChanged(IMediaPlayer sender, object? args)
{
_transportControlsService.UpdatePlaybackPosition(sender.Position, TimeSpan.Zero, sender.NaturalDuration);
_transportControlsService.UpdatePlaybackPosition(sender.Position, TimeSpan.Zero, sender.NaturalDuration, _smtcUpdateInterval);
}

public void OnSizeChanged(object sender, SizeChangedEventArgs args)
Expand Down Expand Up @@ -290,6 +291,7 @@ private void LoadSettings()
{
_playerSeekGesture = _settingsService.PlayerSeekGesture;
_playerVolumeGesture = _settingsService.PlayerVolumeGesture;
_smtcUpdateInterval = TimeSpan.FromSeconds(_settingsService.SmtcUpdateInterval);
}

private void DisposeMediaPlayer()
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 @@ -32,6 +32,7 @@ public sealed partial class SettingsPageViewModel : ObservableRecipient
[ObservableProperty] private bool _searchRemovableStorage;
[ObservableProperty] private bool _advancedMode;
[ObservableProperty] private bool _useMultipleInstances;
[ObservableProperty] private double _smtcUpdateInterval;
[ObservableProperty] private string _globalArguments;
[ObservableProperty] private bool _isRelaunchRequired;

Expand Down Expand Up @@ -81,6 +82,7 @@ public SettingsPageViewModel(ISettingsService settingsService, ILibraryService l
_searchRemovableStorage = _settingsService.SearchRemovableStorage;
_advancedMode = _settingsService.AdvancedMode;
_useMultipleInstances = _settingsService.UseMultipleInstances;
_smtcUpdateInterval = _settingsService.SmtcUpdateInterval;
_globalArguments = _settingsService.GlobalArguments;
_originalAdvancedMode ??= _advancedMode;
_originalGlobalArguments ??= _globalArguments;
Expand Down Expand Up @@ -181,6 +183,12 @@ partial void OnUseMultipleInstancesChanged(bool value)
Messenger.Send(new SettingsChangedMessage(nameof(UseMultipleInstances), typeof(SettingsPageViewModel)));
}

partial void OnSmtcUpdateIntervalChanged(double value)
{
_settingsService.SmtcUpdateInterval = value;
Messenger.Send(new SettingsChangedMessage(nameof(SmtcUpdateInterval), typeof(SettingsPageViewModel)));
}

partial void OnGlobalArgumentsChanged(string value)
{
// No need to broadcast SettingsChangedMessage for this option
Expand Down
15 changes: 15 additions & 0 deletions Screenbox/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,21 @@
</ctc:SettingsExpander.Items>
</ctc:SettingsExpander>

<ctc:SettingsCard
Margin="{StaticResource SettingsCardMargin}"
Description="The default interval is 5 seconds"
Header="System Media Transport Controls (SMTC) update interval"
Visibility="{x:Bind helpers:SystemInformation.IsDesktop}">
<Slider
Width="150"
Maximum="6"
Minimum="1"
StepFrequency="1"
TickFrequency="1"
TickPlacement="Inline"
Value="{x:Bind ViewModel.SmtcUpdateInterval, Mode=TwoWay}" />
</ctc:SettingsCard>

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

Expand Down