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>
26 #include <vlc_playlist.h>
30 #define PL p_instance->p_libvlc_int->p_playlist
32 void libvlc_playlist_loop( libvlc_instance_t *p_instance, vlc_bool_t loop,
33 libvlc_exception_t *p_e)
36 var_SetBool(PL,"loop",loop);
39 void libvlc_playlist_play( libvlc_instance_t *p_instance, int i_id,
40 int i_options, char **ppsz_options,
41 libvlc_exception_t *p_e )
44 ///\todo Handle additionnal options
46 if( PL->items.i_size == 0 ) RAISEVOID( "Empty playlist" );
49 playlist_item_t *p_item = playlist_ItemGetById( PL, i_id, VLC_TRUE );
50 if( !p_item ) RAISEVOID( "Unable to find item" );
52 playlist_Control( PL, PLAYLIST_VIEWPLAY, VLC_FALSE,
53 PL->status.p_node, p_item );
61 void libvlc_playlist_pause( libvlc_instance_t *p_instance,
62 libvlc_exception_t *p_e )
65 if( playlist_Pause( PL ) != VLC_SUCCESS )
66 RAISEVOID( "Empty playlist" );
70 void libvlc_playlist_stop( libvlc_instance_t *p_instance,
71 libvlc_exception_t *p_e )
74 if( playlist_Stop( PL ) != VLC_SUCCESS )
75 RAISEVOID( "Empty playlist" );
78 void libvlc_playlist_clear( libvlc_instance_t *p_instance,
79 libvlc_exception_t *p_e )
82 playlist_Clear( PL, VLC_FALSE );
85 void libvlc_playlist_next( libvlc_instance_t *p_instance,
86 libvlc_exception_t *p_e )
89 if( playlist_Next( PL ) != VLC_SUCCESS )
90 RAISEVOID( "Empty playlist" );
93 void libvlc_playlist_prev( libvlc_instance_t *p_instance,
94 libvlc_exception_t *p_e )
96 if( playlist_Prev( PL ) != VLC_SUCCESS )
97 RAISEVOID( "Empty playlist" );
100 int libvlc_playlist_add( libvlc_instance_t *p_instance, const char *psz_uri,
101 const char *psz_name, libvlc_exception_t *p_e )
103 return libvlc_playlist_add_extended( p_instance, psz_uri, psz_name,
107 int libvlc_playlist_add_extended( libvlc_instance_t *p_instance,
108 const char *psz_uri, const char *psz_name,
109 int i_options, const char **ppsz_options,
110 libvlc_exception_t *p_e )
113 return playlist_AddExt( PL, psz_uri, psz_name,
114 PLAYLIST_INSERT, PLAYLIST_END, -1, ppsz_options,
118 int libvlc_playlist_delete_item( libvlc_instance_t *p_instance, int i_id,
119 libvlc_exception_t *p_e )
121 playlist_item_t *p_item;
123 vlc_mutex_lock( &PL->object_lock );
124 p_item = playlist_ItemGetById( PL, i_id, VLC_TRUE );
125 if( p_item && p_item->p_input ) {
126 int i_ret = playlist_DeleteFromInput( PL, p_item->p_input->i_id, VLC_TRUE );
128 libvlc_exception_raise( p_e, "delete failed" );
129 vlc_mutex_unlock( &PL->object_lock );
133 vlc_mutex_unlock( &PL->object_lock );
137 libvlc_exception_raise( p_e, "item not found" );
138 vlc_mutex_unlock( &PL->object_lock );
143 int libvlc_playlist_isplaying( libvlc_instance_t *p_instance,
144 libvlc_exception_t *p_e )
147 return playlist_IsPlaying( PL );
150 int libvlc_playlist_items_count( libvlc_instance_t *p_instance,
151 libvlc_exception_t *p_e )
154 return PL->items.i_size;
157 libvlc_input_t * libvlc_playlist_get_input( libvlc_instance_t *p_instance,
158 libvlc_exception_t *p_e )
160 libvlc_input_t *p_input;
163 vlc_mutex_lock( &PL->object_lock );
164 if( PL->p_input == NULL )
166 libvlc_exception_raise( p_e, "No active input" );
167 vlc_mutex_unlock( &PL->object_lock );
170 p_input = (libvlc_input_t *)malloc( sizeof( libvlc_input_t ) );
172 p_input->i_input_id = PL->p_input->i_object_id;
173 p_input->p_instance = p_instance;
174 vlc_mutex_unlock( &PL->object_lock );