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