Skip to content

player/command: add prepend and insert-prev flags to loadfile/loadlist - #17250

Open
Dudemanguy wants to merge 2 commits into
mpv-player:masterfrom
Dudemanguy:loadfile-flags2
Open

player/command: add prepend and insert-prev flags to loadfile/loadlist#17250
Dudemanguy wants to merge 2 commits into
mpv-player:masterfrom
Dudemanguy:loadfile-flags2

Conversation

@Dudemanguy

Copy link
Copy Markdown
Member

No description provided.

@na-na-hi

Copy link
Copy Markdown
Contributor

There is no reason to add these when they can already be achieved with the index argument set to 0 (prepend) or playlist-pos (insert-prev).

@Dudemanguy

Copy link
Copy Markdown
Member Author

Shorthands. Of course you can already achieve these (and others) if you use insert-at.

@na-na-hi

Copy link
Copy Markdown
Contributor

These "shorthands" only add interface complexity that led to #16837. I think it is better to document the insert-at 0 and insert-at ${playlist-pos} usage examples instead.

@Dudemanguy

Copy link
Copy Markdown
Member Author

insert-prev looks less complex to me than insert-at ${playlist-pos}

@na-na-hi

Copy link
Copy Markdown
Contributor

I still think mention in documentation is enough. We should not add less generic interfaces when generic ones are available.

@kasper93

Copy link
Copy Markdown
Member

I agree that making interface more complex is not good idea in general, but here we are only adding an alias which doesn't make it more complex in practice.

Though the usefulness of this is limited too, as anyone already would need to handle it differently.

That said, I don't think why this shouldn't be merged. Bikesheding this is waste of time, shrug.

@Dudemanguy

Dudemanguy commented Jan 21, 2026

Copy link
Copy Markdown
Member Author

We have aliases for appending things so I figured why not have them for prepending too. ¯_(ツ)_/¯ I'm sure most users would append 99% of the time but still.

Comment thread player/command.c
case LOAD_TYPE_INSERT_NEXT:
return playlist_get_next(mpctx->playlist, +1);
case LOAD_TYPE_INSERT_PREV:
return mpctx->playing ? mpctx->playing : playlist_entry_from_index(mpctx->playlist, 0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you are manipulating the playlist, shouldn't this be

mpctx->playlist->current ? mpctx->playlist->current : playlist_entry_from_index(mpctx->playlist, 0)

instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mpctx->playing is the same as mpctx->playlist->current

@rdevshp rdevshp Jul 2, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mpctx->playing is the same as mpctx->playlist->current

The version that uses mpctx->playing and the version that uses mpctx->playlist->current can produce different runtime behavior.

Consider the attached program (the attached program requires setting the MPV_BIN environment variable). Running the attached program with the line

return mpctx->playing ? mpctx->playing : playlist_entry_from_index(mpctx->playlist, 0);

prints

initial: ['a.wav:CP', 'b.wav', 'c.wav']
['x.wav', 'a.wav:P', 'b.wav:C', 'c.wav']

whereas with the line

return mpctx->playlist->current ? mpctx->playlist->current : playlist_entry_from_index(mpctx->playlist, 0);

it prints

initial: ['a.wav:CP', 'b.wav', 'c.wav']
['a.wav:P', 'x.wav', 'b.wav:C', 'c.wav']

So they are different in the sense that they can exhibit different runtime behavior.

different_positions.py

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Good observation. In this case, it appears that mpctx->playing is the one with the correct behavior. I took a look at the logs here. For both cases you have this sequence of events (expected):

[   0.068][v][cplayer] Opening done: /tmp/mpv-different-position-1c0i2bqu/a.wav
....
[   0.077][v][cplayer] Starting playback...
....
[   0.093][d][cplayer] Run command: loadfile, flags=64, args=[url="/tmp/mpv-different-position-1c0i2bqu/x.wav", flags="insert-prev", index="-1", options=""]

If we're doing an insert-prev here, then the x.wav should come before a.wav in the playlist. I'm not sure why but mpctx->playlist->current is pointing to b.wav at this point in time which is wrong.

No need to have a switch here. It's not like the enum order should be
changed willy-nilly (although the next commit is going to do that).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants