mpv backend now replay media once it ended/stopped
This commit is contained in:
parent
5679122f5e
commit
856cab57e7
@ -75,10 +75,11 @@ LibMpvBackend::LibMpvBackend(QWidget* parent)
|
|||||||
mpv_set_option_string(m_mpvHandle, "osd-playing-msg", "${media-title}");
|
mpv_set_option_string(m_mpvHandle, "osd-playing-msg", "${media-title}");
|
||||||
mpv_set_option_string(m_mpvHandle, "osc", "yes");
|
mpv_set_option_string(m_mpvHandle, "osc", "yes");
|
||||||
mpv_set_option_string(m_mpvHandle, "input-cursor", "yes");
|
mpv_set_option_string(m_mpvHandle, "input-cursor", "yes");
|
||||||
mpv_set_option_string(m_mpvHandle, "keep-open", "no");
|
// mpv_set_option_string(m_mpvHandle, "keep-open", "no");
|
||||||
mpv_set_option_string(m_mpvHandle, "idle", "yes");
|
mpv_set_option_string(m_mpvHandle, "idle", "yes");
|
||||||
mpv_set_option_string(m_mpvHandle, "save-position-on-quit", "no");
|
mpv_set_option_string(m_mpvHandle, "save-position-on-quit", "no");
|
||||||
mpv_set_option_string(m_mpvHandle, "no-resume-playback", "yes");
|
mpv_set_option_string(m_mpvHandle, "no-resume-playback", "yes");
|
||||||
|
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
mpv_set_option_string(m_mpvHandle, "terminal", "yes");
|
mpv_set_option_string(m_mpvHandle, "terminal", "yes");
|
||||||
#endif
|
#endif
|
||||||
@ -142,6 +143,7 @@ void LibMpvBackend::handleMpvEvent(mpv_event* event) {
|
|||||||
|
|
||||||
case MPV_EVENT_FILE_LOADED:
|
case MPV_EVENT_FILE_LOADED:
|
||||||
emit statusChanged(tr("File loaded"));
|
emit statusChanged(tr("File loaded"));
|
||||||
|
emit playbackStateChanged(PlayerBackend::PlaybackState::PlayingState);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MPV_EVENT_END_FILE: {
|
case MPV_EVENT_END_FILE: {
|
||||||
@ -265,8 +267,12 @@ void LibMpvBackend::onMpvEvents() {
|
|||||||
|
|
||||||
void LibMpvBackend::processEndFile(mpv_event_end_file* end_file) {
|
void LibMpvBackend::processEndFile(mpv_event_end_file* end_file) {
|
||||||
switch (end_file->reason) {
|
switch (end_file->reason) {
|
||||||
case MPV_END_FILE_REASON_EOF:
|
|
||||||
case MPV_END_FILE_REASON_STOP:
|
case MPV_END_FILE_REASON_STOP:
|
||||||
|
emit statusChanged(tr("Stopped"));
|
||||||
|
emit playbackStateChanged(PlayerBackend::PlaybackState::StoppedState);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MPV_END_FILE_REASON_EOF:
|
||||||
case MPV_END_FILE_REASON_QUIT:
|
case MPV_END_FILE_REASON_QUIT:
|
||||||
emit statusChanged(tr("File ended"));
|
emit statusChanged(tr("File ended"));
|
||||||
emit playbackStateChanged(PlayerBackend::PlaybackState::StoppedState);
|
emit playbackStateChanged(PlayerBackend::PlaybackState::StoppedState);
|
||||||
@ -474,12 +480,20 @@ void LibMpvBackend::playUrl(const QUrl& url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LibMpvBackend::playPause() {
|
void LibMpvBackend::playPause() {
|
||||||
int paused;
|
int idle;
|
||||||
mpv_get_property(m_mpvHandle, "pause", MPV_FORMAT_FLAG, &paused);
|
mpv_get_property(m_mpvHandle, "idle-active", MPV_FORMAT_FLAG, &idle);
|
||||||
|
|
||||||
paused = paused == 0 ? 1 : 0;
|
if (idle) {
|
||||||
|
playUrl(m_url);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int paused;
|
||||||
|
mpv_get_property(m_mpvHandle, "pause", MPV_FORMAT_FLAG, &paused);
|
||||||
|
|
||||||
mpv_set_property_async(m_mpvHandle, EVENT_CODE_PAUSE, "pause", MPV_FORMAT_FLAG, &paused);
|
paused = paused == 0 ? 1 : 0;
|
||||||
|
|
||||||
|
mpv_set_property_async(m_mpvHandle, EVENT_CODE_PAUSE, "pause", MPV_FORMAT_FLAG, &paused);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibMpvBackend::pause() {
|
void LibMpvBackend::pause() {
|
||||||
|
@ -132,8 +132,12 @@ void MediaPlayer::onDurationChanged(int duration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MediaPlayer::updateTimeAndProgress(int progress, int total) {
|
void MediaPlayer::updateTimeAndProgress(int progress, int total) {
|
||||||
m_ui.m_lblTime->setText(QSL("%1/%2").arg(QDateTime::fromSecsSinceEpoch(progress).toUTC().toString("hh:mm:ss"),
|
static QString format_hours = QSL("hh:mm:ss");
|
||||||
QDateTime::fromSecsSinceEpoch(total).toUTC().toString("hh:mm:ss")));
|
static QString format_minutes = QSL("mm:ss");
|
||||||
|
QString format = total >= 3600 ? format_hours : format_minutes;
|
||||||
|
|
||||||
|
m_ui.m_lblTime->setText(QSL("%1/%2").arg(QDateTime::fromSecsSinceEpoch(progress).toUTC().toString(format),
|
||||||
|
QDateTime::fromSecsSinceEpoch(total).toUTC().toString(format)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MediaPlayer::onErrorOccurred(const QString& error_string) {
|
void MediaPlayer::onErrorOccurred(const QString& error_string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user