mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:47:37 +00:00
LibVideo: Add a method to get the playback state from PlaybackManager
This commit is contained in:
parent
b081967762
commit
dc049e36cf
2 changed files with 28 additions and 5 deletions
|
@ -349,7 +349,7 @@ protected:
|
||||||
manager().dispatch_state_change();
|
manager().dispatch_state_change();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
bool is_playing() override { return m_playing; }
|
bool is_playing() const override { return m_playing; }
|
||||||
ErrorOr<void> pause() override
|
ErrorOr<void> pause() override
|
||||||
{
|
{
|
||||||
m_playing = false;
|
m_playing = false;
|
||||||
|
@ -370,6 +370,8 @@ class PlaybackManager::StartingStateHandler : public PlaybackManager::ResumingSt
|
||||||
|
|
||||||
StringView name() override { return "Starting"sv; }
|
StringView name() override { return "Starting"sv; }
|
||||||
|
|
||||||
|
PlaybackState get_state() const override { return PlaybackState::Starting; }
|
||||||
|
|
||||||
ErrorOr<void> on_timer_callback() override
|
ErrorOr<void> on_timer_callback() override
|
||||||
{
|
{
|
||||||
// Once we're threaded, instead of checking for the count here we can just mutex
|
// 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; }
|
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
|
ErrorOr<void> pause() override
|
||||||
{
|
{
|
||||||
manager().m_last_present_in_media_time = current_time();
|
manager().m_last_present_in_media_time = current_time();
|
||||||
|
@ -531,7 +534,8 @@ private:
|
||||||
{
|
{
|
||||||
return replace_handler_and_delete_this<PlayingStateHandler>();
|
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 {
|
class PlaybackManager::BufferingStateHandler : public PlaybackManager::ResumingStateHandler {
|
||||||
|
@ -549,6 +553,8 @@ class PlaybackManager::BufferingStateHandler : public PlaybackManager::ResumingS
|
||||||
{
|
{
|
||||||
return assume_next_state();
|
return assume_next_state();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlaybackState get_state() const override { return PlaybackState::Buffering; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class PlaybackManager::SeekingStateHandler : public PlaybackManager::ResumingStateHandler {
|
class PlaybackManager::SeekingStateHandler : public PlaybackManager::ResumingStateHandler {
|
||||||
|
@ -649,6 +655,8 @@ private:
|
||||||
return skip_samples_until_timestamp();
|
return skip_samples_until_timestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlaybackState get_state() const override { return PlaybackState::Seeking; }
|
||||||
|
|
||||||
Time m_target_timestamp { Time::zero() };
|
Time m_target_timestamp { Time::zero() };
|
||||||
SeekMode m_seek_mode { SeekMode::Accurate };
|
SeekMode m_seek_mode { SeekMode::Accurate };
|
||||||
};
|
};
|
||||||
|
@ -678,7 +686,8 @@ private:
|
||||||
manager().m_last_present_in_media_time = start_timestamp.release_value();
|
manager().m_last_present_in_media_time = start_timestamp.release_value();
|
||||||
return replace_handler_and_delete_this<StartingStateHandler>(true);
|
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; }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,15 @@ public:
|
||||||
virtual void start(int interval_ms) = 0;
|
virtual void start(int interval_ms) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class PlaybackState {
|
||||||
|
Starting,
|
||||||
|
Playing,
|
||||||
|
Paused,
|
||||||
|
Buffering,
|
||||||
|
Seeking,
|
||||||
|
Stopped,
|
||||||
|
};
|
||||||
|
|
||||||
class PlaybackManager {
|
class PlaybackManager {
|
||||||
public:
|
public:
|
||||||
enum class SeekMode {
|
enum class SeekMode {
|
||||||
|
@ -115,6 +124,10 @@ public:
|
||||||
{
|
{
|
||||||
return m_playback_handler->is_playing();
|
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; }
|
u64 number_of_skipped_frames() const { return m_skipped_frames; }
|
||||||
|
|
||||||
|
@ -187,7 +200,8 @@ private:
|
||||||
virtual ErrorOr<void> on_enter() { return {}; }
|
virtual ErrorOr<void> on_enter() { return {}; }
|
||||||
|
|
||||||
virtual ErrorOr<void> play() { 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> pause() { return {}; };
|
||||||
virtual ErrorOr<void> buffer() { return {}; };
|
virtual ErrorOr<void> buffer() { return {}; };
|
||||||
virtual ErrorOr<void> seek(Time target_timestamp, SeekMode);
|
virtual ErrorOr<void> seek(Time target_timestamp, SeekMode);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue