mirror of
https://github.com/zoriya/react-native-video.git
synced 2026-05-23 07:06:29 +00:00
feat(windows): add topSeek parms mentioned in docs (#4456)
This commit is contained in:
@@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ struct ReactVideoView : ReactVideoViewT<ReactVideoView> {
|
||||
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<ReactVideoView> {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user