summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZaggy1024 <zaggy1024@gmail.com>2023-04-12 01:01:29 -0500
committerSam Atkins <atkinssj@gmail.com>2023-04-14 12:05:52 +0100
commitdc049e36cf9017009469b8e47bb8695c80e3663d (patch)
tree49bf2a150505d8784ca06d72e5c0698822fd86f2
parentb081967762952d955fec944af281833223358651 (diff)
downloadserenity-dc049e36cf9017009469b8e47bb8695c80e3663d.zip
LibVideo: Add a method to get the playback state from `PlaybackManager`
-rw-r--r--Userland/Libraries/LibVideo/PlaybackManager.cpp17
-rw-r--r--Userland/Libraries/LibVideo/PlaybackManager.h16
2 files changed, 28 insertions, 5 deletions
diff --git a/Userland/Libraries/LibVideo/PlaybackManager.cpp b/Userland/Libraries/LibVideo/PlaybackManager.cpp
index 4366182730..294dfff639 100644
--- a/Userland/Libraries/LibVideo/PlaybackManager.cpp
+++ b/Userland/Libraries/LibVideo/PlaybackManager.cpp
@@ -349,7 +349,7 @@ protected:
manager().dispatch_state_change();
return {};
}
- bool is_playing() override { return m_playing; }
+ bool is_playing() const override { return m_playing; }
ErrorOr<void> pause() override
{
m_playing = false;
@@ -370,6 +370,8 @@ class PlaybackManager::StartingStateHandler : public PlaybackManager::ResumingSt
StringView name() override { return "Starting"sv; }
+ PlaybackState get_state() const override { return PlaybackState::Starting; }
+
ErrorOr<void> on_timer_callback() override
{
// Once we're threaded, instead of checking for the count here we can just mutex
@@ -409,7 +411,8 @@ private:
StringView name() override { return "Playing"sv; }
- bool is_playing() override { return true; };
+ bool is_playing() const override { return true; };
+ PlaybackState get_state() const override { return PlaybackState::Playing; }
ErrorOr<void> pause() override
{
manager().m_last_present_in_media_time = current_time();
@@ -531,7 +534,8 @@ private:
{
return replace_handler_and_delete_this<PlayingStateHandler>();
}
- bool is_playing() override { return false; };
+ bool is_playing() const override { return false; };
+ PlaybackState get_state() const override { return PlaybackState::Paused; }
};
class PlaybackManager::BufferingStateHandler : public PlaybackManager::ResumingStateHandler {
@@ -549,6 +553,8 @@ class PlaybackManager::BufferingStateHandler : public PlaybackManager::ResumingS
{
return assume_next_state();
}
+
+ PlaybackState get_state() const override { return PlaybackState::Buffering; }
};
class PlaybackManager::SeekingStateHandler : public PlaybackManager::ResumingStateHandler {
@@ -649,6 +655,8 @@ private:
return skip_samples_until_timestamp();
}
+ PlaybackState get_state() const override { return PlaybackState::Seeking; }
+
Time m_target_timestamp { Time::zero() };
SeekMode m_seek_mode { SeekMode::Accurate };
};
@@ -678,7 +686,8 @@ private:
manager().m_last_present_in_media_time = start_timestamp.release_value();
return replace_handler_and_delete_this<StartingStateHandler>(true);
}
- bool is_playing() override { return false; };
+ bool is_playing() const override { return false; };
+ PlaybackState get_state() const override { return PlaybackState::Stopped; }
};
}
diff --git a/Userland/Libraries/LibVideo/PlaybackManager.h b/Userland/Libraries/LibVideo/PlaybackManager.h
index 7c5779ded3..1a2591d4b7 100644
--- a/Userland/Libraries/LibVideo/PlaybackManager.h
+++ b/Userland/Libraries/LibVideo/PlaybackManager.h
@@ -91,6 +91,15 @@ public:
virtual void start(int interval_ms) = 0;
};
+enum class PlaybackState {
+ Starting,
+ Playing,
+ Paused,
+ Buffering,
+ Seeking,
+ Stopped,
+};
+
class PlaybackManager {
public:
enum class SeekMode {
@@ -115,6 +124,10 @@ public:
{
return m_playback_handler->is_playing();
}
+ PlaybackState get_state() const
+ {
+ return m_playback_handler->get_state();
+ }
u64 number_of_skipped_frames() const { return m_skipped_frames; }
@@ -187,7 +200,8 @@ private:
virtual ErrorOr<void> on_enter() { return {}; }
virtual ErrorOr<void> play() { return {}; };
- virtual bool is_playing() = 0;
+ virtual bool is_playing() const = 0;
+ virtual PlaybackState get_state() const = 0;
virtual ErrorOr<void> pause() { return {}; };
virtual ErrorOr<void> buffer() { return {}; };
virtual ErrorOr<void> seek(Time target_timestamp, SeekMode);