Skip to content

Commit d902c1b

Browse files
authored
feat(windows): add topSeek parms mentioned in docs (#4456)
1 parent 9f02614 commit d902c1b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

windows/ReactNativeVideoCPP/ReactVideoView.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ ReactVideoView::ReactVideoView(winrt::Microsoft::ReactNative::IReactContext cons
8888
}
8989
}
9090
});
91+
92+
m_positionChangedToken = m_player.PlaybackSession().PositionChanged(
93+
winrt::auto_revoke, [ref = get_weak()](auto const& sender, auto const& args) {
94+
if (auto self = ref.get()) {
95+
auto newPosition = sender.Position().count();
96+
self->m_mediaPlayerPosition = newPosition;
97+
}
98+
});
9199
}
92100

93101
void ReactVideoView::OnMediaOpened(IInspectable const &, IInspectable const &) {
@@ -155,7 +163,22 @@ void ReactVideoView::OnBufferingEnded(IInspectable const &, IInspectable const &
155163
void ReactVideoView::OnSeekCompleted(IInspectable const &, IInspectable const &) {
156164
runOnQueue([weak_this{get_weak()}]() {
157165
if (auto strong_this{weak_this.get()}) {
158-
strong_this->m_reactContext.DispatchEvent(*strong_this, L"topVideoSeek", nullptr);
166+
if (auto mediaPlayer = strong_this->m_player) {
167+
auto currentTimeInSeconds = mediaPlayer.PlaybackSession().Position().count() / 10000000;
168+
auto seekTimeInSeconds = strong_this->m_mediaPlayerPosition / 10000000;
169+
170+
strong_this->m_reactContext.DispatchEvent(
171+
*strong_this,
172+
L"topVideoSeek",
173+
[&](winrt::Microsoft::ReactNative::IJSValueWriter const &eventDataWriter) noexcept {
174+
eventDataWriter.WriteObjectBegin();
175+
{
176+
WriteProperty(eventDataWriter, L"currentTime", currentTimeInSeconds);
177+
WriteProperty(eventDataWriter, L"seekTime", seekTimeInSeconds);
178+
}
179+
eventDataWriter.WriteObjectEnd();
180+
});
181+
}
159182
}
160183
});
161184
}

windows/ReactNativeVideoCPP/ReactVideoView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct ReactVideoView : ReactVideoViewT<ReactVideoView> {
2929
bool m_fullScreen = false;
3030
double m_volume = 0;
3131
double m_position = 0;
32+
double m_mediaPlayerPosition = 0;
3233
Windows::UI::Xaml::DispatcherTimer m_timer;
3334
Windows::Media::Playback::MediaPlayer m_player = nullptr;
3435
Windows::UI::Core::CoreDispatcher m_uiDispatcher = nullptr;
@@ -40,6 +41,7 @@ struct ReactVideoView : ReactVideoViewT<ReactVideoView> {
4041
Windows::Media::Playback::MediaPlaybackSession::BufferingStarted_revoker m_bufferingStartedToken{};
4142
Windows::Media::Playback::MediaPlaybackSession::BufferingEnded_revoker m_bufferingEndedToken{};
4243
Windows::Media::Playback::MediaPlaybackSession::SeekCompleted_revoker m_seekCompletedToken{};
44+
Windows::Media::Playback::MediaPlaybackSession::PositionChanged_revoker m_positionChangedToken{};
4345

4446
bool IsPlaying(Windows::Media::Playback::MediaPlaybackState currentState);
4547
void OnMediaOpened(IInspectable const &sender, IInspectable const &args);

0 commit comments

Comments
 (0)