summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-03-21 14:44:09 +0100
committerwm4 <wm4@nowhere>2020-03-21 19:32:50 +0100
commit68d9d11ddf2817b682b0a9f87d4d42791d5666ca (patch)
treef552f3c866219d56660690846fde02c255cf967f
parent2de783125b29d42193258f885396a21598f1dde1 (diff)
downloadmpv-68d9d11ddf2817b682b0a9f87d4d42791d5666ca.tar.bz2
mpv-68d9d11ddf2817b682b0a9f87d4d42791d5666ca.tar.xz
player: playlist-pos now use -1 for "no entry selected"
It's odd that this state is observable, but is made implicit by making the property unavailable. It's also odd that an API user cannot directly put the player into such a state. Just allow reading/writing -1 (or in fact, any out of bounds index) for this case. I'm also refraining from using OPT_CHOICE for the "no selection" case, because although that would be cleaner in theory, it would cause only problems to API users due to the more complex property type (worse is better). One reason for not restricting the integer range on the input property anymore is that if there are no playlist elements, the range would contain only 1 integer, which cannot be represented anymore since the recent m_option change. This was actually broken with 1 element playlists before (and still is, with the constricted type for OSD and the add/cycle commands). Doesn't matter too much.
-rw-r--r--DOCS/interface-changes.rst3
-rw-r--r--DOCS/man/input.rst7
-rw-r--r--player/command.c16
-rw-r--r--player/loadfile.c2
4 files changed, 17 insertions, 11 deletions
diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst
index 4463930767..c63669ad7c 100644
--- a/DOCS/interface-changes.rst
+++ b/DOCS/interface-changes.rst
@@ -45,6 +45,9 @@ Interface changes
notifications were interleaved in bad ways (it could happen that a
property notification delivered after an event contained a value that was
valid only before the event happened).
+ - the playlist-pos and playlist-pos-1 properties now can return and accept
+ -1, and are never unavailable. Out of range indexes are now accepted, but
+ behave like writing -1.
--- mpv 0.32.0 ---
- change behavior when using legacy option syntax with options that start
with two dashes (``--`` instead of a ``-``). Now, using the recommended
diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst
index a212224e78..8f81b63f9f 100644
--- a/DOCS/man/input.rst
+++ b/DOCS/man/input.rst
@@ -2242,6 +2242,13 @@ Property list
Current position on playlist. The first entry is on position 0. Writing to
this property may start playback at the new position.
+ If there the playlist is empty, or if it's non-empty, but no entry is
+ "current", this property returns -1. Likewise, writing -1 will put the
+ player into idle mode (or exit playback if idle mode is not enabled). If an
+ out of range index is written to the property, this behaves as if writing -1.
+ (Before mpv 0.33.0, instead of returning -1, this property was unavailable
+ if no playlist entry was current.)
+
What happens if you write the same value back to the property is
implementation dependent. Currently, writing the same value will restart
playback from the beginning. It is possible (but not necessarily planned)
diff --git a/player/command.c b/player/command.c
index 938d9fa988..fd5ad60891 100644
--- a/player/command.c
+++ b/player/command.c
@@ -2705,26 +2705,22 @@ static int mp_property_playlist_pos_x(void *ctx, struct m_property *prop,
{
MPContext *mpctx = ctx;
struct playlist *pl = mpctx->playlist;
- if (!pl->num_entries)
- return M_PROPERTY_UNAVAILABLE;
switch (action) {
case M_PROPERTY_GET: {
int pos = playlist_entry_to_index(pl, pl->current);
- if (pos < 0)
- return M_PROPERTY_UNAVAILABLE;
- *(int *)arg = pos + base;
+ *(int *)arg = pos < 0 ? -1 : pos + base;
return M_PROPERTY_OK;
}
case M_PROPERTY_SET: {
int pos = *(int *)arg - base;
- struct playlist_entry *e = playlist_entry_from_index(pl, pos);
- if (!e)
- return M_PROPERTY_ERROR;
- mp_set_playlist_entry(mpctx, e);
+ mp_set_playlist_entry(mpctx, playlist_entry_from_index(pl, pos));
return M_PROPERTY_OK;
}
- case M_PROPERTY_GET_TYPE: {
+ case M_PROPERTY_GET_TYPE:
+ *(struct m_option *)arg = (struct m_option){.type = CONF_TYPE_INT};
+ return M_PROPERTY_OK;
+ case M_PROPERTY_GET_CONSTRICTED_TYPE: {
struct m_option opt = {
.type = CONF_TYPE_INT,
.min = base,
diff --git a/player/loadfile.c b/player/loadfile.c
index 8a8094c3e3..0ae59a0e65 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -1828,7 +1828,7 @@ void mp_set_playlist_entry(struct MPContext *mpctx, struct playlist_entry *e)
mpctx->playlist->current_was_replaced = false;
// Make it pick up the new entry.
if (mpctx->stop_play != PT_QUIT)
- mpctx->stop_play = PT_CURRENT_ENTRY;
+ mpctx->stop_play = e ? PT_CURRENT_ENTRY : PT_STOP;
mp_wakeup_core(mpctx);
}