diff options
-rw-r--r-- | support/hololens/ServoApp/BrowserPage.cpp | 14 | ||||
-rw-r--r-- | support/hololens/ServoApp/BrowserPage.xaml | 6 | ||||
-rw-r--r-- | support/hololens/ServoApp/ServoControl/Servo.cpp | 16 | ||||
-rw-r--r-- | support/hololens/ServoApp/ServoControl/Servo.h | 2 | ||||
-rw-r--r-- | support/hololens/ServoApp/ServoControl/ServoControl.cpp | 9 | ||||
-rw-r--r-- | support/hololens/ServoApp/ServoControl/ServoControl.h | 23 | ||||
-rw-r--r-- | support/hololens/ServoApp/ServoControl/ServoControl.idl | 3 |
7 files changed, 69 insertions, 4 deletions
diff --git a/support/hololens/ServoApp/BrowserPage.cpp b/support/hololens/ServoApp/BrowserPage.cpp index 6653ebb233a..536f1f378b1 100644 --- a/support/hololens/ServoApp/BrowserPage.cpp +++ b/support/hololens/ServoApp/BrowserPage.cpp @@ -70,6 +70,20 @@ void BrowserPage::BindServoEvents() { servoControl().OnCaptureGesturesEnded( [=] { navigationBar().IsHitTestVisible(true); }); urlTextbox().GotFocus(std::bind(&BrowserPage::OnURLFocused, this, _1)); + servoControl().OnMediaSessionMetadata( + [=](hstring title, hstring artist, hstring album) {}); + servoControl().OnMediaSessionPlaybackStateChange([=](const auto &, + int state) { + if (state == 1 /* none */) { + mediaControls().Visibility(Visibility::Collapsed); + return; + } + mediaControls().Visibility(Visibility::Visible); + playButton().Visibility(state == 3 /* paused */ ? Visibility::Visible + : Visibility::Collapsed); + pauseButton().Visibility(state == 3 /* paused */ ? Visibility::Collapsed + : Visibility::Visible); + }); } void BrowserPage::OnURLFocused(Windows::Foundation::IInspectable const &) { diff --git a/support/hololens/ServoApp/BrowserPage.xaml b/support/hololens/ServoApp/BrowserPage.xaml index 8d68ecf533b..727e73e11cc 100644 --- a/support/hololens/ServoApp/BrowserPage.xaml +++ b/support/hololens/ServoApp/BrowserPage.xaml @@ -137,9 +137,9 @@ <Button Margin="0,10,10,0" Click="OnXRPkgWarningDismissClick">Dismiss</Button> </StackPanel> </StackPanel> - <CommandBar Grid.Row="3" Visibility="Collapsed"> - <AppBarButton Icon="Play" Label="Play" Click="OnMediaControlsPlayClicked"/> - <AppBarButton Icon="Pause" Label="Pause" Click="OnMediaControlsPauseClicked"/> + <CommandBar Grid.Row="3" x:Name="mediaControls" Visibility="Collapsed"> + <AppBarButton Icon="Play" Label="Play" x:Name="playButton" Visibility="Collapsed" Click="OnMediaControlsPlayClicked"/> + <AppBarButton Icon="Pause" Label="Pause" x:Name="pauseButton" Click="OnMediaControlsPauseClicked"/> <CommandBar.Content> <TextBlock Text="Now playing..." Margin="12,14"/> diff --git a/support/hololens/ServoApp/ServoControl/Servo.cpp b/support/hololens/ServoApp/ServoControl/Servo.cpp index 8c66e8cdeb3..afe3539efe9 100644 --- a/support/hololens/ServoApp/ServoControl/Servo.cpp +++ b/support/hololens/ServoApp/ServoControl/Servo.cpp @@ -56,6 +56,16 @@ const char *get_clipboard_contents() { return nullptr; } +void on_media_session_metadata(const char *title, const char *album, + const char *artist) { + return sServo->Delegate().OnServoMediaSessionMetadata( + char2hstring(title), char2hstring(album), char2hstring(artist)); +} + +void on_media_session_playback_state_change(const int state) { + return sServo->Delegate().OnServoMediaSessionPlaybackStateChange(state); +} + Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height, float dpi, ServoDelegate &aDelegate) : mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) { @@ -63,7 +73,8 @@ Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height, capi::CInitOptions o; hstring defaultPrefs = L" --pref dom.webxr.enabled"; o.args = *hstring2char(args + defaultPrefs); - o.url = *hstring2char(url); + o.url = + "https://ferjm.github.io/web-api-tests/video/mp4.html"; //*hstring2char(url); o.width = mWindowWidth; o.height = mWindowHeight; o.density = dpi; @@ -110,6 +121,9 @@ Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height, c.on_ime_state_changed = &on_ime_state_changed; c.get_clipboard_contents = &get_clipboard_contents; c.set_clipboard_contents = &set_clipboard_contents; + c.on_media_session_metadata = &on_media_session_metadata; + c.on_media_session_playback_state_change = + &on_media_session_playback_state_change; capi::register_panic_handler(&on_panic); diff --git a/support/hololens/ServoApp/ServoControl/Servo.h b/support/hololens/ServoApp/ServoControl/Servo.h index 5cf4e113e33..2e76256f021 100644 --- a/support/hololens/ServoApp/ServoControl/Servo.h +++ b/support/hololens/ServoApp/ServoControl/Servo.h @@ -36,6 +36,8 @@ public: virtual void OnServoIMEStateChanged(bool) = 0; virtual void Flush() = 0; virtual void MakeCurrent() = 0; + virtual void OnServoMediaSessionMetadata(hstring, hstring, hstring) = 0; + virtual void OnServoMediaSessionPlaybackStateChange(int) = 0; protected: virtual ~ServoDelegate(){}; diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.cpp b/support/hololens/ServoApp/ServoControl/ServoControl.cpp index 38cc4f284f4..d1d19118a29 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.cpp +++ b/support/hololens/ServoApp/ServoControl/ServoControl.cpp @@ -432,6 +432,15 @@ void ServoControl::OnServoIMEStateChanged(bool aShow) { // https://docs.microsoft.com/en-us/windows/win32/winauto/uiauto-implementingtextandtextrange } +void ServoControl::OnServoMediaSessionMetadata(hstring title, hstring artist, + hstring album) { + RunOnUIThread([=] { mOnMediaSessionMetadataEvent(title, artist, album); }); +} + +void ServoControl::OnServoMediaSessionPlaybackStateChange(int state) { + RunOnUIThread([=] { mOnMediaSessionPlaybackStateChangeEvent(*this, state); }); +} + template <typename Callable> void ServoControl::RunOnUIThread(Callable cb) { Dispatcher().RunAsync(CoreDispatcherPriority::High, cb); } diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.h b/support/hololens/ServoApp/ServoControl/ServoControl.h index fea53fdb5bb..5daa227f126 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.h +++ b/support/hololens/ServoApp/ServoControl/ServoControl.h @@ -70,6 +70,23 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate { mOnCaptureGesturesEndedEvent.remove(token); } + winrt::event_token + OnMediaSessionMetadata(MediaSessionMetadataDelegate const &handler) { + return mOnMediaSessionMetadataEvent.add(handler); + }; + void OnMediaSessionMetadata(winrt::event_token const &token) noexcept { + mOnMediaSessionMetadataEvent.remove(token); + } + + winrt::event_token OnMediaSessionPlaybackStateChange( + Windows::Foundation::EventHandler<int> const &handler) { + return mOnMediaSessionPlaybackStateChangeEvent.add(handler); + }; + void + OnMediaSessionPlaybackStateChange(winrt::event_token const &token) noexcept { + mOnMediaSessionPlaybackStateChangeEvent.remove(token); + } + void SetTransientMode(bool transient) { mTransient = transient; } void SetArgs(hstring args) { mArgs = args; } @@ -87,6 +104,9 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate { virtual bool OnServoAllowNavigation(winrt::hstring); virtual void OnServoAnimatingChanged(bool); virtual void OnServoIMEStateChanged(bool); + virtual void OnServoMediaSessionMetadata(winrt::hstring, winrt::hstring, + winrt::hstring); + virtual void OnServoMediaSessionPlaybackStateChange(int); private: winrt::event<Windows::Foundation::EventHandler<hstring>> mOnURLChangedEvent; @@ -96,6 +116,9 @@ private: winrt::event<EventDelegate> mOnLoadEndedEvent; winrt::event<EventDelegate> mOnCaptureGesturesStartedEvent; winrt::event<EventDelegate> mOnCaptureGesturesEndedEvent; + winrt::event<MediaSessionMetadataDelegate> mOnMediaSessionMetadataEvent; + winrt::event<Windows::Foundation::EventHandler<int>> + mOnMediaSessionPlaybackStateChangeEvent; float mDPI = 1; hstring mInitialURL = DEFAULT_URL; diff --git a/support/hololens/ServoApp/ServoControl/ServoControl.idl b/support/hololens/ServoApp/ServoControl/ServoControl.idl index f6ba55b3b56..3a5698e1601 100644 --- a/support/hololens/ServoApp/ServoControl/ServoControl.idl +++ b/support/hololens/ServoApp/ServoControl/ServoControl.idl @@ -2,6 +2,7 @@ namespace ServoApp { delegate void EventDelegate(); delegate void HistoryChangedDelegate(Boolean back, Boolean forward); + delegate void MediaSessionMetadataDelegate(String title, String artist, String album); runtimeclass ServoControl : Windows.UI.Xaml.Controls.Control { ServoControl(); @@ -20,5 +21,7 @@ namespace ServoApp { event HistoryChangedDelegate OnHistoryChanged; event Windows.Foundation.EventHandler<String> OnTitleChanged; event Windows.Foundation.EventHandler<String> OnURLChanged; + event MediaSessionMetadataDelegate OnMediaSessionMetadata; + event Windows.Foundation.EventHandler<int> OnMediaSessionPlaybackStateChange; } } // namespace ServoApp |