]> git.sesse.net Git - vlc/blob - src/control/control_playlist.c
Fix a bug whereby --disable-shared-libvlc would actually enable it
[vlc] / src / control / 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_stop( libvlc_instance_t *p_instance,
79                            libvlc_exception_t *p_exception )
80 {
81     if( playlist_Stop( p_instance->p_playlist ) != VLC_SUCCESS )
82     {
83         libvlc_exception_raise( p_exception, "Empty playlist" );
84     }
85 }
86
87 void libvlc_playlist_clear( libvlc_instance_t *p_instance,
88                            libvlc_exception_t *p_exception )
89 {
90     playlist_Clear( p_instance->p_playlist );
91 }
92
93 void libvlc_playlist_next( libvlc_instance_t *p_instance,
94                            libvlc_exception_t *p_exception )
95 {
96     if( playlist_Next( p_instance->p_playlist ) != VLC_SUCCESS )
97     {
98         libvlc_exception_raise( p_exception, "Empty playlist" );
99     }
100 }
101
102 void libvlc_playlist_prev( libvlc_instance_t *p_instance,
103                            libvlc_exception_t *p_exception )
104 {
105     if( playlist_Prev( p_instance->p_playlist ) != VLC_SUCCESS )
106     {
107         libvlc_exception_raise( p_exception, "Empty playlist" );
108     }
109 }
110
111 int libvlc_playlist_add( libvlc_instance_t *p_instance, const char *psz_uri,
112                          const char *psz_name, libvlc_exception_t *p_exception )
113 {
114     return libvlc_playlist_add_extended( p_instance, psz_uri, psz_name,
115                                          0, NULL, p_exception );
116 }
117
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 )
122 {
123     return playlist_AddExt( p_instance->p_playlist, psz_uri, psz_name,
124                             PLAYLIST_INSERT, PLAYLIST_END, -1, ppsz_options,
125                             i_options );
126 }
127
128 int libvlc_playlist_isplaying( libvlc_instance_t *p_instance,
129                                libvlc_exception_t *p_exception )
130 {
131     if( !p_instance->p_playlist )
132     {
133         libvlc_exception_raise( p_exception, "No playlist" );
134         return 0;
135     }
136     return playlist_IsPlaying( p_instance->p_playlist );
137 }
138
139 int libvlc_playlist_items_count( libvlc_instance_t *p_instance,
140                                  libvlc_exception_t *p_exception )
141 {
142     if( !p_instance->p_playlist )
143     {
144         libvlc_exception_raise( p_exception, "No playlist" );
145         return 0;
146     }
147     return p_instance->p_playlist->i_size;
148 }
149
150 libvlc_input_t * libvlc_playlist_get_input( libvlc_instance_t *p_instance,
151                                             libvlc_exception_t *p_exception )
152 {
153     libvlc_input_t *p_input;
154
155     vlc_mutex_lock( &p_instance->p_playlist->object_lock );
156     if( p_instance->p_playlist->p_input == NULL )
157     {
158         libvlc_exception_raise( p_exception, "No active input" );
159         vlc_mutex_unlock( &p_instance->p_playlist->object_lock );
160         return NULL;
161     }
162     p_input = (libvlc_input_t *)malloc( sizeof( libvlc_input_t ) );
163
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 );
167
168     return p_input;
169 }