Hook up the buttons
This commit is contained in:
parent
e286eb66f3
commit
3f895d93e7
|
@ -1,6 +1,7 @@
|
|||
#include "pch.h"
|
||||
#include "MediaControlHost.h"
|
||||
#include "MediaControlHost.g.cpp"
|
||||
using namespace winrt::Windows::Foundation;
|
||||
using namespace winrt::Windows::UI::Xaml;
|
||||
using namespace winrt::Windows::UI::Core;
|
||||
using namespace winrt::Windows::Media;
|
||||
|
@ -13,10 +14,9 @@ namespace winrt::TerminalApp::implementation
|
|||
auto media = mediaAsync.get();
|
||||
auto artist = media.AlbumArtist();
|
||||
auto title = media.Title();
|
||||
std::wstring realTitle = title.c_str();
|
||||
std::wstring realArtist = artist.c_str();
|
||||
|
||||
auto info = session.GetPlaybackInfo();
|
||||
_playbackState = info.PlaybackStatus();
|
||||
|
||||
Dispatcher().RunAsync(CoreDispatcherPriority::Normal, [this, artist, title, info]() {
|
||||
_Title().Text(title);
|
||||
|
@ -45,19 +45,6 @@ namespace winrt::TerminalApp::implementation
|
|||
{
|
||||
_UpdateMediaInfo(session);
|
||||
|
||||
auto mediaAsync = session.TryGetMediaPropertiesAsync();
|
||||
auto media = mediaAsync.get();
|
||||
auto info = session.GetPlaybackInfo();
|
||||
auto status = info.PlaybackStatus();
|
||||
|
||||
if (status == Control::GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing)
|
||||
{
|
||||
_PlayPauseIcon().Glyph(L"");
|
||||
}
|
||||
else if (status == Control::GlobalSystemMediaTransportControlsSessionPlaybackStatus::Paused)
|
||||
{
|
||||
_PlayPauseIcon().Glyph(L"");
|
||||
}
|
||||
}
|
||||
|
||||
fire_and_forget MediaControlHost::_SetupMediaManager()
|
||||
|
@ -86,6 +73,10 @@ namespace winrt::TerminalApp::implementation
|
|||
{
|
||||
InitializeComponent();
|
||||
|
||||
_PreviousButton().Click({ this, &MediaControlHost::_PreviousClick });
|
||||
_PlayPauseButton().Click({ this, &MediaControlHost::_PlayPauseClick });
|
||||
_NextButton().Click({ this, &MediaControlHost::_NextClick });
|
||||
|
||||
Loaded([this](auto&&, auto&&) {
|
||||
_SetupMediaManager();
|
||||
});
|
||||
|
@ -122,6 +113,63 @@ namespace winrt::TerminalApp::implementation
|
|||
_PlayPauseButton().Focus(FocusState::Programmatic);
|
||||
}
|
||||
|
||||
void MediaControlHost::_PreviousClick(IInspectable const& sender,
|
||||
RoutedEventArgs const& e)
|
||||
{
|
||||
_DispatchPreviousClick();
|
||||
}
|
||||
void MediaControlHost::_NextClick(IInspectable const& sender,
|
||||
RoutedEventArgs const& e)
|
||||
{
|
||||
_DispatchNextClick();
|
||||
}
|
||||
void MediaControlHost::_PlayPauseClick(IInspectable const& sender,
|
||||
RoutedEventArgs const& e)
|
||||
{
|
||||
_DispatchPlayPauseClick();
|
||||
}
|
||||
|
||||
fire_and_forget MediaControlHost::_DispatchPreviousClick()
|
||||
{
|
||||
co_await winrt::resume_background();
|
||||
if (_session)
|
||||
{
|
||||
if (_playbackState == Control::GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing)
|
||||
{
|
||||
_session.TrySkipPreviousAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fire_and_forget MediaControlHost::_DispatchNextClick()
|
||||
{
|
||||
co_await winrt::resume_background();
|
||||
if (_session)
|
||||
{
|
||||
if (_playbackState == Control::GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing)
|
||||
{
|
||||
_session.TrySkipNextAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fire_and_forget MediaControlHost::_DispatchPlayPauseClick()
|
||||
{
|
||||
co_await winrt::resume_background();
|
||||
if (_session)
|
||||
{
|
||||
auto foo = _playbackState;
|
||||
if (_playbackState == Control::GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing)
|
||||
{
|
||||
_session.TryPauseAsync();
|
||||
}
|
||||
else if (_playbackState == Control::GlobalSystemMediaTransportControlsSessionPlaybackStatus::Paused)
|
||||
{
|
||||
_session.TryPlayAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MediaControlHost, CloseRequested, _closeRequestedHandlers, TerminalApp::IControlHost, TerminalApp::ClosedEventArgs);
|
||||
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MediaControlHost, TitleChanged, _titleChangedHandlers, TerminalApp::IControlHost, Microsoft::Terminal::TerminalControl::TitleChangedEventArgs);
|
||||
}
|
||||
|
|
|
@ -22,17 +22,31 @@ namespace winrt::TerminalApp::implementation
|
|||
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(CloseRequested, _closeRequestedHandlers, TerminalApp::IControlHost, TerminalApp::ClosedEventArgs);
|
||||
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(TitleChanged, _titleChangedHandlers, TerminalApp::IControlHost, Microsoft::Terminal::TerminalControl::TitleChangedEventArgs);
|
||||
|
||||
void _PreviousClick(winrt::Windows::Foundation::IInspectable const& sender,
|
||||
winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
|
||||
void _NextClick(winrt::Windows::Foundation::IInspectable const& sender,
|
||||
winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
|
||||
void _PlayPauseClick(winrt::Windows::Foundation::IInspectable const& sender,
|
||||
winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
|
||||
|
||||
private:
|
||||
winrt::Windows::Media::Control::GlobalSystemMediaTransportControlsSession _session{ nullptr };
|
||||
// winrt::Windows::UI::Xaml::Controls::RichEditBox _textBox{ nullptr };
|
||||
Windows::Media::Control::GlobalSystemMediaTransportControlsSessionPlaybackStatus _playbackState{ Windows::Media::Control::GlobalSystemMediaTransportControlsSessionPlaybackStatus::Closed };
|
||||
|
||||
fire_and_forget _SetupMediaManager();
|
||||
|
||||
void _MediaPropertiesChanged(winrt::Windows::Media::Control::GlobalSystemMediaTransportControlsSession session,
|
||||
winrt::Windows::Media::Control::MediaPropertiesChangedEventArgs args);
|
||||
void _PlaybackInfoChanged(winrt::Windows::Media::Control::GlobalSystemMediaTransportControlsSession session,
|
||||
winrt::Windows::Media::Control::PlaybackInfoChangedEventArgs args);
|
||||
// void _TimelinePropertiesChanged(winrt::Windows::Media::Control::GlobalSystemMediaTransportControlsSession session,
|
||||
// winrt::Windows::Media::Control::MediaPropertiesChangedEventArgs args);
|
||||
|
||||
void _UpdateMediaInfo(winrt::Windows::Media::Control::GlobalSystemMediaTransportControlsSession session);
|
||||
|
||||
fire_and_forget _DispatchPreviousClick();
|
||||
fire_and_forget _DispatchNextClick();
|
||||
fire_and_forget _DispatchPlayPauseClick();
|
||||
};
|
||||
}
|
||||
namespace winrt::TerminalApp::factory_implementation
|
||||
|
|
|
@ -10,10 +10,10 @@ the MIT License. See LICENSE in the project root for license information. -->
|
|||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:Name="_Root"
|
||||
Background="{ThemeResource SystemChromeLowColor}"
|
||||
VerticalAlignment="Stretch"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
@ -34,37 +34,40 @@ the MIT License. See LICENSE in the project root for license information. -->
|
|||
</Button>
|
||||
</RelativePanel>
|
||||
|
||||
<StackPanel Grid.Row="1">
|
||||
<StackPanel
|
||||
x:Name="_Buttons"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
|
||||
<RichEditBox x:Name="_Editor"
|
||||
Grid.Row="1"
|
||||
Height="100"
|
||||
/>
|
||||
<StackPanel.Resources>
|
||||
<Style TargetType="Button">
|
||||
<Setter Property="Background" Value="Transparent"></Setter>
|
||||
</Style>
|
||||
</StackPanel.Resources>
|
||||
|
||||
<StackPanel x:Name="_Buttons" Grid.Row="1" Orientation="Horizontal">
|
||||
<Button x:Name="_PreviousButton">
|
||||
<Button.Content>
|
||||
<Button x:Name="_PreviousButton">
|
||||
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
<Button x:Name="_PlayPauseButton">
|
||||
<Button.Content>
|
||||
</Button>
|
||||
<Button x:Name="_PlayPauseButton">
|
||||
<!-- Pause is xE769 -->
|
||||
<FontIcon x:Name="_PlayPauseIcon" FontFamily="Segoe MDL2 Assets" Glyph=""/>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
<Button x:Name="_NextButton">
|
||||
<Button.Content>
|
||||
</Button>
|
||||
<Button x:Name="_NextButton">
|
||||
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
</Button>
|
||||
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="2">
|
||||
<TextBlock x:Name="_Title">
|
||||
<TextBlock
|
||||
TextWrapping="WrapWholeWords"
|
||||
HorizontalAlignment="Center" x:Name="_Title" FontSize="20">
|
||||
Title
|
||||
</TextBlock>
|
||||
<TextBlock x:Name="_Band">
|
||||
<TextBlock
|
||||
TextWrapping="WrapWholeWords"
|
||||
HorizontalAlignment="Center" x:Name="_Band">
|
||||
Band
|
||||
</TextBlock>
|
||||
|
||||
|
|
Loading…
Reference in a new issue