Skip to content

Commit

Permalink
Port away from deprecated/removed APIs in mpv 2.0
Browse files Browse the repository at this point in the history
Register observers as MPV_EVENT_IDLE is deprecated and
MPV_EVENT_PAUSE/MPV_EVENT_UNPAUSE have been removed.
  • Loading branch information
easyteacher committed Feb 21, 2022
1 parent 8de8f0f commit 7864f24
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions src/mpvhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ MpvHandler::MpvHandler(int64_t wid, QObject *parent):
mpv_observe_property(mpv, 0, "sub-visibility", MPV_FORMAT_FLAG);
mpv_observe_property(mpv, 0, "mute", MPV_FORMAT_FLAG);
mpv_observe_property(mpv, 0, "core-idle", MPV_FORMAT_FLAG);
mpv_observe_property(mpv, 0, "idle-active", MPV_FORMAT_FLAG);
mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_FLAG);
mpv_observe_property(mpv, 0, "paused-for-cache", MPV_FORMAT_FLAG);

// setup callback event handling
Expand Down Expand Up @@ -191,6 +193,31 @@ bool MpvHandler::event(QEvent *event)
ShowText(QString(), 0);
}
}
else if(QString(prop->name) == "idle-active")
{
if(prop->format == MPV_FORMAT_FLAG)
{
if((bool)*(unsigned*)prop->data)
{
fileInfo.length = 0;
setTime(0);
setPlayState(Mpv::Idle);
}
}
}
else if(QString(prop->name) == "pause")
{
if(prop->format == MPV_FORMAT_FLAG)
{
if((bool)*(unsigned*)prop->data)
{
setPlayState(Mpv::Paused);
ShowText(QString(), 0);
}
else
setPlayState(Mpv::Playing);
}
}
else if(QString(prop->name) == "paused-for-cache")
{
if(prop->format == MPV_FORMAT_FLAG)
Expand All @@ -203,26 +230,14 @@ bool MpvHandler::event(QEvent *event)
}
break;
}
case MPV_EVENT_IDLE:
fileInfo.length = 0;
setTime(0);
setPlayState(Mpv::Idle);
break;
// these two look like they're reversed but they aren't. the names are misleading.
// these two look like they're reversed but they aren't. the names are misleading.
case MPV_EVENT_START_FILE:
setPlayState(Mpv::Loaded);
break;
case MPV_EVENT_FILE_LOADED:
setPlayState(Mpv::Started);
LoadFileInfo();
SetProperties();
case MPV_EVENT_UNPAUSE:
setPlayState(Mpv::Playing);
break;
case MPV_EVENT_PAUSE:
setPlayState(Mpv::Paused);
ShowText(QString(), 0);
break;
case MPV_EVENT_END_FILE:
if(playState == Mpv::Loaded)
ShowText(tr("File couldn't be opened"));
Expand Down

0 comments on commit 7864f24

Please sign in to comment.