]> git.sesse.net Git - vlc/blob - src/control/playlist.c
delete item added in playlist control
[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
27 #include <vlc/intf.h>
28
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 )
32 {
33     ///\todo Handle additionnal options
34
35     if( p_instance->p_playlist->i_size == 0 )
36     {
37         libvlc_exception_raise( p_exception, "Empty playlist" );
38         return;
39     }
40     if( i_id > 0 )
41     {
42         /* Always use the current view when using libvlc */
43         playlist_view_t *p_view;
44         playlist_item_t *p_item;
45
46         if( p_instance->p_playlist->status.i_view == -1 )
47         {
48             playlist_Control( p_instance->p_playlist, PLAYLIST_GOTO,
49                               i_id );
50         }
51         p_view = playlist_ViewFind( p_instance->p_playlist,
52                                     p_instance->p_playlist->status.i_view );
53         if( !p_view )
54         {
55              libvlc_exception_raise( p_exception,
56                                      "Unable to find current playlist view ");
57              return;
58         }
59
60         p_item = playlist_ItemGetById( p_instance->p_playlist, i_id );
61
62         if( !p_item )
63         {
64             libvlc_exception_raise( p_exception, "Unable to find item " );
65             return;
66         }
67
68         playlist_Control( p_instance->p_playlist, PLAYLIST_VIEWPLAY,
69                           p_instance->p_playlist->status.i_view,
70                           p_view->p_root, p_item );
71     }
72     else
73     {
74         playlist_Play( p_instance->p_playlist );
75     }
76 }
77
78 void libvlc_playlist_pause( libvlc_instance_t *p_instance,
79                            libvlc_exception_t *p_exception )
80 {
81     if( playlist_Pause( p_instance->p_playlist ) != VLC_SUCCESS )
82     {
83         libvlc_exception_raise( p_exception, "Empty playlist" );
84     }
85 }
86
87
88 void libvlc_playlist_stop( libvlc_instance_t *p_instance,
89                            libvlc_exception_t *p_exception )
90 {
91     if( playlist_Stop( p_instance->p_playlist ) != VLC_SUCCESS )
92     {
93         libvlc_exception_raise( p_exception, "Empty playlist" );
94     }
95 }
96
97 void libvlc_playlist_clear( libvlc_instance_t *p_instance,
98                            libvlc_exception_t *p_exception )
99 {
100     playlist_Clear( p_instance->p_playlist );
101 }
102
103 void libvlc_playlist_next( libvlc_instance_t *p_instance,
104                            libvlc_exception_t *p_exception )
105 {
106     if( playlist_Next( p_instance->p_playlist ) != VLC_SUCCESS )
107     {
108         libvlc_exception_raise( p_exception, "Empty playlist" );
109     }
110 }
111
112 void libvlc_playlist_prev( libvlc_instance_t *p_instance,
113                            libvlc_exception_t *p_exception )
114 {
115     if( playlist_Prev( p_instance->p_playlist ) != VLC_SUCCESS )
116     {
117         libvlc_exception_raise( p_exception, "Empty playlist" );
118     }
119 }
120
121 int libvlc_playlist_add( libvlc_instance_t *p_instance, const char *psz_uri,
122                          const char *psz_name, libvlc_exception_t *p_exception )
123 {
124     return libvlc_playlist_add_extended( p_instance, psz_uri, psz_name,
125                                          0, NULL, p_exception );
126 }
127
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 )
132 {
133     return playlist_AddExt( p_instance->p_playlist, psz_uri, psz_name,
134                             PLAYLIST_INSERT, PLAYLIST_END, -1, ppsz_options,
135                             i_options );
136 }
137
138 int libvlc_playlist_delete_item( libvlc_instance_t *p_instance, int i_id,
139                                  libvlc_exception_t *p_exception )
140 {
141     return playlist_Delete( p_instance->p_playlist, i_id );
142 }
143
144
145 int libvlc_playlist_isplaying( libvlc_instance_t *p_instance,
146                                libvlc_exception_t *p_exception )
147 {
148     if( !p_instance->p_playlist )
149     {
150         libvlc_exception_raise( p_exception, "No playlist" );
151         return 0;
152     }
153     return playlist_IsPlaying( p_instance->p_playlist );
154 }
155
156 int libvlc_playlist_items_count( libvlc_instance_t *p_instance,
157                                  libvlc_exception_t *p_exception )
158 {
159     if( !p_instance->p_playlist )
160     {
161         libvlc_exception_raise( p_exception, "No playlist" );
162         return 0;
163     }
164     return p_instance->p_playlist->i_size;
165 }
166
167 libvlc_input_t * libvlc_playlist_get_input( libvlc_instance_t *p_instance,
168                                             libvlc_exception_t *p_exception )
169 {
170     libvlc_input_t *p_input;
171
172     vlc_mutex_lock( &p_instance->p_playlist->object_lock );
173     if( p_instance->p_playlist->p_input == NULL )
174     {
175         libvlc_exception_raise( p_exception, "No active input" );
176         vlc_mutex_unlock( &p_instance->p_playlist->object_lock );
177         return NULL;
178     }
179     p_input = (libvlc_input_t *)malloc( sizeof( libvlc_input_t ) );
180
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 );
184
185     return p_input;
186 }