]> git.sesse.net Git - vlc/blob - src/control/playlist.c
Fixed a missing assert.h inclusion.
[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 #include <assert.h>
30
31 void libvlc_playlist_play( libvlc_instance_t *p_instance, int i_id,
32                            int i_options, char **ppsz_options,
33                            libvlc_exception_t *p_e )
34 {
35     assert( p_instance->p_playlist );
36     ///\todo Handle additionnal options
37
38     if( p_instance->p_playlist->i_size == 0 ) RAISEVOID( "Empty playlist" );
39     if( i_id > 0 )
40     {
41         playlist_item_t *p_item = playlist_ItemGetById( p_instance->p_playlist,
42                                                         i_id );
43         if( !p_item ) RAISEVOID( "Unable to find item" );
44
45         playlist_LockControl( p_instance->p_playlist, PLAYLIST_VIEWPLAY,
46                           p_instance->p_playlist->status.p_node, p_item );
47     }
48     else
49     {
50         playlist_Play( p_instance->p_playlist );
51     }
52 }
53
54 void libvlc_playlist_pause( libvlc_instance_t *p_instance,
55                            libvlc_exception_t *p_e )
56 {
57     assert( p_instance->p_playlist );
58     if( playlist_Pause( p_instance->p_playlist ) != VLC_SUCCESS )
59         RAISEVOID( "Empty playlist" );
60 }
61
62
63 void libvlc_playlist_stop( libvlc_instance_t *p_instance,
64                            libvlc_exception_t *p_e )
65 {
66     assert( p_instance->p_playlist );
67     if( playlist_Stop( p_instance->p_playlist ) != VLC_SUCCESS )
68         RAISEVOID( "Empty playlist" );
69 }
70
71 void libvlc_playlist_clear( libvlc_instance_t *p_instance,
72                            libvlc_exception_t *p_e )
73 {
74     assert( p_instance->p_playlist );
75     playlist_Clear( p_instance->p_playlist );
76 }
77
78 void libvlc_playlist_next( libvlc_instance_t *p_instance,
79                            libvlc_exception_t *p_e )
80 {
81     assert( p_instance->p_playlist );
82     if( playlist_Next( p_instance->p_playlist ) != VLC_SUCCESS )
83         RAISEVOID( "Empty playlist" );
84 }
85
86 void libvlc_playlist_prev( libvlc_instance_t *p_instance,
87                            libvlc_exception_t *p_e )
88 {
89     if( playlist_Prev( p_instance->p_playlist ) != VLC_SUCCESS )
90         RAISEVOID( "Empty playlist" );
91 }
92
93 int libvlc_playlist_add( libvlc_instance_t *p_instance, const char *psz_uri,
94                          const char *psz_name, libvlc_exception_t *p_e )
95 {
96     return libvlc_playlist_add_extended( p_instance, psz_uri, psz_name,
97                                          0, NULL, p_e );
98 }
99
100 int libvlc_playlist_add_extended( libvlc_instance_t *p_instance,
101                                   const char *psz_uri, const char *psz_name,
102                                   int i_options, const char **ppsz_options,
103                                   libvlc_exception_t *p_e )
104 {
105     assert( p_instance->p_playlist );
106     return playlist_PlaylistAddExt( p_instance->p_playlist, psz_uri, psz_name,
107                             PLAYLIST_INSERT, PLAYLIST_END, -1, ppsz_options,
108                             i_options );
109 }
110
111 int libvlc_playlist_delete_item( libvlc_instance_t *p_instance, int i_id,
112                                  libvlc_exception_t *p_e )
113 {
114     assert( p_instance->p_playlist );
115     return playlist_DeleteFromItemId( p_instance->p_playlist, i_id );
116 }
117
118
119 int libvlc_playlist_isplaying( libvlc_instance_t *p_instance,
120                                libvlc_exception_t *p_e )
121 {
122     assert( p_instance->p_playlist );
123     return playlist_IsPlaying( p_instance->p_playlist );
124 }
125
126 int libvlc_playlist_items_count( libvlc_instance_t *p_instance,
127                                  libvlc_exception_t *p_e )
128 {
129     assert( p_instance->p_playlist );
130     return p_instance->p_playlist->i_size;
131 }
132
133 libvlc_input_t * libvlc_playlist_get_input( libvlc_instance_t *p_instance,
134                                             libvlc_exception_t *p_e )
135 {
136     libvlc_input_t *p_input;
137     assert( p_instance->p_playlist );
138
139     vlc_mutex_lock( &p_instance->p_playlist->object_lock );
140     if( p_instance->p_playlist->p_input == NULL )
141     {
142         libvlc_exception_raise( p_e, "No active input" );
143         vlc_mutex_unlock( &p_instance->p_playlist->object_lock );
144         return NULL;
145     }
146     p_input = (libvlc_input_t *)malloc( sizeof( libvlc_input_t ) );
147
148     p_input->i_input_id = p_instance->p_playlist->p_input->i_object_id;
149     p_input->p_instance = p_instance;
150     vlc_mutex_unlock( &p_instance->p_playlist->object_lock );
151
152     return p_input;
153 }