]> git.sesse.net Git - vlc/blob - src/control/playlist.c
Merge back branch 0.8.6-playlist-vlm to trunk.
[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         playlist_item_t *p_item = playlist_ItemGetById( p_instance->p_playlist, i_id );
43
44         if( !p_item )
45         {
46             libvlc_exception_raise( p_exception, "Unable to find item " );
47             return;
48         }
49         playlist_Control( p_instance->p_playlist, PLAYLIST_VIEWPLAY,
50                           p_instance->p_playlist->status.p_node, p_item );
51     }
52     else
53     {
54         playlist_Play( p_instance->p_playlist );
55     }
56 }
57
58 void libvlc_playlist_pause( libvlc_instance_t *p_instance,
59                            libvlc_exception_t *p_exception )
60 {
61     if( playlist_Pause( p_instance->p_playlist ) != VLC_SUCCESS )
62     {
63         libvlc_exception_raise( p_exception, "Empty playlist" );
64     }
65 }
66
67
68 void libvlc_playlist_stop( libvlc_instance_t *p_instance,
69                            libvlc_exception_t *p_exception )
70 {
71     if( playlist_Stop( p_instance->p_playlist ) != VLC_SUCCESS )
72     {
73         libvlc_exception_raise( p_exception, "Empty playlist" );
74     }
75 }
76
77 void libvlc_playlist_clear( libvlc_instance_t *p_instance,
78                            libvlc_exception_t *p_exception )
79 {
80     playlist_Clear( p_instance->p_playlist );
81 }
82
83 void libvlc_playlist_next( libvlc_instance_t *p_instance,
84                            libvlc_exception_t *p_exception )
85 {
86     if( playlist_Next( p_instance->p_playlist ) != VLC_SUCCESS )
87     {
88         libvlc_exception_raise( p_exception, "Empty playlist" );
89     }
90 }
91
92 void libvlc_playlist_prev( libvlc_instance_t *p_instance,
93                            libvlc_exception_t *p_exception )
94 {
95     if( playlist_Prev( p_instance->p_playlist ) != VLC_SUCCESS )
96     {
97         libvlc_exception_raise( p_exception, "Empty playlist" );
98     }
99 }
100
101 int libvlc_playlist_add( libvlc_instance_t *p_instance, const char *psz_uri,
102                          const char *psz_name, libvlc_exception_t *p_exception )
103 {
104     return libvlc_playlist_add_extended( p_instance, psz_uri, psz_name,
105                                          0, NULL, p_exception );
106 }
107
108 int libvlc_playlist_add_extended( libvlc_instance_t *p_instance,
109                                   const char *psz_uri, const char *psz_name,
110                                   int i_options, const char **ppsz_options,
111                                   libvlc_exception_t *p_exception )
112 {
113     return playlist_AddExt( p_instance->p_playlist, psz_uri, psz_name,
114                             PLAYLIST_INSERT, PLAYLIST_END, -1, ppsz_options,
115                             i_options );
116 }
117
118 int libvlc_playlist_delete_item( libvlc_instance_t *p_instance, int i_id,
119                                  libvlc_exception_t *p_exception )
120 {
121     return playlist_Delete( p_instance->p_playlist, i_id );
122 }
123
124
125 int libvlc_playlist_isplaying( libvlc_instance_t *p_instance,
126                                libvlc_exception_t *p_exception )
127 {
128     if( !p_instance->p_playlist )
129     {
130         libvlc_exception_raise( p_exception, "No playlist" );
131         return 0;
132     }
133     return playlist_IsPlaying( p_instance->p_playlist );
134 }
135
136 int libvlc_playlist_items_count( libvlc_instance_t *p_instance,
137                                  libvlc_exception_t *p_exception )
138 {
139     if( !p_instance->p_playlist )
140     {
141         libvlc_exception_raise( p_exception, "No playlist" );
142         return 0;
143     }
144     return p_instance->p_playlist->i_size;
145 }
146
147 libvlc_input_t * libvlc_playlist_get_input( libvlc_instance_t *p_instance,
148                                             libvlc_exception_t *p_exception )
149 {
150     libvlc_input_t *p_input;
151
152     vlc_mutex_lock( &p_instance->p_playlist->object_lock );
153     if( p_instance->p_playlist->p_input == NULL )
154     {
155         libvlc_exception_raise( p_exception, "No active input" );
156         vlc_mutex_unlock( &p_instance->p_playlist->object_lock );
157         return NULL;
158     }
159     p_input = (libvlc_input_t *)malloc( sizeof( libvlc_input_t ) );
160
161     p_input->i_input_id = p_instance->p_playlist->p_input->i_object_id;
162     p_input->p_instance = p_instance;
163     vlc_mutex_unlock( &p_instance->p_playlist->object_lock );
164
165     return p_input;
166 }