@@ -68,7 +68,7 @@ using AVFrameRefPtr = std::unique_ptr<AVFrame, deleteAVFrameRef>;
6868}
6969
7070namespace Media {
71- class Video
71+ class Video : public std ::enable_shared_from_this<Video>
7272 {
7373 public:
7474 Video (VideoPlayer &player, Engine::BaseEngine &engine, const std::string &fileName_)
@@ -99,6 +99,18 @@ namespace Media {
9999
100100 bool init (const uint16_t width, const uint16_t height)
101101 {
102+ actions.push_back (Engine::Input::RegisterAction (Engine::ActionType::Video_Close,
103+ [videoPtr = weak_from_this ()](bool triggered, float /* intensity*/ ){
104+ auto video = videoPtr.lock ();
105+ if (!video) {
106+ LogWarn () << " Video already finished, the action should not be triggered" ;
107+ return ;
108+ }
109+
110+ if (triggered)
111+ video->stop = true ;
112+ }));
113+
102114 av_init_packet (&packet);
103115 packet.data = nullptr ;
104116 packet.size = 0 ;
@@ -309,6 +321,8 @@ namespace Media {
309321 assert (!videoFrames.empty ());
310322 assert (videoFrames.front ());
311323
324+ if (stop)
325+ return false ;
312326 if (currentTime >= videoFrames.front ()->pts ) {
313327 AVFrameRefPtr frame;
314328 videoFrames.front ().swap (frame);
@@ -344,6 +358,8 @@ namespace Media {
344358 AVPacket packet = {};
345359 Handle::TextureHandle texture;
346360 UI::ImageView *view;
361+ bool stop = false ;
362+ std::vector<Engine::ManagedActionBinding> actions;
347363 };
348364}
349365#endif
@@ -364,7 +380,7 @@ void Media::VideoPlayer::play(std::string fileName)
364380 if (!Utils::endsWith (Utils::toUpper (fileName), " .BIK" ))
365381 fileName += " .bik" ;
366382
367- currentVideo = std::make_unique <Video>(*this , engine, fileName);
383+ currentVideo = std::make_shared <Video>(*this , engine, fileName);
368384#else
369385 LogWarn () << " No libavcodec support compiled, won't play" << fileName;
370386#endif
0 commit comments