From eb0d1443b539ba1842ab9a20533f66aaa6df36e3 Mon Sep 17 00:00:00 2001 From: talksik Date: Mon, 25 Sep 2023 12:09:53 -0700 Subject: [PATCH] adding in implementation for playing and pausing updates --- packages/video_player/.clangd | 2 +- .../video_player/elinux/gst_video_player.cc | 6 ++++++ .../elinux/video_player_elinux_plugin.cc | 20 +++++++++++++++++++ .../elinux/video_player_stream_handler.h | 4 ++++ .../elinux/video_player_stream_handler_impl.h | 14 +++++++++++-- .../lib/src/elinux_video_player.dart | 2 -- packages/video_player/pubspec.yaml | 2 +- 7 files changed, 44 insertions(+), 6 deletions(-) diff --git a/packages/video_player/.clangd b/packages/video_player/.clangd index 7df1249..b3c7872 100644 --- a/packages/video_player/.clangd +++ b/packages/video_player/.clangd @@ -1,3 +1,3 @@ CompileFlags: - Add: [-I/home/talksik/code/opensource/flutter-elinux-plugins/packages/video_player/example/elinux/flutter/ephemeral/, -I/home/talksik/code/opensource/flutter-elinux-plugins/packages/video_player/example/elinux/flutter/ephemeral/cpp_client_wrapper/include, -I/usr/include/glib-2.0, -I/usr/lib/x86_64-linux-gnu/glib-2.0/include] + Add: [-I/usr/include/gstreamer-1.0, -I/home/talksik/code/opensource/flutter-elinux-plugins/packages/video_player/example/elinux/flutter/ephemeral/, -I/home/talksik/code/opensource/flutter-elinux-plugins/packages/video_player/example/elinux/flutter/ephemeral/cpp_client_wrapper/include, -I/usr/include/glib-2.0, -I/usr/lib/x86_64-linux-gnu/glib-2.0/include] diff --git a/packages/video_player/elinux/gst_video_player.cc b/packages/video_player/elinux/gst_video_player.cc index d0e1e09..4dc054b 100644 --- a/packages/video_player/elinux/gst_video_player.cc +++ b/packages/video_player/elinux/gst_video_player.cc @@ -54,6 +54,8 @@ bool GstVideoPlayer::Play() { std::cerr << "Failed to change the state to PLAYING" << std::endl; return false; } + + stream_handler_->OnNotifyPlaying(true); return true; } @@ -63,6 +65,8 @@ bool GstVideoPlayer::Pause() { std::cerr << "Failed to change the state to PAUSED" << std::endl; return false; } + + stream_handler_->OnNotifyPlaying(false); return true; } @@ -72,6 +76,8 @@ bool GstVideoPlayer::Stop() { std::cerr << "Failed to change the state to READY" << std::endl; return false; } + + stream_handler_->OnNotifyPlaying(false); return true; } diff --git a/packages/video_player/elinux/video_player_elinux_plugin.cc b/packages/video_player/elinux/video_player_elinux_plugin.cc index a703e31..afbf78e 100644 --- a/packages/video_player/elinux/video_player_elinux_plugin.cc +++ b/packages/video_player/elinux/video_player_elinux_plugin.cc @@ -130,6 +130,7 @@ class VideoPlayerPlugin : public flutter::Plugin { void SendInitializedEventMessage(int64_t texture_id); void SendPlayCompletedEventMessage(int64_t texture_id); + void SendIsPlayingStateUpdate(int64_t texture_id, bool is_playing); flutter::EncodableValue WrapError(const std::string& message, const std::string& code = std::string(), @@ -364,6 +365,9 @@ void VideoPlayerPlugin::HandleCreateMethodCall( // OnNotifyCompleted [texture_id, host = this]() { host->SendPlayCompletedEventMessage(texture_id); + }, + [texture_id, host = this](bool is_playing) { + host->SendIsPlayingStateUpdate(texture_id, is_playing); }); instance->player = std::make_unique(uri, std::move(player_handler)); @@ -598,6 +602,22 @@ void VideoPlayerPlugin::SendPlayCompletedEventMessage(int64_t texture_id) { players_[texture_id]->event_sink->Success(event); } +void VideoPlayerPlugin::SendIsPlayingStateUpdate(int64_t texture_id, + bool is_playing) { + if (players_.find(texture_id) == players_.end() || + !players_[texture_id]->event_sink) { + return; + } + + flutter::EncodableMap encodables = { + {flutter::EncodableValue("event"), + flutter::EncodableValue("isPlayingStateUpdate")}, + {flutter::EncodableValue("isPlaying"), + flutter::EncodableValue(is_playing)}}; + flutter::EncodableValue event(encodables); + players_[texture_id]->event_sink->Success(event); +} + flutter::EncodableValue VideoPlayerPlugin::WrapError( const std::string& message, const std::string& code, const std::string& details) { diff --git a/packages/video_player/elinux/video_player_stream_handler.h b/packages/video_player/elinux/video_player_stream_handler.h index cf63c4a..e251a3b 100644 --- a/packages/video_player/elinux/video_player_stream_handler.h +++ b/packages/video_player/elinux/video_player_stream_handler.h @@ -23,10 +23,14 @@ class VideoPlayerStreamHandler { // Notifies the completion of playing a video. void OnNotifyCompleted() { OnNotifyCompletedInternal(); } + // Notifies update of playing or pausing a video. + void OnNotifyPlaying(bool is_playing) { OnNotifyPlayingInternal(is_playing); } + protected: virtual void OnNotifyInitializedInternal() = 0; virtual void OnNotifyFrameDecodedInternal() = 0; virtual void OnNotifyCompletedInternal() = 0; + virtual void OnNotifyPlayingInternal(bool is_playing) = 0; }; #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_VIDEO_PLAYER_STREAM_HANDLER_H_ diff --git a/packages/video_player/elinux/video_player_stream_handler_impl.h b/packages/video_player/elinux/video_player_stream_handler_impl.h index 7b955b0..f7543ed 100644 --- a/packages/video_player/elinux/video_player_stream_handler_impl.h +++ b/packages/video_player/elinux/video_player_stream_handler_impl.h @@ -14,13 +14,16 @@ class VideoPlayerStreamHandlerImpl : public VideoPlayerStreamHandler { using OnNotifyInitialized = std::function; using OnNotifyFrameDecoded = std::function; using OnNotifyCompleted = std::function; + using OnNotifyPlaying = std::function; VideoPlayerStreamHandlerImpl(OnNotifyInitialized on_notify_initialized, OnNotifyFrameDecoded on_notify_frame_decoded, - OnNotifyCompleted on_notify_completed) + OnNotifyCompleted on_notify_completed, + OnNotifyPlaying on_notify_playing) : on_notify_initialized_(on_notify_initialized), on_notify_frame_decoded_(on_notify_frame_decoded), - on_notify_completed_(on_notify_completed) {} + on_notify_completed_(on_notify_completed), + on_notify_playing_(on_notify_playing) {} virtual ~VideoPlayerStreamHandlerImpl() = default; // Prevent copying. @@ -50,9 +53,16 @@ class VideoPlayerStreamHandlerImpl : public VideoPlayerStreamHandler { } } + void OnNotifyPlayingInternal(bool is_playing) { + if (on_notify_playing_) { + on_notify_playing_(is_playing); + } + } + OnNotifyInitialized on_notify_initialized_; OnNotifyFrameDecoded on_notify_frame_decoded_; OnNotifyCompleted on_notify_completed_; + OnNotifyPlaying on_notify_playing_; }; #endif // PACKAGES_VIDEO_PLAYER_VIDEO_PLAYER_ELINUX_VIDEO_PLAYER_STREAM_HANDLER_IMPL_H_ diff --git a/packages/video_player/lib/src/elinux_video_player.dart b/packages/video_player/lib/src/elinux_video_player.dart index 72caa5a..1b40f2d 100644 --- a/packages/video_player/lib/src/elinux_video_player.dart +++ b/packages/video_player/lib/src/elinux_video_player.dart @@ -149,13 +149,11 @@ class ELinuxVideoPlayer extends VideoPlayerPlatform { return VideoEvent(eventType: VideoEventType.bufferingStart); case 'bufferingEnd': return VideoEvent(eventType: VideoEventType.bufferingEnd); -/* TODO: need implementation case 'isPlayingStateUpdate': return VideoEvent( eventType: VideoEventType.isPlayingStateUpdate, isPlaying: map['isPlaying'] as bool, ); -*/ default: return VideoEvent(eventType: VideoEventType.unknown); } diff --git a/packages/video_player/pubspec.yaml b/packages/video_player/pubspec.yaml index 643f07b..a10d08a 100644 --- a/packages/video_player/pubspec.yaml +++ b/packages/video_player/pubspec.yaml @@ -11,7 +11,7 @@ environment: dependencies: flutter: sdk: flutter - video_player_platform_interface: ^5.1.1 + video_player_platform_interface: ^6.2.1 flutter: plugin: