mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Hololens - Trigger MediaSessionActions for play and pause buttons
This commit is contained in:
parent
d633c8b9da
commit
d5200ba453
11 changed files with 69 additions and 22 deletions
|
@ -607,6 +607,14 @@ pub extern "C" fn click(x: f32, y: f32) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn media_session_action(action: i32) {
|
||||||
|
catch_any_panic(|| {
|
||||||
|
debug!("media_session_action");
|
||||||
|
call(|s| s.media_session_action(action));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
pub struct WakeupCallback(extern "C" fn());
|
pub struct WakeupCallback(extern "C" fn());
|
||||||
|
|
||||||
impl WakeupCallback {
|
impl WakeupCallback {
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "BrowserPage.h"
|
#include "BrowserPage.h"
|
||||||
#include "BrowserPage.g.cpp"
|
#include "BrowserPage.g.cpp"
|
||||||
#include "DefaultUrl.h"
|
#include "DefaultUrl.h"
|
||||||
|
#include "MediaSession.h"
|
||||||
|
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
using namespace winrt::Windows::Foundation;
|
using namespace winrt::Windows::Foundation;
|
||||||
|
@ -72,18 +73,20 @@ void BrowserPage::BindServoEvents() {
|
||||||
urlTextbox().GotFocus(std::bind(&BrowserPage::OnURLFocused, this, _1));
|
urlTextbox().GotFocus(std::bind(&BrowserPage::OnURLFocused, this, _1));
|
||||||
servoControl().OnMediaSessionMetadata(
|
servoControl().OnMediaSessionMetadata(
|
||||||
[=](hstring title, hstring artist, hstring album) {});
|
[=](hstring title, hstring artist, hstring album) {});
|
||||||
servoControl().OnMediaSessionPlaybackStateChange([=](const auto &,
|
servoControl().OnMediaSessionPlaybackStateChange(
|
||||||
int state) {
|
[=](const auto &, int state) {
|
||||||
if (state == 1 /* none */) {
|
if (state == servo::PlaybackState::NONE) {
|
||||||
mediaControls().Visibility(Visibility::Collapsed);
|
mediaControls().Visibility(Visibility::Collapsed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mediaControls().Visibility(Visibility::Visible);
|
mediaControls().Visibility(Visibility::Visible);
|
||||||
playButton().Visibility(state == 3 /* paused */ ? Visibility::Visible
|
playButton().Visibility(state == servo::PlaybackState::PAUSED
|
||||||
: Visibility::Collapsed);
|
? Visibility::Visible
|
||||||
pauseButton().Visibility(state == 3 /* paused */ ? Visibility::Collapsed
|
: Visibility::Collapsed);
|
||||||
: Visibility::Visible);
|
pauseButton().Visibility(state == servo::PlaybackState::PAUSED
|
||||||
});
|
? Visibility::Collapsed
|
||||||
|
: Visibility::Visible);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserPage::OnURLFocused(Windows::Foundation::IInspectable const &) {
|
void BrowserPage::OnURLFocused(Windows::Foundation::IInspectable const &) {
|
||||||
|
@ -159,9 +162,15 @@ void BrowserPage::OnURLEdited(IInspectable const &,
|
||||||
|
|
||||||
void BrowserPage::OnMediaControlsPlayClicked(
|
void BrowserPage::OnMediaControlsPlayClicked(
|
||||||
Windows::Foundation::IInspectable const &,
|
Windows::Foundation::IInspectable const &,
|
||||||
Windows::UI::Xaml::RoutedEventArgs const &) {}
|
Windows::UI::Xaml::RoutedEventArgs const &) {
|
||||||
|
servoControl().SendMediaSessionAction(
|
||||||
|
static_cast<int32_t>(servo::MediaSessionAction::PLAY));
|
||||||
|
}
|
||||||
void BrowserPage::OnMediaControlsPauseClicked(
|
void BrowserPage::OnMediaControlsPauseClicked(
|
||||||
Windows::Foundation::IInspectable const &,
|
Windows::Foundation::IInspectable const &,
|
||||||
Windows::UI::Xaml::RoutedEventArgs const &) {}
|
Windows::UI::Xaml::RoutedEventArgs const &) {
|
||||||
|
servoControl().SendMediaSessionAction(
|
||||||
|
static_cast<int32_t>(servo::MediaSessionAction::PAUSE));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace winrt::ServoApp::implementation
|
} // namespace winrt::ServoApp::implementation
|
||||||
|
|
|
@ -140,10 +140,6 @@
|
||||||
<CommandBar Grid.Row="3" x:Name="mediaControls" Visibility="Collapsed">
|
<CommandBar Grid.Row="3" x:Name="mediaControls" Visibility="Collapsed">
|
||||||
<AppBarButton Icon="Play" Label="Play" x:Name="playButton" Visibility="Collapsed" Click="OnMediaControlsPlayClicked"/>
|
<AppBarButton Icon="Play" Label="Play" x:Name="playButton" Visibility="Collapsed" Click="OnMediaControlsPlayClicked"/>
|
||||||
<AppBarButton Icon="Pause" Label="Pause" x:Name="pauseButton" Click="OnMediaControlsPauseClicked"/>
|
<AppBarButton Icon="Pause" Label="Pause" x:Name="pauseButton" Click="OnMediaControlsPauseClicked"/>
|
||||||
|
|
||||||
<CommandBar.Content>
|
|
||||||
<TextBlock Text="Now playing..." Margin="12,14"/>
|
|
||||||
</CommandBar.Content>
|
|
||||||
</CommandBar>
|
</CommandBar>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
|
21
support/hololens/ServoApp/MediaSession.h
Normal file
21
support/hololens/ServoApp/MediaSession.h
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace winrt::servo {
|
||||||
|
enum PlaybackState {
|
||||||
|
NONE = 1,
|
||||||
|
PLAYING,
|
||||||
|
PAUSED
|
||||||
|
};
|
||||||
|
|
||||||
|
enum MediaSessionAction {
|
||||||
|
PLAY = 1,
|
||||||
|
PAUSE,
|
||||||
|
SEEK_BACKWARD,
|
||||||
|
SEEK_FORWARD,
|
||||||
|
PREVIOUS_TRACK,
|
||||||
|
NEXT_TRACK,
|
||||||
|
SKIP_AD,
|
||||||
|
STOP,
|
||||||
|
SEEK_TO
|
||||||
|
};
|
||||||
|
}
|
|
@ -122,6 +122,7 @@
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="logs.h" />
|
<ClInclude Include="logs.h" />
|
||||||
|
<ClInclude Include="MediaSession.h" />
|
||||||
<ClInclude Include="pch.h" />
|
<ClInclude Include="pch.h" />
|
||||||
<ClInclude Include="App.h">
|
<ClInclude Include="App.h">
|
||||||
<DependentUpon>App.xaml</DependentUpon>
|
<DependentUpon>App.xaml</DependentUpon>
|
||||||
|
|
|
@ -40,6 +40,9 @@
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="DefaultUrl.h" />
|
<ClInclude Include="DefaultUrl.h" />
|
||||||
<ClInclude Include="XRPkgChecker.h" />
|
<ClInclude Include="XRPkgChecker.h" />
|
||||||
|
<ClInclude Include="MediaSession.h">
|
||||||
|
<Filter>ServoControl</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Image Include="Assets\Wide310x150Logo.scale-200.png">
|
<Image Include="Assets\Wide310x150Logo.scale-200.png">
|
||||||
|
|
|
@ -73,8 +73,7 @@ Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height,
|
||||||
capi::CInitOptions o;
|
capi::CInitOptions o;
|
||||||
hstring defaultPrefs = L" --pref dom.webxr.enabled";
|
hstring defaultPrefs = L" --pref dom.webxr.enabled";
|
||||||
o.args = *hstring2char(args + defaultPrefs);
|
o.args = *hstring2char(args + defaultPrefs);
|
||||||
o.url =
|
o.url = *hstring2char(url);
|
||||||
"https://ferjm.github.io/web-api-tests/video/mp4.html"; //*hstring2char(url);
|
|
||||||
o.width = mWindowWidth;
|
o.width = mWindowWidth;
|
||||||
o.height = mWindowHeight;
|
o.height = mWindowHeight;
|
||||||
o.density = dpi;
|
o.density = dpi;
|
||||||
|
|
|
@ -88,6 +88,9 @@ public:
|
||||||
capi::resize(mWindowWidth, mWindowHeight);
|
capi::resize(mWindowWidth, mWindowHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void SendMediaSessionAction(int32_t action) {
|
||||||
|
capi::media_session_action(action);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ServoDelegate &mDelegate;
|
ServoDelegate &mDelegate;
|
||||||
|
|
|
@ -271,6 +271,10 @@ hstring ServoControl::LoadURIOrSearch(hstring input) {
|
||||||
return searchUri;
|
return searchUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServoControl::SendMediaSessionAction(int32_t action) {
|
||||||
|
RunOnGLThread([=] { mServo->SendMediaSessionAction(action); });
|
||||||
|
}
|
||||||
|
|
||||||
void ServoControl::TryLoadUri(hstring input) {
|
void ServoControl::TryLoadUri(hstring input) {
|
||||||
if (!mLooping) {
|
if (!mLooping) {
|
||||||
mInitialURL = input;
|
mInitialURL = input;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "OpenGLES.h"
|
#include "OpenGLES.h"
|
||||||
#include "Servo.h"
|
#include "Servo.h"
|
||||||
#include "DefaultUrl.h"
|
#include "DefaultUrl.h"
|
||||||
|
#include "MediaSession.h"
|
||||||
|
|
||||||
namespace winrt::ServoApp::implementation {
|
namespace winrt::ServoApp::implementation {
|
||||||
struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
|
struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
|
||||||
|
@ -15,6 +16,7 @@ struct ServoControl : ServoControlT<ServoControl>, public servo::ServoDelegate {
|
||||||
void Stop();
|
void Stop();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
hstring LoadURIOrSearch(hstring);
|
hstring LoadURIOrSearch(hstring);
|
||||||
|
void SendMediaSessionAction(int32_t);
|
||||||
|
|
||||||
void OnLoaded(IInspectable const &,
|
void OnLoaded(IInspectable const &,
|
||||||
Windows::UI::Xaml::RoutedEventArgs const &);
|
Windows::UI::Xaml::RoutedEventArgs const &);
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace ServoApp {
|
||||||
void SetTransientMode(Boolean transient);
|
void SetTransientMode(Boolean transient);
|
||||||
void SetArgs(String args);
|
void SetArgs(String args);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
void SendMediaSessionAction(UInt32 action);
|
||||||
event EventDelegate OnLoadStarted;
|
event EventDelegate OnLoadStarted;
|
||||||
event EventDelegate OnLoadEnded;
|
event EventDelegate OnLoadEnded;
|
||||||
event EventDelegate OnCaptureGesturesStarted;
|
event EventDelegate OnCaptureGesturesStarted;
|
||||||
|
@ -21,7 +22,7 @@ namespace ServoApp {
|
||||||
event HistoryChangedDelegate OnHistoryChanged;
|
event HistoryChangedDelegate OnHistoryChanged;
|
||||||
event Windows.Foundation.EventHandler<String> OnTitleChanged;
|
event Windows.Foundation.EventHandler<String> OnTitleChanged;
|
||||||
event Windows.Foundation.EventHandler<String> OnURLChanged;
|
event Windows.Foundation.EventHandler<String> OnURLChanged;
|
||||||
event MediaSessionMetadataDelegate OnMediaSessionMetadata;
|
event MediaSessionMetadataDelegate OnMediaSessionMetadata;
|
||||||
event Windows.Foundation.EventHandler<int> OnMediaSessionPlaybackStateChange;
|
event Windows.Foundation.EventHandler<int> OnMediaSessionPlaybackStateChange;
|
||||||
}
|
}
|
||||||
} // namespace ServoApp
|
} // namespace ServoApp
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue