adding in implementation for playing and pausing updates
This commit is contained in:
@@ -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]
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<GstVideoPlayer>(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) {
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -14,13 +14,16 @@ class VideoPlayerStreamHandlerImpl : public VideoPlayerStreamHandler {
|
||||
using OnNotifyInitialized = std::function<void()>;
|
||||
using OnNotifyFrameDecoded = std::function<void()>;
|
||||
using OnNotifyCompleted = std::function<void()>;
|
||||
using OnNotifyPlaying = std::function<void(bool)>;
|
||||
|
||||
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_
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user