From 3648b3899cc994ab232375deffeb98b7be5a87d4 Mon Sep 17 00:00:00 2001 From: Anton Fedchin Date: Thu, 18 Jan 2018 17:18:28 +0300 Subject: [win10] make the uwp app working in background and handles media buttons. --- .../windows/packaging/uwp/package.appxmanifest.in | 4 +- xbmc/windowing/win10/WinEventsWin10.cpp | 55 ++++++++++++++++++++++ xbmc/windowing/win10/WinEventsWin10.h | 3 ++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/tools/windows/packaging/uwp/package.appxmanifest.in b/tools/windows/packaging/uwp/package.appxmanifest.in index c4bf60359b..1b4a619151 100644 --- a/tools/windows/packaging/uwp/package.appxmanifest.in +++ b/tools/windows/packaging/uwp/package.appxmanifest.in @@ -3,7 +3,8 @@ xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" - IgnorableNamespaces="uap mp"> + xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" + IgnorableNamespaces="mp uap uap3"> @@ -234,5 +235,6 @@ + \ No newline at end of file diff --git a/xbmc/windowing/win10/WinEventsWin10.cpp b/xbmc/windowing/win10/WinEventsWin10.cpp index 7fd1918b29..a90345f081 100644 --- a/xbmc/windowing/win10/WinEventsWin10.cpp +++ b/xbmc/windowing/win10/WinEventsWin10.cpp @@ -31,6 +31,7 @@ #include "utils/log.h" #include "utils/SystemInfo.h" #include "windowing/windows/WinKeyMap.h" +#include "xbmc/GUIUserMessages.h" #include "WinEventsWin10.h" using namespace PERIPHERALS; @@ -38,6 +39,7 @@ using namespace KODI::MESSAGING; using namespace Windows::Devices::Input; using namespace Windows::Foundation; using namespace Windows::Graphics::Display; +using namespace Windows::Media; using namespace Windows::System; using namespace Windows::UI::Core; using namespace Windows::UI::Input; @@ -134,6 +136,17 @@ void CWinEventsWin10::InitEventHandlers(CoreWindow^ window) // system SystemNavigationManager^ sysNavManager = SystemNavigationManager::GetForCurrentView(); sysNavManager->BackRequested += ref new EventHandler(CWinEventsWin10::OnBackRequested); + // requirement for backgroup playback + m_smtc = SystemMediaTransportControls::GetForCurrentView(); + if (m_smtc) + { + m_smtc->IsPlayEnabled = true; + m_smtc->IsPauseEnabled = true; + m_smtc->IsStopEnabled = true; + m_smtc->ButtonPressed += ref new TypedEventHandler + (CWinEventsWin10::OnSystemMediaButtonPressed); + m_smtc->IsEnabled = true; + } } void CWinEventsWin10::UpdateWindowSize() @@ -466,3 +479,45 @@ void CWinEventsWin10::OnBackRequested(Platform::Object^ sender, Windows::UI::Cor } args->Handled = true; } + +void CWinEventsWin10::OnSystemMediaButtonPressed(SystemMediaTransportControls^ sender, SystemMediaTransportControlsButtonPressedEventArgs^ args) +{ + int action = ACTION_NONE; + switch (args->Button) + { + case SystemMediaTransportControlsButton::ChannelDown: + action = ACTION_CHANNEL_DOWN; + break; + case SystemMediaTransportControlsButton::ChannelUp: + action = ACTION_CHANNEL_UP; + break; + case SystemMediaTransportControlsButton::FastForward: + action = ACTION_PLAYER_FORWARD; + break; + case SystemMediaTransportControlsButton::Rewind: + action = ACTION_PLAYER_REWIND; + break; + case SystemMediaTransportControlsButton::Next: + action = ACTION_NEXT_ITEM; + break; + case SystemMediaTransportControlsButton::Previous: + action = ACTION_PREV_ITEM; + break; + case SystemMediaTransportControlsButton::Pause: + case SystemMediaTransportControlsButton::Play: + action = ACTION_PLAYER_PLAYPAUSE; + break; + case SystemMediaTransportControlsButton::Stop: + action = ACTION_STOP; + break; + case SystemMediaTransportControlsButton::Record: + action = ACTION_RECORD; + break; + default: + break; + } + if (action != ACTION_NONE) + { + CApplicationMessenger::GetInstance().PostMsg(TMSG_GUI_ACTION, WINDOW_INVALID, -1, static_cast(new CAction(action))); + } +} diff --git a/xbmc/windowing/win10/WinEventsWin10.h b/xbmc/windowing/win10/WinEventsWin10.h index ec08d97cbb..5c7d38c3cc 100644 --- a/xbmc/windowing/win10/WinEventsWin10.h +++ b/xbmc/windowing/win10/WinEventsWin10.h @@ -57,11 +57,14 @@ public: static void OnDisplayContentsInvalidated(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); // system static void OnBackRequested(Platform::Object^ sender, Windows::UI::Core::BackRequestedEventArgs^ args); + // system media handlers + static void OnSystemMediaButtonPressed(Windows::Media::SystemMediaTransportControls^, Windows::Media::SystemMediaTransportControlsButtonPressedEventArgs^); private: void UpdateWindowSize(); void Kodi_KeyEvent(unsigned int vkey, unsigned scancode, unsigned keycode, bool isDown); Concurrency::concurrent_queue m_events; + Windows::Media::SystemMediaTransportControls^ m_smtc{ nullptr }; }; #endif // WINDOW_EVENTS_WIN10_H -- cgit v1.2.3