[vlc-devel] [PATCH 1/2] dbus: simplify previous/next detection
Romain Vimont
rom1v at videolabs.io
Tue Apr 6 16:16:38 UTC 2021
Use the existing playlist API to detect if there is a previous or next
item in the playlist.
---
modules/control/dbus/dbus_player.c | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/modules/control/dbus/dbus_player.c b/modules/control/dbus/dbus_player.c
index 195d82e717..0fb8e62d7f 100644
--- a/modules/control/dbus/dbus_player.c
+++ b/modules/control/dbus/dbus_player.c
@@ -256,16 +256,10 @@ MarshalCanGoNext( intf_thread_t *p_intf, DBusMessageIter *container )
{
vlc_playlist_t *playlist = p_intf->p_sys->playlist;
vlc_playlist_Lock(playlist);
- size_t count = vlc_playlist_Count(playlist);
- ssize_t index = vlc_playlist_GetCurrentIndex(playlist);
- enum vlc_playlist_playback_repeat repeat_mode =
- vlc_playlist_GetPlaybackRepeat(playlist);
+ bool has_next = vlc_playlist_HasNext(playlist);
vlc_playlist_Unlock(playlist);
- dbus_bool_t b_can_go_next =
- count != 0 &&
- ((index != -1 && (size_t)index < count - 1) ||
- repeat_mode != VLC_PLAYLIST_PLAYBACK_REPEAT_NONE);
+ dbus_bool_t b_can_go_next = has_next;
if( !dbus_message_iter_append_basic( container, DBUS_TYPE_BOOLEAN,
&b_can_go_next ) )
@@ -279,15 +273,10 @@ MarshalCanGoPrevious( intf_thread_t *p_intf, DBusMessageIter *container )
{
vlc_playlist_t *playlist = p_intf->p_sys->playlist;
vlc_playlist_Lock(playlist);
- size_t count = vlc_playlist_Count(playlist);
- ssize_t index = vlc_playlist_GetCurrentIndex(playlist);
- enum vlc_playlist_playback_repeat repeat_mode =
- vlc_playlist_GetPlaybackRepeat(playlist);
+ bool has_prev = vlc_playlist_HasPrev(playlist);
vlc_playlist_Unlock(playlist);
- dbus_bool_t b_can_go_previous =
- count != 0 &&
- (index > 0 || repeat_mode != VLC_PLAYLIST_PLAYBACK_REPEAT_NONE);
+ dbus_bool_t b_can_go_previous = has_prev;
if( !dbus_message_iter_append_basic( container, DBUS_TYPE_BOOLEAN,
&b_can_go_previous ) )
--
2.31.0
More information about the vlc-devel
mailing list