1 /*****************************************************************************
2 * vlc_mediaplayer.c: vlc.MediaPlayer binding
3 *****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.fr>
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.
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.
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 *****************************************************************************/
25 /***********************************************************************
27 ***********************************************************************/
30 vlcMediaPlayer_get_length( PyObject *self, PyObject *args )
32 libvlc_exception_t ex;
35 i_ret = libvlc_media_player_get_length( LIBVLC_MEDIAPLAYER->p_mp, &ex);
37 return Py_BuildValue( "L", i_ret );
41 vlcMediaPlayer_get_time( PyObject *self, PyObject *args )
43 libvlc_exception_t ex;
46 i_ret = libvlc_media_player_get_time( LIBVLC_MEDIAPLAYER->p_mp, &ex);
48 return Py_BuildValue( "L", i_ret );
52 vlcMediaPlayer_set_time( PyObject *self, PyObject *args )
54 libvlc_exception_t ex;
57 if( !PyArg_ParseTuple( args, "L", &i_time ) )
61 libvlc_media_player_set_time( LIBVLC_MEDIAPLAYER->p_mp, i_time, &ex);
68 vlcMediaPlayer_get_position( PyObject *self, PyObject *args )
70 libvlc_exception_t ex;
73 f_ret = libvlc_media_player_get_position( LIBVLC_MEDIAPLAYER->p_mp, &ex);
75 return Py_BuildValue( "f", f_ret );
79 vlcMediaPlayer_set_position( PyObject *self, PyObject *args )
81 libvlc_exception_t ex;
84 if( !PyArg_ParseTuple( args, "f", &f_pos ) )
88 libvlc_media_player_set_position( LIBVLC_MEDIAPLAYER->p_mp, f_pos, &ex);
95 vlcMediaPlayer_will_play( PyObject *self, PyObject *args )
97 libvlc_exception_t ex;
100 i_ret = libvlc_media_player_will_play( LIBVLC_MEDIAPLAYER->p_mp, &ex);
102 return Py_BuildValue( "i", i_ret );
106 vlcMediaPlayer_get_rate( PyObject *self, PyObject *args )
108 libvlc_exception_t ex;
111 f_ret = libvlc_media_player_get_rate( LIBVLC_MEDIAPLAYER->p_mp, &ex);
113 return Py_BuildValue( "f", f_ret );
117 vlcMediaPlayer_set_rate( PyObject *self, PyObject *args )
119 libvlc_exception_t ex;
122 if( !PyArg_ParseTuple( args, "f", &f_rate ) )
126 libvlc_media_player_set_rate( LIBVLC_MEDIAPLAYER->p_mp, f_rate, &ex);
128 Py_INCREF( Py_None );
133 vlcMediaPlayer_get_state( PyObject *self, PyObject *args )
135 libvlc_exception_t ex;
138 i_ret = libvlc_media_player_get_state( LIBVLC_MEDIAPLAYER->p_mp, &ex);
140 return Py_BuildValue( "i", i_ret );
144 vlcMediaPlayer_has_vout( PyObject *self, PyObject *args )
146 libvlc_exception_t ex;
149 i_ret = libvlc_media_player_has_vout( LIBVLC_MEDIAPLAYER->p_mp, &ex);
151 return Py_BuildValue( "i", i_ret );
155 vlcMediaPlayer_get_fps( PyObject *self, PyObject *args )
157 libvlc_exception_t ex;
160 f_ret = libvlc_media_player_get_fps( LIBVLC_MEDIAPLAYER->p_mp, &ex);
162 return Py_BuildValue( "f", f_ret );
166 vlcMediaPlayer_audio_get_track( PyObject *self, PyObject *args )
168 libvlc_exception_t ex;
172 i_ret = libvlc_audio_get_track( LIBVLC_MEDIAPLAYER->p_mp, &ex );
174 return Py_BuildValue( "i", i_ret );
178 vlcMediaPlayer_audio_set_track( PyObject *self, PyObject *args )
180 libvlc_exception_t ex;
183 if( !PyArg_ParseTuple( args, "i", &i_track ) )
187 libvlc_audio_set_track( LIBVLC_MEDIAPLAYER->p_mp, i_track, &ex );
189 Py_INCREF( Py_None );
194 vlcMediaPlayer_get_chapter( PyObject *self, PyObject *args )
196 libvlc_exception_t ex;
200 i_ret = libvlc_media_player_get_chapter( LIBVLC_MEDIAPLAYER->p_mp, &ex );
202 return Py_BuildValue( "i", i_ret );
206 vlcMediaPlayer_get_chapter_count( PyObject *self, PyObject *args )
208 libvlc_exception_t ex;
212 i_ret = libvlc_media_player_get_chapter_count( LIBVLC_MEDIAPLAYER->p_mp, &ex );
214 return Py_BuildValue( "i", i_ret );
218 vlcMediaPlayer_set_chapter( PyObject *self, PyObject *args )
220 libvlc_exception_t ex;
223 if( !PyArg_ParseTuple( args, "i", &i_chapter ) )
227 libvlc_media_player_set_chapter( LIBVLC_MEDIAPLAYER->p_mp, i_chapter, &ex );
229 Py_INCREF( Py_None );
235 vlcMediaPlayer_toggle_fullscreen( PyObject *self, PyObject *args )
237 libvlc_exception_t ex;
240 libvlc_toggle_fullscreen( LIBVLC_MEDIAPLAYER->p_mp, &ex);
242 Py_INCREF( Py_None );
247 vlcMediaPlayer_set_fullscreen( PyObject *self, PyObject *args )
249 libvlc_exception_t ex;
252 if( !PyArg_ParseTuple( args, "i", &i_fullscreen ) )
256 libvlc_set_fullscreen( LIBVLC_MEDIAPLAYER->p_mp, i_fullscreen, &ex);
258 Py_INCREF( Py_None );
263 vlcMediaPlayer_get_fullscreen( PyObject *self, PyObject *args )
265 libvlc_exception_t ex;
269 i_ret = libvlc_get_fullscreen( LIBVLC_MEDIAPLAYER->p_mp, &ex);
271 return Py_BuildValue( "i", i_ret );
275 vlcMediaPlayer_get_height( PyObject *self, PyObject *args )
277 libvlc_exception_t ex;
281 i_ret = libvlc_video_get_height( LIBVLC_MEDIAPLAYER->p_mp, &ex);
283 return Py_BuildValue( "i", i_ret );
287 vlcMediaPlayer_get_width( PyObject *self, PyObject *args )
289 libvlc_exception_t ex;
293 i_ret = libvlc_video_get_width( LIBVLC_MEDIAPLAYER->p_mp, &ex);
295 return Py_BuildValue( "i", i_ret );
299 vlcMediaPlayer_get_aspect_ratio( PyObject *self, PyObject *args )
301 libvlc_exception_t ex;
306 psz_ret = libvlc_video_get_aspect_ratio( LIBVLC_MEDIAPLAYER->p_mp, &ex);
308 o_ret=Py_BuildValue( "s", psz_ret );
314 vlcMediaPlayer_set_aspect_ratio( PyObject *self, PyObject *args )
316 libvlc_exception_t ex;
319 if( !PyArg_ParseTuple( args, "s", &psz_ratio ) )
323 libvlc_video_set_aspect_ratio( LIBVLC_MEDIAPLAYER->p_mp, psz_ratio, &ex);
326 Py_INCREF( Py_None );
331 vlcMediaPlayer_video_take_snapshot( PyObject *self, PyObject *args )
333 libvlc_exception_t ex;
336 if( !PyArg_ParseTuple( args, "s", &psz_filename ) )
340 libvlc_video_take_snapshot( LIBVLC_MEDIAPLAYER->p_mp, psz_filename, 0, 0, &ex);
342 Py_INCREF( Py_None );
347 vlcMediaPlayer_video_resize( PyObject *self, PyObject *args )
349 libvlc_exception_t ex;
353 if( !PyArg_ParseTuple( args, "ii", &i_width, &i_height ) )
357 libvlc_video_resize( LIBVLC_MEDIAPLAYER->p_mp, i_width, i_height, &ex);
359 Py_INCREF( Py_None );
364 vlcMediaPlayer_video_reparent( PyObject *self, PyObject *args )
366 libvlc_exception_t ex;
367 WINDOWHANDLE i_visual;
370 if( !PyArg_ParseTuple( args, "i", &i_visual ) )
374 i_ret = libvlc_video_reparent( LIBVLC_MEDIAPLAYER->p_mp, i_visual, &ex);
376 return Py_BuildValue( "i", i_ret );
380 vlcMediaPlayer_is_seekable( PyObject *self, PyObject *args )
382 libvlc_exception_t ex;
385 i_ret = libvlc_media_player_is_seekable( LIBVLC_MEDIAPLAYER->p_mp, &ex);
387 return Py_BuildValue( "i", i_ret );
391 vlcMediaPlayer_can_pause( PyObject *self, PyObject *args )
393 libvlc_exception_t ex;
396 i_ret = libvlc_media_player_can_pause( LIBVLC_MEDIAPLAYER->p_mp, &ex);
398 return Py_BuildValue( "i", i_ret );
402 vlcMediaPlayer_play( PyObject *self, PyObject *args )
404 libvlc_exception_t ex;
407 libvlc_media_player_play( LIBVLC_MEDIAPLAYER->p_mp, &ex);
409 Py_INCREF( Py_None );
414 vlcMediaPlayer_pause( PyObject *self, PyObject *args )
416 libvlc_exception_t ex;
419 libvlc_media_player_pause( LIBVLC_MEDIAPLAYER->p_mp, &ex);
421 Py_INCREF( Py_None );
426 vlcMediaPlayer_stop( PyObject *self, PyObject *args )
428 libvlc_exception_t ex;
431 libvlc_media_player_stop( LIBVLC_MEDIAPLAYER->p_mp, &ex);
433 Py_INCREF( Py_None );
438 vlcMediaPlayer_set_drawable( PyObject *self, PyObject *args )
440 libvlc_exception_t ex;
443 if( !PyArg_ParseTuple( args, "i", &i_drawable ) )
447 libvlc_media_player_set_drawable( LIBVLC_MEDIAPLAYER->p_mp, (libvlc_drawable_t) i_drawable, &ex );
450 Py_INCREF( Py_None );
455 vlcMediaPlayer_set_media( PyObject *self, PyObject *args )
457 libvlc_exception_t ex;
458 PyObject* py_param = NULL;
460 if( !PyArg_ParseTuple( args, "O", &py_param ) )
462 if( PyObject_TypeCheck( py_param, &vlcMedia_Type ) == 1 )
465 libvlc_media_player_set_media( LIBVLC_MEDIAPLAYER->p_mp, ((vlcMedia*)py_param)->p_media, &ex );
470 PyObject *py_exc = vlc_Exception;
471 PyErr_SetString( py_exc, "vlc.Media parameter needed" );
478 vlcMediaPlayer_get_media( PyObject *self, PyObject *args )
480 libvlc_exception_t ex;
481 libvlc_media_t *p_media;
485 p_media = libvlc_media_player_get_media( LIBVLC_MEDIAPLAYER->p_mp, &ex );
490 Py_INCREF( Py_None );
495 p_ret = PyObject_New( vlcMedia, &vlcMedia_Type );
496 p_ret->p_media = p_media;
497 Py_INCREF( p_ret ); /* Ah bon ? */
498 return ( PyObject * )p_ret;
503 vlcMediaPlayer_get_spu( PyObject *self, PyObject *args )
505 libvlc_exception_t ex;
508 i_ret = libvlc_video_get_spu( LIBVLC_MEDIAPLAYER->p_mp, &ex);
510 return Py_BuildValue( "i", i_ret );
514 vlcMediaPlayer_set_spu( PyObject *self, PyObject *args )
516 libvlc_exception_t ex;
519 if( !PyArg_ParseTuple( args, "i", &i_spu ) )
523 libvlc_video_set_spu( LIBVLC_MEDIAPLAYER->p_mp, i_spu, &ex);
525 Py_INCREF( Py_None );
530 static PyMethodDef vlcMediaPlayer_methods[] =
532 { "get_length", vlcMediaPlayer_get_length, METH_VARARGS,
533 "get_length() -> long " },
534 { "get_time", vlcMediaPlayer_get_time, METH_VARARGS,
535 "get_time() -> long" },
536 { "set_time", vlcMediaPlayer_set_time, METH_VARARGS,
538 { "get_position", vlcMediaPlayer_get_position, METH_VARARGS,
539 "get_position() -> float" },
540 { "set_position", vlcMediaPlayer_set_position, METH_VARARGS,
541 "set_position(float)" },
542 { "will_play", vlcMediaPlayer_will_play, METH_VARARGS,
543 "will_play() -> int" },
544 { "is_seekable", vlcMediaPlayer_is_seekable, METH_VARARGS,
545 "is_seekable() -> int" },
546 { "can_pause", vlcMediaPlayer_can_pause, METH_VARARGS,
547 "can_pause() -> int" },
548 { "get_rate", vlcMediaPlayer_get_rate, METH_VARARGS,
549 "get_rate() -> float" },
550 { "set_rate", vlcMediaPlayer_set_rate, METH_VARARGS,
552 { "get_state", vlcMediaPlayer_get_state, METH_VARARGS,
553 "get_state() -> int" },
554 { "has_vout", vlcMediaPlayer_has_vout, METH_VARARGS,
555 "has_vout() -> int" },
556 { "get_fps", vlcMediaPlayer_get_fps, METH_VARARGS,
557 "get_fps() -> float" },
558 { "audio_get_track", vlcMediaPlayer_audio_get_track, METH_VARARGS,
559 "audio_get_track() -> int Get current audio track" },
560 { "audio_set_track", vlcMediaPlayer_audio_set_track, METH_VARARGS,
561 "audio_set_track(int) Set current audio track" },
562 { "toggle_fullscreen", vlcMediaPlayer_toggle_fullscreen, METH_VARARGS,
563 "toggle_fullscreen() Toggle fullscreen status on video output" },
564 { "set_fullscreen", vlcMediaPlayer_set_fullscreen, METH_VARARGS,
565 "set_fullscreen(bool) Enable or disable fullscreen on a video output" },
566 { "get_fullscreen", vlcMediaPlayer_get_fullscreen, METH_VARARGS,
567 "get_fullscreen() -> bool Get current fullscreen status" },
568 { "get_height", vlcMediaPlayer_get_height, METH_VARARGS,
569 "get_height() -> int Get current video height" },
570 { "get_width", vlcMediaPlayer_get_width, METH_VARARGS,
571 "get_width() -> int Get current video width" },
572 { "get_aspect_ratio", vlcMediaPlayer_get_aspect_ratio, METH_VARARGS,
573 "get_aspect_ratio() -> str Get current video aspect ratio" },
574 { "set_aspect_ratio", vlcMediaPlayer_set_aspect_ratio, METH_VARARGS,
575 "set_aspect_ratio(str) Set new video aspect ratio" },
576 { "video_take_snapshot", vlcMediaPlayer_video_take_snapshot, METH_VARARGS,
577 "video_take_snapshot(filename=str) Take a snapshot of the current video window" },
578 { "video_resize", vlcMediaPlayer_video_resize, METH_VARARGS,
579 "video_resize(width=int, height=int) Resize the current video output window" },
580 { "video_reparent", vlcMediaPlayer_video_reparent, METH_VARARGS,
581 "video_reparent(visual=int) change the parent for the current video output" },
583 { "play", vlcMediaPlayer_play, METH_VARARGS,
584 "play() Play the media instance" },
585 { "pause", vlcMediaPlayer_pause, METH_VARARGS,
586 "pause() Pause the media instance" },
587 { "stop", vlcMediaPlayer_stop, METH_VARARGS,
588 "stop() Stop the media instance" },
589 { "set_drawable", vlcMediaPlayer_set_drawable, METH_VARARGS,
590 "set_drawable() Set the drawable id" },
592 { "get_chapter", vlcMediaPlayer_get_chapter, METH_VARARGS,
593 "get_chapter() -> int Get current chapter" },
594 { "set_chapter", vlcMediaPlayer_set_chapter, METH_VARARGS,
595 "set_chapter(int) Set current chapter" },
596 { "get_chapter_count", vlcMediaPlayer_get_chapter_count, METH_VARARGS,
597 "get_chapter_count() -> int Get current chapter count" },
599 { "set_media", vlcMediaPlayer_set_media, METH_VARARGS,
600 "set_media(vlc.Media) Set the media that will be used by the media_player" },
601 { "get_media", vlcMediaPlayer_get_media, METH_VARARGS,
602 "get_media() -> vlc.Media Get the media used by the media_player (if any)." },
604 { "get_spu", vlcMediaPlayer_get_spu, METH_VARARGS,
605 "get_spu() -> int Get current video subtitle" },
606 { "set_spu", vlcMediaPlayer_set_spu, METH_VARARGS,
607 "set_spu(int) Set new video subtitle" },
609 { NULL } /* Sentinel */
612 static PyTypeObject vlcMediaPlayer_Type =
614 PyObject_HEAD_INIT( NULL )
616 "vlc.MediaPlayer", /*tp_name*/
617 sizeof( vlcMediaPlayer_Type ), /*tp_basicsize*/
626 0, /*tp_as_sequence*/
634 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
635 "vlc.MediaPlayer object\n\nIt cannot be instanciated standalone, it must be obtained from an existing vlc.Instance object", /* tp_doc */
638 0, /* tp_richcompare */
639 0, /* tp_weaklistoffset */
642 vlcMediaPlayer_methods, /* tp_methods */
647 0, /* tp_descr_get */
648 0, /* tp_descr_set */
649 0, /* tp_dictoffset */