tdf#123743 deactive after the player is stopped.
The queried media duration for gstreamer isn't ready at the beginning.
Instead of deactivate the audio node immediately after querying the
duration, schedule to update the media duration and use the updated
duration to schedule deactivation.
Change-Id: I8bfa69377fbc18b21baf48bc293d2d0853e8805a
Reviewed-on: https://gerrit.libreoffice.org/68451
Tested-by: Jenkins
Reviewed-by: Mark Hung <marklh9@gmail.com>
diff --git a/slideshow/source/engine/animationnodes/animationaudionode.cxx b/slideshow/source/engine/animationnodes/animationaudionode.cxx
index b024de2..9e3f6bc 100644
--- a/slideshow/source/engine/animationnodes/animationaudionode.cxx
+++ b/slideshow/source/engine/animationnodes/animationaudionode.cxx
@@ -76,12 +76,14 @@ void AnimationAudioNode::activate_st()
}
else
{
// no node duration. Take inherent media time, then
// no node duration. Take inherent media time. We have to recheck
// if the player is playing in case the duration isn't accurate
// or the progress fall behind.
auto self(getSelf());
scheduleDeactivationEvent(
makeDelay( [self] () { self->deactivate(); },
makeDelay( [this] () { this->checkPlayingStatus(); },
mpPlayer->getDuration(),
"AnimationAudioNode::deactivate with delay") );
"AnimationAudioNode::check if sitll playing with delay") );
}
}
else
@@ -182,6 +184,19 @@ bool AnimationAudioNode::handleAnimationEvent(
return true;
}
void AnimationAudioNode::checkPlayingStatus()
{
auto self(getSelf());
double nDuration = mpPlayer->getDuration();
if (!mpPlayer->isPlaying() || nDuration < 0.0)
nDuration = 0.0;
scheduleDeactivationEvent(
makeDelay( [self] () { self->deactivate(); },
nDuration,
"AnimationAudioNode::deactivate with delay") );
}
} // namespace internal
} // namespace presentation
diff --git a/slideshow/source/engine/animationnodes/animationaudionode.hxx b/slideshow/source/engine/animationnodes/animationaudionode.hxx
index 6efd40f..30de41c 100644
--- a/slideshow/source/engine/animationnodes/animationaudionode.hxx
+++ b/slideshow/source/engine/animationnodes/animationaudionode.hxx
@@ -59,6 +59,7 @@ private:
void createPlayer() const;
void resetPlayer() const;
void checkPlayingStatus();
};
} // namespace internal
diff --git a/slideshow/source/engine/soundplayer.cxx b/slideshow/source/engine/soundplayer.cxx
index 65b5783..18a1948 100644
--- a/slideshow/source/engine/soundplayer.cxx
+++ b/slideshow/source/engine/soundplayer.cxx
@@ -170,6 +170,11 @@ namespace slideshow
if( mxPlayer.is() )
mxPlayer->setPlaybackLoop( bLoop );
}
bool SoundPlayer::isPlaying() const
{
return mxPlayer->isPlaying();
}
}
}
diff --git a/slideshow/source/inc/soundplayer.hxx b/slideshow/source/inc/soundplayer.hxx
index ea496d8..92ac94b 100644
--- a/slideshow/source/inc/soundplayer.hxx
+++ b/slideshow/source/inc/soundplayer.hxx
@@ -83,6 +83,7 @@ namespace slideshow
bool startPlayback();
bool stopPlayback();
bool isPlaying() const;
void setPlaybackLoop( bool bLoop );