]> git.sesse.net Git - vlc/blob - src/control/playlist.c
0872b5ac86032e6e30de0dd0004eb23a4345b37b
[vlc] / src / control / playlist.c
1 /*****************************************************************************
2  * playlist.c: libvlc new API playlist handling functions
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #include "libvlc_internal.h"
25 #include <vlc/libvlc.h>
26 #include <vlc_playlist.h>
27
28 #include <assert.h>
29
30 #define PL p_instance->p_libvlc_int->p_playlist
31
32 void libvlc_playlist_loop( libvlc_instance_t *p_instance, vlc_bool_t loop,
33                            libvlc_exception_t *p_e)
34 {
35     assert( PL );
36     var_SetBool(PL,"loop",loop);
37 }
38
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 )
42 {
43     assert( PL );
44     ///\todo Handle additionnal options
45
46     if( PL->items.i_size == 0 ) RAISEVOID( "Empty playlist" );
47     if( i_id > 0 )
48     {
49         playlist_item_t *p_item = playlist_ItemGetById( PL, i_id, VLC_TRUE );
50         if( !p_item ) RAISEVOID( "Unable to find item" );
51
52         playlist_Control( PL, PLAYLIST_VIEWPLAY, VLC_FALSE,
53                           PL->status.p_node, p_item );
54     }
55     else
56     {
57         playlist_Play( PL );
58     }
59 }
60
61 void libvlc_playlist_pause( libvlc_instance_t *p_instance,
62                            libvlc_exception_t *p_e )
63 {
64     assert( PL );
65     if( playlist_Pause( PL ) != VLC_SUCCESS )
66         RAISEVOID( "Empty playlist" );
67 }
68
69
70 void libvlc_playlist_stop( libvlc_instance_t *p_instance,
71                            libvlc_exception_t *p_e )
72 {
73     assert( PL );
74     if( playlist_Stop( PL ) != VLC_SUCCESS )
75         RAISEVOID( "Empty playlist" );
76 }
77
78 void libvlc_playlist_clear( libvlc_instance_t *p_instance,
79                            libvlc_exception_t *p_e )
80 {
81     assert( PL );
82     playlist_Clear( PL, VLC_FALSE );
83 }
84
85 void libvlc_playlist_next( libvlc_instance_t *p_instance,
86                            libvlc_exception_t *p_e )
87 {
88     assert( PL );
89     if( playlist_Next( PL ) != VLC_SUCCESS )
90         RAISEVOID( "Empty playlist" );
91 }
92
93 void libvlc_playlist_prev( libvlc_instance_t *p_instance,
94                            libvlc_exception_t *p_e )
95 {
96     if( playlist_Prev( PL ) != VLC_SUCCESS )
97         RAISEVOID( "Empty playlist" );
98 }
99
100 int libvlc_playlist_add( libvlc_instance_t *p_instance, const char *psz_uri,
101                          const char *psz_name, libvlc_exception_t *p_e )
102 {
103     return libvlc_playlist_add_extended( p_instance, psz_uri, psz_name,
104                                          0, NULL, p_e );
105 }
106
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 )
111 {
112     assert( PL );
113     return playlist_AddExt( PL, psz_uri, psz_name,
114                             PLAYLIST_INSERT, PLAYLIST_END, -1, ppsz_options,
115                             i_options, 1 );
116 }
117
118 int libvlc_playlist_delete_item( libvlc_instance_t *p_instance, int i_id,
119                                  libvlc_exception_t *p_e )
120 {
121     playlist_item_t *p_item;
122     assert( PL );
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 );
127         if( i_ret ) {
128             libvlc_exception_raise( p_e, "delete failed" );
129             vlc_mutex_unlock( &PL->object_lock );
130             return VLC_EGENERIC;
131         }
132         else {
133             vlc_mutex_unlock( &PL->object_lock );
134             return VLC_SUCCESS;
135         }
136     }
137     libvlc_exception_raise( p_e, "item not found" );
138     vlc_mutex_unlock( &PL->object_lock );
139     return VLC_EGENERIC;
140 }
141
142
143 int libvlc_playlist_isplaying( libvlc_instance_t *p_instance,
144                                libvlc_exception_t *p_e )
145 {
146     assert( PL );
147     return playlist_IsPlaying( PL );
148 }
149
150 int libvlc_playlist_items_count( libvlc_instance_t *p_instance,
151                                  libvlc_exception_t *p_e )
152 {
153     assert( PL );
154     return PL->items.i_size;
155 }
156
157 libvlc_input_t * libvlc_playlist_get_input( libvlc_instance_t *p_instance,
158                                             libvlc_exception_t *p_e )
159 {
160     libvlc_input_t *p_input;
161     assert( PL );
162
163     vlc_mutex_lock( &PL->object_lock );
164     if( PL->p_input == NULL )
165     {
166         libvlc_exception_raise( p_e, "No active input" );
167         vlc_mutex_unlock( &PL->object_lock );
168         return NULL;
169     }
170     p_input = (libvlc_input_t *)malloc( sizeof( libvlc_input_t ) );
171
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 );
175
176     return p_input;
177 }