1 /*****************************************************************************
2 * playlist.c: libvlc new API playlist handling functions
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include <libvlc_internal.h>
25 #include <vlc/libvlc.h>
29 void libvlc_playlist_play( libvlc_instance_t *p_instance, int i_id,
30 int i_options, char **ppsz_options,
31 libvlc_exception_t *p_exception )
33 ///\todo Handle additionnal options
35 if( p_instance->p_playlist->i_size == 0 )
37 libvlc_exception_raise( p_exception, "Empty playlist" );
42 /* Always use the current view when using libvlc */
43 playlist_view_t *p_view;
44 playlist_item_t *p_item;
46 if( p_instance->p_playlist->status.i_view == -1 )
48 playlist_Control( p_instance->p_playlist, PLAYLIST_GOTO,
51 p_view = playlist_ViewFind( p_instance->p_playlist,
52 p_instance->p_playlist->status.i_view );
55 libvlc_exception_raise( p_exception,
56 "Unable to find current playlist view ");
60 p_item = playlist_ItemGetById( p_instance->p_playlist, i_id );
64 libvlc_exception_raise( p_exception, "Unable to find item " );
68 playlist_Control( p_instance->p_playlist, PLAYLIST_VIEWPLAY,
69 p_instance->p_playlist->status.i_view,
70 p_view->p_root, p_item );
74 playlist_Play( p_instance->p_playlist );
78 void libvlc_playlist_pause( libvlc_instance_t *p_instance,
79 libvlc_exception_t *p_exception )
81 if( playlist_Pause( p_instance->p_playlist ) != VLC_SUCCESS )
83 libvlc_exception_raise( p_exception, "Empty playlist" );
88 void libvlc_playlist_stop( libvlc_instance_t *p_instance,
89 libvlc_exception_t *p_exception )
91 if( playlist_Stop( p_instance->p_playlist ) != VLC_SUCCESS )
93 libvlc_exception_raise( p_exception, "Empty playlist" );
97 void libvlc_playlist_clear( libvlc_instance_t *p_instance,
98 libvlc_exception_t *p_exception )
100 playlist_Clear( p_instance->p_playlist );
103 void libvlc_playlist_next( libvlc_instance_t *p_instance,
104 libvlc_exception_t *p_exception )
106 if( playlist_Next( p_instance->p_playlist ) != VLC_SUCCESS )
108 libvlc_exception_raise( p_exception, "Empty playlist" );
112 void libvlc_playlist_prev( libvlc_instance_t *p_instance,
113 libvlc_exception_t *p_exception )
115 if( playlist_Prev( p_instance->p_playlist ) != VLC_SUCCESS )
117 libvlc_exception_raise( p_exception, "Empty playlist" );
121 int libvlc_playlist_add( libvlc_instance_t *p_instance, const char *psz_uri,
122 const char *psz_name, libvlc_exception_t *p_exception )
124 return libvlc_playlist_add_extended( p_instance, psz_uri, psz_name,
125 0, NULL, p_exception );
128 int libvlc_playlist_add_extended( libvlc_instance_t *p_instance,
129 const char *psz_uri, const char *psz_name,
130 int i_options, const char **ppsz_options,
131 libvlc_exception_t *p_exception )
133 return playlist_AddExt( p_instance->p_playlist, psz_uri, psz_name,
134 PLAYLIST_INSERT, PLAYLIST_END, -1, ppsz_options,
138 int libvlc_playlist_delete_item( libvlc_instance_t *p_instance, int i_id,
139 libvlc_exception_t *p_exception )
141 return playlist_Delete( p_instance->p_playlist, i_id );
145 int libvlc_playlist_isplaying( libvlc_instance_t *p_instance,
146 libvlc_exception_t *p_exception )
148 if( !p_instance->p_playlist )
150 libvlc_exception_raise( p_exception, "No playlist" );
153 return playlist_IsPlaying( p_instance->p_playlist );
156 int libvlc_playlist_items_count( libvlc_instance_t *p_instance,
157 libvlc_exception_t *p_exception )
159 if( !p_instance->p_playlist )
161 libvlc_exception_raise( p_exception, "No playlist" );
164 return p_instance->p_playlist->i_size;
167 libvlc_input_t * libvlc_playlist_get_input( libvlc_instance_t *p_instance,
168 libvlc_exception_t *p_exception )
170 libvlc_input_t *p_input;
172 vlc_mutex_lock( &p_instance->p_playlist->object_lock );
173 if( p_instance->p_playlist->p_input == NULL )
175 libvlc_exception_raise( p_exception, "No active input" );
176 vlc_mutex_unlock( &p_instance->p_playlist->object_lock );
179 p_input = (libvlc_input_t *)malloc( sizeof( libvlc_input_t ) );
181 p_input->i_input_id = p_instance->p_playlist->p_input->i_object_id;
182 p_input->p_instance = p_instance;
183 vlc_mutex_unlock( &p_instance->p_playlist->object_lock );