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_stop( libvlc_instance_t *p_instance,
79 libvlc_exception_t *p_exception )
81 if( playlist_Stop( p_instance->p_playlist ) != VLC_SUCCESS )
83 libvlc_exception_raise( p_exception, "Empty playlist" );
87 void libvlc_playlist_clear( libvlc_instance_t *p_instance,
88 libvlc_exception_t *p_exception )
90 playlist_Clear( p_instance->p_playlist );
93 void libvlc_playlist_next( libvlc_instance_t *p_instance,
94 libvlc_exception_t *p_exception )
96 if( playlist_Next( p_instance->p_playlist ) != VLC_SUCCESS )
98 libvlc_exception_raise( p_exception, "Empty playlist" );
102 void libvlc_playlist_prev( libvlc_instance_t *p_instance,
103 libvlc_exception_t *p_exception )
105 if( playlist_Prev( p_instance->p_playlist ) != VLC_SUCCESS )
107 libvlc_exception_raise( p_exception, "Empty playlist" );
111 int libvlc_playlist_add( libvlc_instance_t *p_instance, const char *psz_uri,
112 const char *psz_name, libvlc_exception_t *p_exception )
114 return libvlc_playlist_add_extended( p_instance, psz_uri, psz_name,
115 0, NULL, p_exception );
118 int libvlc_playlist_add_extended( libvlc_instance_t *p_instance,
119 const char *psz_uri, const char *psz_name,
120 int i_options, const char **ppsz_options,
121 libvlc_exception_t *p_exception )
123 return playlist_AddExt( p_instance->p_playlist, psz_uri, psz_name,
124 PLAYLIST_INSERT, PLAYLIST_END, -1, ppsz_options,
128 int libvlc_playlist_isplaying( libvlc_instance_t *p_instance,
129 libvlc_exception_t *p_exception )
131 if( !p_instance->p_playlist )
133 libvlc_exception_raise( p_exception, "No playlist" );
136 return playlist_IsPlaying( p_instance->p_playlist );
139 int libvlc_playlist_items_count( libvlc_instance_t *p_instance,
140 libvlc_exception_t *p_exception )
142 if( !p_instance->p_playlist )
144 libvlc_exception_raise( p_exception, "No playlist" );
147 return p_instance->p_playlist->i_size;
150 libvlc_input_t * libvlc_playlist_get_input( libvlc_instance_t *p_instance,
151 libvlc_exception_t *p_exception )
153 libvlc_input_t *p_input;
155 vlc_mutex_lock( &p_instance->p_playlist->object_lock );
156 if( p_instance->p_playlist->p_input == NULL )
158 libvlc_exception_raise( p_exception, "No active input" );
159 vlc_mutex_unlock( &p_instance->p_playlist->object_lock );
162 p_input = (libvlc_input_t *)malloc( sizeof( libvlc_input_t ) );
164 p_input->i_input_id = p_instance->p_playlist->p_input->i_object_id;
165 p_input->p_instance = p_instance;
166 vlc_mutex_unlock( &p_instance->p_playlist->object_lock );