Skip to content

Commit

Permalink
src/player/mpvadapter: fix compatibility with mpv 0.38.0
Browse files Browse the repository at this point in the history
Since mpv client API 2.3 introduced with mpv 0.38.0, the loadfile
command now takes an additional argument, which breaks audio clip
generation. To fix this, optionally add the additional (and ignored)
argument to the loadfile command depending on the loaded mpv version.
  • Loading branch information
SpaghettiBorgar authored and ripose-jp committed Jun 18, 2024
1 parent 7f24f54 commit b5aa03d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/player/mpvadapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,18 @@ void MpvAdapter::open(const QString &file,

QByteArray filename = file.toUtf8();
QByteArray opts = options.join(',').toUtf8();
char *argOpts = opts.isEmpty() ? NULL : opts.data();

const char *args[5] = {
/* Since mpv client API 2.3 (mpv 0.38.0) "loadfile" places an extra argument before the options,
so we need to conditionally re-arrange the arguments array */
bool isApi23 = mpv_client_api_version() >= MPV_MAKE_VERSION(2, 3);

const char *args[] = {
"loadfile",
filename,
append ? "append-play" : "replace",
opts.isEmpty() ? NULL : opts.data(),
isApi23 ? "0" : argOpts,
isApi23 ? argOpts : NULL,
NULL
};

Expand Down Expand Up @@ -918,11 +924,15 @@ QString MpvAdapter::tempAudioClip(
optionCmd += QString("start=%1").arg(start, 0, 'f', 3).toUtf8();
optionCmd += QString(",end=%1").arg(end, 0, 'f', 3).toUtf8();
optionCmd += QString(",aid=%1").arg(aid).toUtf8();
char *argOpts = optionCmd.isEmpty() ? NULL : optionCmd.data();

bool isApi23 = mpv_client_api_version() >= MPV_MAKE_VERSION(2, 3);
const char *args[] = {
"loadfile",
input,
"replace",
optionCmd.isEmpty() ? NULL : optionCmd.data(),
isApi23 ? "0" : argOpts,
isApi23 ? argOpts : NULL,
NULL
};

Expand Down

0 comments on commit b5aa03d

Please sign in to comment.