1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2018 VLC authors and VideoLAN
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
27 #include "input/player.h"
34 /* called when the current media has changed _automatically_ (not on
37 player_on_current_media_changed(vlc_player_t
*player
, input_item_t
*new_media
,
41 vlc_playlist_t
*playlist
= userdata
;
43 /* the playlist and the player share the lock */
44 vlc_playlist_AssertLocked(playlist
);
46 input_item_t
*media
= playlist
->current
!= -1
47 ? playlist
->items
.data
[playlist
->current
]->media
49 if (new_media
== media
)
53 ssize_t index
= new_media
? vlc_playlist_IndexOfMedia(playlist
, new_media
)
56 struct vlc_playlist_state state
;
57 vlc_playlist_state_Save(playlist
, &state
);
59 playlist
->current
= index
;
60 playlist
->has_prev
= vlc_playlist_ComputeHasPrev(playlist
);
61 playlist
->has_next
= vlc_playlist_ComputeHasNext(playlist
);
63 vlc_playlist_state_NotifyChanges(playlist
, &state
);
67 on_player_media_meta_changed(vlc_player_t
*player
, input_item_t
*media
,
71 vlc_playlist_t
*playlist
= userdata
;
73 /* the playlist and the player share the lock */
74 vlc_playlist_AssertLocked(playlist
);
76 vlc_playlist_NotifyMediaUpdated(playlist
, media
);
80 on_player_media_length_changed(vlc_player_t
*player
, vlc_tick_t new_length
,
84 VLC_UNUSED(new_length
);
85 vlc_playlist_t
*playlist
= userdata
;
87 /* the playlist and the player share the lock */
88 vlc_playlist_AssertLocked(playlist
);
90 input_item_t
*media
= vlc_player_GetCurrentMedia(player
);
93 vlc_playlist_NotifyMediaUpdated(playlist
, media
);
97 on_player_media_subitems_changed(vlc_player_t
*player
, input_item_t
*media
,
98 input_item_node_t
*subitems
, void *userdata
)
102 vlc_playlist_t
*playlist
= userdata
;
103 vlc_playlist_ExpandItemFromNode(playlist
, subitems
);
106 static input_item_t
*
107 player_get_next_media(vlc_player_t
*player
, void *userdata
)
110 vlc_playlist_t
*playlist
= userdata
;
111 return vlc_playlist_GetNextMedia(playlist
);
114 static const struct vlc_player_media_provider player_media_provider
= {
115 .get_next
= player_get_next_media
,
118 static const struct vlc_player_cbs player_callbacks
= {
119 .on_current_media_changed
= player_on_current_media_changed
,
120 .on_media_meta_changed
= on_player_media_meta_changed
,
121 .on_length_changed
= on_player_media_length_changed
,
122 .on_media_subitems_changed
= on_player_media_subitems_changed
,
126 vlc_playlist_PlayerInit(vlc_playlist_t
*playlist
, vlc_object_t
*parent
)
128 playlist
->player
= vlc_player_New(parent
, &player_media_provider
, playlist
);
129 if (unlikely(!playlist
->player
))
132 vlc_player_Lock(playlist
->player
);
133 /* the playlist and the player share the lock */
134 vlc_playlist_AssertLocked(playlist
);
135 playlist
->player_listener
= vlc_player_AddListener(playlist
->player
,
138 vlc_player_Unlock(playlist
->player
);
139 if (unlikely(!playlist
->player_listener
))
141 vlc_player_Delete(playlist
->player
);
148 vlc_playlist_PlayerDestroy(vlc_playlist_t
*playlist
)
150 vlc_player_Lock(playlist
->player
);
151 vlc_player_RemoveListener(playlist
->player
, playlist
->player_listener
);
152 vlc_player_Unlock(playlist
->player
);
154 vlc_player_Delete(playlist
->player
);
158 vlc_playlist_GetPlayer(vlc_playlist_t
*playlist
)
160 return playlist
->player
;
164 vlc_playlist_Start(vlc_playlist_t
*playlist
)
166 return vlc_player_Start(playlist
->player
);
170 vlc_playlist_Stop(vlc_playlist_t
*playlist
)
172 vlc_player_Stop(playlist
->player
);
176 vlc_playlist_Pause(vlc_playlist_t
*playlist
)
178 vlc_player_Pause(playlist
->player
);
182 vlc_playlist_Resume(vlc_playlist_t
*playlist
)
184 vlc_player_Resume(playlist
->player
);