feat: stream live to laut.fm and import from its library
The Settings page gets a laut.fm card: a switch, the live access data from Radioadmin (server, port, mountpoint, user, password) and the station id and Radioadmin token for the library. Password and token are written to settings.json encrypted with DPAPI for the Windows user. While laut.fm is on, the Schedule page shows a Live button next to "Jetzt starten". It logs in at the Icecast server with PUT and sends a copy of the broadcast mix as MP3 at 128 kbit/s, encoded by Windows Media Foundation. ProgramOutput hands that copy out through a live feed. Each item that starts sets the stream title; ad items send START_AD_BREAK at most once every 15 minutes. LautFmProvider searches the station's tracks through the Radioadmin API and the Import page lists it while laut.fm is on, so laut.fm tracks are imported into the same library as local songs. Providers can now hide themselves with IsAvailable. Nothing was tested against a real laut.fm account; the tests use a local fake server and fake HTTP answers. Refs #15 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5d261717fe
commit
a94fb862d2
16 files changed
+999
-16
No files matched your search
@@ -31,10 +31,12 @@ public partial class SchedulePage : Page
|
||||
|
||||
private readonly Microphone _microphone;
|
||||
private readonly ProgramMixer _mixer;
|
||||
private readonly LiveController _live;
|
||||
|
||||
public SchedulePage(ScheduleController controller, Microphone microphone, ProgramOutput output)
|
||||
public SchedulePage(ScheduleController controller, Microphone microphone, ProgramOutput output, LiveController live)
|
||||
{
|
||||
_controller = controller;
|
||||
_live = live;
|
||||
_microphone = microphone;
|
||||
_mixer = output.Mixer;
|
||||
InitializeComponent();
|
||||
@@ -53,6 +55,7 @@ public partial class SchedulePage : Page
|
||||
_controller.ItemStarted += OnItemStarted;
|
||||
_controller.ItemFailed += OnItemFailed;
|
||||
_controller.Finished += OnFinished;
|
||||
_live.Problem += OnLiveProblem;
|
||||
|
||||
_loading = true;
|
||||
VolumeSlider.Value = _controller.Volume;
|
||||
@@ -63,6 +66,7 @@ public partial class SchedulePage : Page
|
||||
MusicForMeSlider.IsEnabled = !_mixer.ListenToBroadcast;
|
||||
_loading = false;
|
||||
ShowMicrophone(); // it stays on while the user visits other pages
|
||||
ShowLive();
|
||||
FillStartTimes();
|
||||
if (_controller.Plan.Count > 0)
|
||||
UnlimitedBox.IsChecked = _controller.IsUnlimited;
|
||||
@@ -82,6 +86,7 @@ public partial class SchedulePage : Page
|
||||
_controller.ItemStarted -= OnItemStarted;
|
||||
_controller.ItemFailed -= OnItemFailed;
|
||||
_controller.Finished -= OnFinished;
|
||||
_live.Problem -= OnLiveProblem;
|
||||
_progressTimer.Stop();
|
||||
}
|
||||
|
||||
@@ -216,6 +221,47 @@ public partial class SchedulePage : Page
|
||||
System.Windows.Automation.AutomationProperties.SetName(MicButton, on ? "Mikrofon ausschalten, es ist auf Sendung" : "Mikrofon einschalten");
|
||||
}
|
||||
|
||||
private async void OnLiveToggle(object sender, RoutedEventArgs e)
|
||||
{
|
||||
LiveButton.IsEnabled = false;
|
||||
try
|
||||
{
|
||||
if (_live.IsLive)
|
||||
{
|
||||
await Task.Run(_live.Stop);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Opening the devices and the connection can take a moment, so it runs off the UI thread.
|
||||
await Task.Run(() => _live.StartAsync());
|
||||
Message.IsOpen = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is LiveStreamException or NAudio.MmException)
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Error, "Live nicht möglich", ex.Message);
|
||||
}
|
||||
LiveButton.IsEnabled = true;
|
||||
ShowLive();
|
||||
}
|
||||
|
||||
// Comes from a background thread; the stream may have ended.
|
||||
private void OnLiveProblem(object? sender, string message) => Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Warning, "laut.fm", message);
|
||||
ShowLive();
|
||||
});
|
||||
|
||||
private void ShowLive()
|
||||
{
|
||||
var live = _live.IsLive;
|
||||
// Stays visible while live, so a stream can be stopped after laut.fm was switched off.
|
||||
LiveButton.Visibility = _live.IsEnabled || live ? Visibility.Visible : Visibility.Collapsed;
|
||||
LiveButton.Content = live ? "Live beenden" : "Live";
|
||||
LiveButton.Appearance = live ? ControlAppearance.Danger : ControlAppearance.Secondary;
|
||||
System.Windows.Automation.AutomationProperties.SetName(LiveButton, live ? "Livestream zu laut.fm beenden, er läuft" : "Livestream zu laut.fm starten");
|
||||
}
|
||||
|
||||
private void OnEndNow(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in new issue
Block a user