First POC for a radio browser
This commit is contained in:
parent
4d180871ca
commit
fbb65a039a
@ -12,6 +12,7 @@ using System.Windows.Threading;
|
||||
using MpcNET;
|
||||
using MpcNET.Commands.Database;
|
||||
using MpcNET.Commands.Playback;
|
||||
using MpcNET.Commands.Queue;
|
||||
using MpcNET.Commands.Status;
|
||||
using MpcNET.Message;
|
||||
using MpcNET.Types;
|
||||
@ -439,5 +440,14 @@ namespace unison
|
||||
_currentVolume = 0;
|
||||
SetVolume(_currentVolume);
|
||||
}
|
||||
|
||||
public void ClearQueue() => SendCommand(new ClearCommand());
|
||||
public void PlayCommand() => SendCommand(new PlayCommand(0));
|
||||
|
||||
public void AddSong(string Uri)
|
||||
{
|
||||
Debug.WriteLine("AddCommand path: " + Uri);
|
||||
SendCommand(new AddCommand(Uri));
|
||||
}
|
||||
}
|
||||
}
|
@ -110,12 +110,20 @@
|
||||
</Border>
|
||||
</Grid>
|
||||
<Grid x:Name="BottomLayout" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}" Width="Auto" MinHeight="40">
|
||||
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Center" Margin="0,0,10,0">
|
||||
<Button x:Name="Snapcast" HorizontalAlignment="Left" VerticalAlignment="Center" Click="Snapcast_Clicked" Margin="10,0,0,0" Padding="5, 2" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" FocusVisualStyle="{x:Null}" IsEnabled="False">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<emoji:TextBlock Text="🔊" Padding="0,0,0,2"/>
|
||||
<TextBlock x:Name="SnapcastText" Text="{x:Static properties:Resources.StartSnapcast}" Margin="5, 0, 0, 0"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
<Button x:Name="Radio" Padding="5, 2" HorizontalAlignment="Left" Click="Radios_Clicked" Margin="5,0,10,0" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<emoji:TextBlock Text="📻" Padding="0,0,0,2"/>
|
||||
<TextBlock Text="Radios" Margin="5, 0, 0, 0"/>
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<Grid x:Name="ConnectionOkIcon" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<TextBlock FontFamily="Segoe MDL2 Assets" Text="" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" VerticalAlignment="Center" HorizontalAlignment="Center" />
|
||||
|
@ -12,6 +12,7 @@ namespace unison
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private readonly Settings _settingsWin;
|
||||
private readonly Radios _radiosWin;
|
||||
private readonly DispatcherTimer _timer;
|
||||
private readonly MPDHandler _mpd;
|
||||
|
||||
@ -23,6 +24,7 @@ namespace unison
|
||||
WindowState = WindowState.Minimized;
|
||||
|
||||
_settingsWin = new Settings();
|
||||
_radiosWin = new Radios();
|
||||
_timer = new DispatcherTimer();
|
||||
_mpd = (MPDHandler)Application.Current.Properties["mpd"];
|
||||
|
||||
@ -214,6 +216,15 @@ namespace unison
|
||||
snapcast.LaunchOrExit();
|
||||
}
|
||||
|
||||
public async void Radios_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_radiosWin.Show();
|
||||
_radiosWin.Activate();
|
||||
|
||||
if (_radiosWin.WindowState == WindowState.Minimized)
|
||||
_radiosWin.WindowState = WindowState.Normal;
|
||||
}
|
||||
|
||||
public void Settings_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_settingsWin.Show();
|
||||
|
22
Views/Radios.xaml
Normal file
22
Views/Radios.xaml
Normal file
@ -0,0 +1,22 @@
|
||||
<Window x:Class="unison.Radios"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:unison"
|
||||
mc:Ignorable="d"
|
||||
Title="Radios" Closing="Window_Closing" SizeToContent="WidthAndHeight">
|
||||
<Grid>
|
||||
<StackPanel HorizontalAlignment="Left" Orientation="Vertical">
|
||||
|
||||
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="5,5,0,0">
|
||||
<TextBox x:Name="SearchBar" Text="fip" TextWrapping="Wrap" HorizontalAlignment="Left" Width="200"/>
|
||||
<Button Content="Search" Click="Search_Clicked" Margin="5,0,0,0"/>
|
||||
</StackPanel>
|
||||
|
||||
|
||||
<ListView x:Name="lvDataBinding" SelectionChanged="SelectionChanged" Width="400" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5,10,5,5"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
107
Views/Radios.xaml.cs
Normal file
107
Views/Radios.xaml.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using RadioBrowser;
|
||||
using RadioBrowser.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace unison
|
||||
{
|
||||
public class StationView : StationInfo
|
||||
{
|
||||
public StationView(string _name, Uri _url, int _bitrate, string _codec, string _country, Uri _favicon)
|
||||
{
|
||||
Name = _name;
|
||||
Url = _url;
|
||||
Bitrate = _bitrate;
|
||||
Codec = _codec;
|
||||
CountryCode = _country;
|
||||
Favicon = _favicon;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{this.Name} - {this.Bitrate} - {this.Codec} - {this.CountryCode}";
|
||||
}
|
||||
}
|
||||
|
||||
public partial class Radios : Window
|
||||
{
|
||||
RadioBrowserClient _radioBrowser;
|
||||
List<StationView> _stations = new List<StationView>();
|
||||
|
||||
private MPDHandler _mpd;
|
||||
|
||||
public Radios()
|
||||
{
|
||||
InitializeComponent();
|
||||
_radioBrowser = new RadioBrowserClient();
|
||||
}
|
||||
|
||||
public async Task Search(string name)
|
||||
{
|
||||
var searchByName = await _radioBrowser.Search.ByNameAsync(name);
|
||||
Debug.WriteLine(searchByName.FirstOrDefault()?.Name);
|
||||
Debug.WriteLine("");
|
||||
}
|
||||
|
||||
public async Task SearchAdvanced(string name)
|
||||
{
|
||||
Debug.Write(name);
|
||||
|
||||
_stations.Clear();
|
||||
var advancedSearch = await _radioBrowser.Search.AdvancedAsync(new AdvancedSearchOptions
|
||||
{
|
||||
Name = name
|
||||
});
|
||||
foreach (var station in advancedSearch)
|
||||
_stations.Add(new StationView(station.Name, station.Url, station.Bitrate, station.Codec, station.CountryCode, station.Favicon));
|
||||
lvDataBinding.ItemsSource = _stations;
|
||||
ICollectionView view = CollectionViewSource.GetDefaultView(_stations);
|
||||
view.Refresh();
|
||||
|
||||
Debug.WriteLine(_stations[0].Url.AbsoluteUri);
|
||||
}
|
||||
|
||||
private void SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
Debug.WriteLine("Selected: {0}", e.AddedItems[0]);
|
||||
|
||||
_mpd = (MPDHandler)Application.Current.Properties["mpd"];
|
||||
_mpd.ClearQueue();
|
||||
|
||||
StationView station = (StationView)e.AddedItems[0];
|
||||
_mpd.AddSong(station.Url.AbsoluteUri);
|
||||
_mpd.PlayCommand();
|
||||
}
|
||||
|
||||
public List<StationView> GetStations()
|
||||
{
|
||||
return _stations;
|
||||
}
|
||||
|
||||
private async void Search_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await SearchAdvanced(SearchBar.Text);
|
||||
}
|
||||
|
||||
private void Window_Closing(object sender, CancelEventArgs e)
|
||||
{
|
||||
e.Cancel = true;
|
||||
WindowState = WindowState.Minimized;
|
||||
Hide();
|
||||
}
|
||||
|
||||
public void InitHwnd()
|
||||
{
|
||||
WindowInteropHelper helper = new(this);
|
||||
helper.EnsureHandle();
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
<ApplicationIcon>Resources\icon-full.ico</ApplicationIcon>
|
||||
<Win32Resource></Win32Resource>
|
||||
<StartupObject>unison.App</StartupObject>
|
||||
<Version>1.0</Version>
|
||||
<Version>1.1</Version>
|
||||
<Company />
|
||||
<Authors>Théo Marchal</Authors>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
@ -74,6 +74,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Emoji.Wpf" Version="0.3.3" />
|
||||
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
|
||||
<PackageReference Include="RadioBrowser" Version="0.6.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user