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