Make seeking use set property with time-pos instead of command

This commit is contained in:
Ylva Selling
2023-02-28 10:35:10 -05:00
parent 4a617aa9eb
commit afc9a0c1c7
2 changed files with 9 additions and 15 deletions

View File

@@ -56,7 +56,7 @@ public:
void play();
void goToStart();
void seekToTime(double time);
void seekToTime(double time, bool pauseAfter = false);
void toggleMute();
const std::unique_ptr<ghoul::opengl::Texture>& frameTexture() const;

View File

@@ -332,7 +332,7 @@ VideoPlayer::VideoPlayer(const ghoul::Dictionary& dictionary)
{MpvKey::Width, MPV_FORMAT_INT64},
{MpvKey::Meta, MPV_FORMAT_NODE},
{MpvKey::Fps, MPV_FORMAT_DOUBLE},
{MpvKey::IsSeeking, MPV_FORMAT_DOUBLE},
{MpvKey::IsSeeking, MPV_FORMAT_FLAG},
{MpvKey::Mute, MPV_FORMAT_STRING}
};
@@ -475,20 +475,14 @@ void VideoPlayer::initializeMpv() {
_isInitialized = true;
}
void VideoPlayer::seekToTime(double time) {
if (!_isInitialized) {
void VideoPlayer::seekToTime(double time, bool pauseAfter) {
if (_isSeeking || abs(_currentVideoTime - time) < glm::epsilon<double>()) {
return;
}
// Prevent from seeking to the same time multiple times in a row
bool seekIsDifferent = abs(time - _currentVideoTime) > _seekThreshold;
if (seekIsDifferent && !_isSeeking) {
// Pause while seeking
pause();
std::string timeString = std::to_string(time);
const char* params = timeString.c_str();
const char* cmd[] = { keys[MpvKey::Seek], params, "absolute", NULL};
commandAsyncMpv(cmd, MpvKey::Seek);
_isSeeking = true;
pause();
setPropertyAsyncMpv(time, MpvKey::Time);
if (!pauseAfter) {
play();
}
}
@@ -605,7 +599,6 @@ void VideoPlayer::handleMpvEvents() {
break;
}
case MpvKey::Seek: {
_isSeeking = false;
break;
}
default: {
@@ -714,6 +707,7 @@ void VideoPlayer::handleMpvProperties(mpv_event* event) {
}
case MpvKey::IsSeeking: {
bool* isSeekingBool = reinterpret_cast<bool*>(prop->data);
_isSeeking = *isSeekingBool;
std::string isSeekingString = *isSeekingBool ? "Is Seeking" : "Not Seeking";
LINFO(isSeekingString);
break;