Skip to content

Commit

Permalink
(#94) Make local playback port configurable instead of hardcoding 8000
Browse files Browse the repository at this point in the history
+ Windows UI
  • Loading branch information
Difegue committed Sep 4, 2024
1 parent d9756d2 commit b7d157f
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public partial class LocalPlaybackViewModel : ViewModelBase
private LibVLC _vlcCore;
private MediaPlayer _mediaPlayer;
private string _serverHost;
private int _serverPort;

public LocalPlaybackViewModel(SettingsViewModel settingsVm, MPDConnectionService mpdService, IInteropService interopService, INotificationService notificationService, IDispatcherService dispatcherService) : base(dispatcherService)
{
Expand All @@ -37,6 +38,9 @@ public LocalPlaybackViewModel(SettingsViewModel settingsVm, MPDConnectionService
if (e.PropertyName == nameof(_settingsVm.ServerHost))
_serverHost = _settingsVm.ServerHost;
if (e.PropertyName == nameof(_settingsVm.LocalPlaybackPort))
_serverPort = _settingsVm.LocalPlaybackPort;
};

// Run an idle loop in a spare thread to make sure the libVLC volume is always accurate
Expand All @@ -57,9 +61,10 @@ public LocalPlaybackViewModel(SettingsViewModel settingsVm, MPDConnectionService
});
}

public void Initialize(string host, bool isEnabled)
public void Initialize(string host, int port, bool isEnabled)
{
_serverHost = host;
_serverPort = port;
IsEnabled = isEnabled;
}

Expand Down Expand Up @@ -147,7 +152,7 @@ partial void OnIsPlayingChanged(bool value)
{
if (value && _serverHost != null && _mpdService.IsConnected)
{
var urlString = "http://" + _serverHost + ":8000";
var urlString = "http://" + _serverHost + ":" + _serverPort;
var streamUrl = new Uri(urlString);
var media = new Media(_vlcCore, streamUrl);

Expand Down
9 changes: 9 additions & 0 deletions Sources/Stylophone.Common/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public SettingsViewModel(MPDConnectionService mpdService, IApplicationStorageSer
[ObservableProperty]
private bool _isLocalPlaybackEnabled;

[ObservableProperty]
private int _localPlaybackPort;

partial void OnElementThemeChanged(Theme value)
{
Task.Run (async () => await _interop.SetThemeAsync(value));
Expand Down Expand Up @@ -123,6 +126,11 @@ partial void OnIsLocalPlaybackEnabledChanged(bool value)
_applicationStorageService.SetValue(nameof(IsLocalPlaybackEnabled), value);
}

partial void OnLocalPlaybackPortChanged(int value)
{
_applicationStorageService.SetValue(nameof(LocalPlaybackPort), value);
}


[RelayCommand]
private async Task ClearCacheAsync()
Expand Down Expand Up @@ -176,6 +184,7 @@ public async Task EnsureInstanceInitializedAsync()
_enableAnalytics = _applicationStorageService.GetValue(nameof(EnableAnalytics), true);
_isAlbumArtFetchingEnabled = _applicationStorageService.GetValue(nameof(IsAlbumArtFetchingEnabled), true);
_isLocalPlaybackEnabled = _applicationStorageService.GetValue<bool>(nameof(IsLocalPlaybackEnabled));
_localPlaybackPort = _applicationStorageService.GetValue(nameof(LocalPlaybackPort), 8000);

Enum.TryParse(_applicationStorageService.GetValue<string>(nameof(ElementTheme)), out _elementTheme);

Expand Down
18 changes: 18 additions & 0 deletions Sources/Stylophone.Localization/Strings/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Sources/Stylophone.Localization/Strings/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -488,4 +488,10 @@ Enabling this option will show a second volume slider to control local volume.</
<data name="SongPlaybackLabel" xml:space="preserve">
<value>Song playback</value>
</data>
<data name="SettingsLocalPlaybackPortHeader" xml:space="preserve">
<value>Stream port</value>
</data>
<data name="SettingsLocalPlaybackPortText" xml:space="preserve">
<value>Set this to the port of your server's httpd stream.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions Sources/Stylophone.Localization/Strings/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,10 @@ L'activation de cette option affichera un second slider pour contrôler le volum
<data name="SongPlaybackLabel" xml:space="preserve">
<value>Lecture de la piste</value>
</data>
<data name="SettingsLocalPlaybackPortHeader" xml:space="preserve">
<value>Port du stream </value>
</data>
<data name="SettingsLocalPlaybackPortText" xml:space="preserve">
<value>Ajustez ce paramètre pour correspondre au port de votre stream httpd sur le serveur.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions Sources/Stylophone.Localization/Strings/Resources.pt-PT.resx
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,10 @@ Ativando esta opção mostrará um segundo deslizador de volume para controlar o
<data name="SongPlaybackLabel" xml:space="preserve">
<value>Leitura da faixa</value>
</data>
<data name="SettingsLocalPlaybackPortHeader" xml:space="preserve">
<value>Porta do fluxo</value>
</data>
<data name="SettingsLocalPlaybackPortText" xml:space="preserve">
<value>Introduze a porta do fluxo httpd do seu servidor MPD aqui.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions Sources/Stylophone.Localization/Strings/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -488,4 +488,10 @@ Enabling this option will show a second volume slider to control local volume.</
<data name="SongPlaybackLabel" xml:space="preserve">
<value>Song playback</value>
</data>
<data name="SettingsLocalPlaybackPortHeader" xml:space="preserve">
<value>Stream port</value>
</data>
<data name="SettingsLocalPlaybackPortText" xml:space="preserve">
<value>Set this to the port of your server's httpd stream.</value>
</data>
</root>
3 changes: 2 additions & 1 deletion Sources/Stylophone/Activation/DefaultActivationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ private async Task StartupAsync()
var port = Ioc.Default.GetRequiredService<IApplicationStorageService>().GetValue<int>(nameof(SettingsViewModel.ServerPort), 6600);
var pass = Ioc.Default.GetRequiredService<IApplicationStorageService>().GetValue<string>(nameof(SettingsViewModel.ServerPassword));
var localPlaybackEnabled = Ioc.Default.GetRequiredService<IApplicationStorageService>().GetValue<bool>(nameof(SettingsViewModel.IsLocalPlaybackEnabled));
var localPlaybackPort = Ioc.Default.GetRequiredService<IApplicationStorageService>().GetValue<int>(nameof(SettingsViewModel.LocalPlaybackPort), 8000);

var localPlaybackVm = Ioc.Default.GetRequiredService<LocalPlaybackViewModel>();
localPlaybackVm.Initialize(host, localPlaybackEnabled);
localPlaybackVm.Initialize(host, localPlaybackPort, localPlaybackEnabled);

var mpdService = Ioc.Default.GetRequiredService<MPDConnectionService>();
mpdService.SetServerInfo(host, port, pass);
Expand Down
23 changes: 19 additions & 4 deletions Sources/Stylophone/Views/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,34 @@
</toolkit:SettingsExpander.ItemsFooter>
</toolkit:SettingsExpander>

<toolkit:SettingsCard
<toolkit:SettingsExpander
Header="{x:Bind strings:Resources.SettingsLocalPlaybackHeader}"
Description="{x:Bind strings:Resources.SettingsLocalPlaybackText}"
Visibility="{x:Bind ViewModel.IsStreamingAvailable, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}">
<toolkit:SettingsCard.HeaderIcon>
<toolkit:SettingsExpander.HeaderIcon>
<FontIcon Glyph="&#xE7F3;" />
</toolkit:SettingsCard.HeaderIcon>
</toolkit:SettingsExpander.HeaderIcon>

<ToggleSwitch
IsOn="{x:Bind ViewModel.IsLocalPlaybackEnabled, Mode=TwoWay}"
OffContent=""
OnContent="" />
</toolkit:SettingsCard>

<toolkit:SettingsExpander.ItemsFooter>
<toolkit:SettingsCard CornerRadius="0" Margin="-1,0"
Header="{x:Bind strings:Resources.SettingsLocalPlaybackPortHeader}"
Description="{x:Bind strings:Resources.SettingsLocalPlaybackPortText}">
<controls:NumberBox
Width="128"
Margin="0,-8"
Maximum="65536"
Minimum="1"
PlaceholderText="8000"
SpinButtonPlacementMode="Compact"
Value="{x:Bind ViewModel.LocalPlaybackPort, Mode=TwoWay}" />
</toolkit:SettingsCard>
</toolkit:SettingsExpander.ItemsFooter>
</toolkit:SettingsExpander>

<!-- DB/Art -->

Expand Down

0 comments on commit b7d157f

Please sign in to comment.