diff --git a/windows/ReactNativeVideoCPP/ReactVideoView.cpp b/windows/ReactNativeVideoCPP/ReactVideoView.cpp index bb0c71ba..2bbc53bd 100644 --- a/windows/ReactNativeVideoCPP/ReactVideoView.cpp +++ b/windows/ReactNativeVideoCPP/ReactVideoView.cpp @@ -88,6 +88,14 @@ ReactVideoView::ReactVideoView(winrt::Microsoft::ReactNative::IReactContext cons } } }); + + m_positionChangedToken = m_player.PlaybackSession().PositionChanged( + winrt::auto_revoke, [ref = get_weak()](auto const& sender, auto const& args) { + if (auto self = ref.get()) { + auto newPosition = sender.Position().count(); + self->m_mediaPlayerPosition = newPosition; + } + }); } void ReactVideoView::OnMediaOpened(IInspectable const &, IInspectable const &) { @@ -155,7 +163,22 @@ void ReactVideoView::OnBufferingEnded(IInspectable const &, IInspectable const & void ReactVideoView::OnSeekCompleted(IInspectable const &, IInspectable const &) { runOnQueue([weak_this{get_weak()}]() { if (auto strong_this{weak_this.get()}) { - strong_this->m_reactContext.DispatchEvent(*strong_this, L"topVideoSeek", nullptr); + if (auto mediaPlayer = strong_this->m_player) { + auto currentTimeInSeconds = mediaPlayer.PlaybackSession().Position().count() / 10000000; + auto seekTimeInSeconds = strong_this->m_mediaPlayerPosition / 10000000; + + strong_this->m_reactContext.DispatchEvent( + *strong_this, + L"topVideoSeek", + [&](winrt::Microsoft::ReactNative::IJSValueWriter const &eventDataWriter) noexcept { + eventDataWriter.WriteObjectBegin(); + { + WriteProperty(eventDataWriter, L"currentTime", currentTimeInSeconds); + WriteProperty(eventDataWriter, L"seekTime", seekTimeInSeconds); + } + eventDataWriter.WriteObjectEnd(); + }); + } } }); } diff --git a/windows/ReactNativeVideoCPP/ReactVideoView.h b/windows/ReactNativeVideoCPP/ReactVideoView.h index d468b981..3e819889 100644 --- a/windows/ReactNativeVideoCPP/ReactVideoView.h +++ b/windows/ReactNativeVideoCPP/ReactVideoView.h @@ -29,6 +29,7 @@ struct ReactVideoView : ReactVideoViewT { bool m_fullScreen = false; double m_volume = 0; double m_position = 0; + double m_mediaPlayerPosition = 0; Windows::UI::Xaml::DispatcherTimer m_timer; Windows::Media::Playback::MediaPlayer m_player = nullptr; Windows::UI::Core::CoreDispatcher m_uiDispatcher = nullptr; @@ -40,6 +41,7 @@ struct ReactVideoView : ReactVideoViewT { Windows::Media::Playback::MediaPlaybackSession::BufferingStarted_revoker m_bufferingStartedToken{}; Windows::Media::Playback::MediaPlaybackSession::BufferingEnded_revoker m_bufferingEndedToken{}; Windows::Media::Playback::MediaPlaybackSession::SeekCompleted_revoker m_seekCompletedToken{}; + Windows::Media::Playback::MediaPlaybackSession::PositionChanged_revoker m_positionChangedToken{}; bool IsPlaying(Windows::Media::Playback::MediaPlaybackState currentState); void OnMediaOpened(IInspectable const &sender, IInspectable const &args);