Qt: start hover audio/video after a timeout

This commit is contained in:
Megamouse 2026-03-20 01:53:40 +01:00
parent 40229adb14
commit 51514f9dc8
2 changed files with 28 additions and 1 deletions

View File

@ -27,6 +27,7 @@ static std::array<qt_audio_instance, 2> s_audio_instance = {};
qt_video_source::qt_video_source(bool is_emulation)
: video_source()
, m_audio_instance_index(is_emulation ? qt_audio_instance::emu_index : qt_audio_instance::gui_index)
, m_video_timer_timeout_ms(is_emulation ? 0 : 1000)
{
}
@ -56,7 +57,7 @@ void qt_video_source::set_active(bool active)
if (active)
{
start_movie();
start_movie_timer();
}
else
{
@ -187,6 +188,27 @@ void qt_video_source::init_movie()
}
}
void qt_video_source::start_movie_timer()
{
if (m_video_timer_timeout_ms == 0)
{
start_movie();
return;
}
if (!m_video_timer)
{
m_video_timer = std::make_unique<QTimer>();
QObject::connect(m_video_timer.get(), &QTimer::timeout, m_video_timer.get(), [this]()
{
if (!m_active) return;
start_movie();
});
}
m_video_timer->start(m_video_timer_timeout_ms);
}
void qt_video_source::start_movie()
{
init_movie();
@ -210,6 +232,7 @@ void qt_video_source::start_movie()
void qt_video_source::stop_movie()
{
m_active = false;
m_video_timer.reset();
if (m_movie)
{

View File

@ -10,6 +10,7 @@
#include <QVideoSink>
#include <QVideoFrame>
#include <QPixmap>
#include <QTimer>
class qt_video_source : public video_source
{
@ -29,6 +30,7 @@ public:
void set_active(bool active) override;
bool get_active() const override { return m_active; }
void start_movie_timer();
void start_movie();
void stop_movie();
@ -51,11 +53,13 @@ protected:
QString m_video_path;
QString m_audio_path;
u32 m_audio_instance_index = 0;
u32 m_video_timer_timeout_ms = 0;
std::string m_iso_path; // path of the source archive
QByteArray m_video_data{};
QImage m_image{};
std::vector<u8> m_image_path;
std::unique_ptr<QTimer> m_video_timer;
std::unique_ptr<QBuffer> m_video_buffer;
std::unique_ptr<QMediaPlayer> m_media_player;
std::unique_ptr<QVideoSink> m_video_sink;