1 /*****************************************************************************
2 * vlc_mediaplayer.c: vlc.MediaPlayer binding
3 *****************************************************************************
4 * Copyright (C) 2006,2007,2008,2009 the VideoLAN team
7 * Authors: Olivier Aubert <olivier.aubert at liris.cnrs.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(self), &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(self), &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(self), 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(self), &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(self), 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(self), &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(self), &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(self), 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(self), &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(self), &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(self), &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(self), &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(self), 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(self), &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(self), &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(self), 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(self), &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(self), 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(self), &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(self), &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(self), &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(self), &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(self), 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(self), psz_filename, 0, 0, &ex);
342 Py_INCREF( Py_None );
347 vlcMediaPlayer_is_seekable( PyObject *self, PyObject *args )
349 libvlc_exception_t ex;
352 i_ret = libvlc_media_player_is_seekable( LIBVLC_MEDIAPLAYER(self), &ex);
354 return Py_BuildValue( "i", i_ret );
358 vlcMediaPlayer_can_pause( PyObject *self, PyObject *args )
360 libvlc_exception_t ex;
363 i_ret = libvlc_media_player_can_pause( LIBVLC_MEDIAPLAYER(self), &ex);
365 return Py_BuildValue( "i", i_ret );
369 vlcMediaPlayer_play( PyObject *self, PyObject *args )
371 libvlc_exception_t ex;
374 libvlc_media_player_play( LIBVLC_MEDIAPLAYER(self), &ex);
376 Py_INCREF( Py_None );
381 vlcMediaPlayer_pause( PyObject *self, PyObject *args )
383 libvlc_exception_t ex;
386 libvlc_media_player_pause( LIBVLC_MEDIAPLAYER(self), &ex);
388 Py_INCREF( Py_None );
393 vlcMediaPlayer_stop( PyObject *self, PyObject *args )
395 libvlc_exception_t ex;
398 libvlc_media_player_stop( LIBVLC_MEDIAPLAYER(self), &ex);
400 Py_INCREF( Py_None );
405 vlcMediaPlayer_set_xwindow( PyObject *self, PyObject *args )
407 libvlc_exception_t ex;
410 if( !PyArg_ParseTuple( args, "i", &i_drawable ) )
414 libvlc_media_player_set_xwindow( LIBVLC_MEDIAPLAYER(self), i_drawable, &ex );
417 Py_INCREF( Py_None );
422 vlcMediaPlayer_get_xwindow( PyObject *self, PyObject *args )
426 i_ret = libvlc_media_player_get_xwindow( LIBVLC_MEDIAPLAYER(self));
427 return Py_BuildValue( "i", i_ret );
431 vlcMediaPlayer_set_hwnd( PyObject *self, PyObject *args )
433 libvlc_exception_t ex;
436 if( !PyArg_ParseTuple( args, "l", &i_drawable ) )
440 libvlc_media_player_set_hwnd( LIBVLC_MEDIAPLAYER(self), (void*) i_drawable, &ex );
443 Py_INCREF( Py_None );
448 vlcMediaPlayer_get_hwnd( PyObject *self, PyObject *args )
452 i_ret = libvlc_media_player_get_hwnd( LIBVLC_MEDIAPLAYER(self));
453 return Py_BuildValue( "l", i_ret );
457 vlcMediaPlayer_set_agl( PyObject *self, PyObject *args )
459 libvlc_exception_t ex;
462 if( !PyArg_ParseTuple( args, "i", &i_drawable ) )
466 libvlc_media_player_set_agl( LIBVLC_MEDIAPLAYER(self), i_drawable, &ex );
469 Py_INCREF( Py_None );
474 vlcMediaPlayer_get_agl( PyObject *self, PyObject *args )
478 i_ret = libvlc_media_player_get_agl( LIBVLC_MEDIAPLAYER(self));
479 return Py_BuildValue( "i", i_ret );
483 vlcMediaPlayer_set_nsobject( PyObject *self, PyObject *args )
485 libvlc_exception_t ex;
488 if( !PyArg_ParseTuple( args, "l", &i_drawable ) )
492 libvlc_media_player_set_nsobject( LIBVLC_MEDIAPLAYER(self), (void*) i_drawable, &ex );
495 Py_INCREF( Py_None );
500 vlcMediaPlayer_get_nsobject( PyObject *self, PyObject *args )
504 i_ret = libvlc_media_player_get_nsobject( LIBVLC_MEDIAPLAYER(self));
505 return Py_BuildValue( "l", i_ret );
509 vlcMediaPlayer_set_media( PyObject *self, PyObject *args )
511 libvlc_exception_t ex;
512 PyObject* py_param = NULL;
514 if( !PyArg_ParseTuple( args, "O", &py_param ) )
516 if( PyObject_TypeCheck( py_param, &vlcMedia_Type ) == 1 )
519 libvlc_media_player_set_media( LIBVLC_MEDIAPLAYER(self), ((vlcMedia*)py_param)->p_media, &ex );
524 PyObject *py_exc = vlc_Exception;
525 PyErr_SetString( py_exc, "vlc.Media parameter needed" );
532 vlcMediaPlayer_get_media( PyObject *self, PyObject *args )
534 libvlc_exception_t ex;
535 libvlc_media_t *p_media;
539 p_media = libvlc_media_player_get_media( LIBVLC_MEDIAPLAYER(self), &ex );
544 Py_INCREF( Py_None );
549 p_ret = PyObject_New( vlcMedia, &vlcMedia_Type );
550 p_ret->p_media = p_media;
551 Py_INCREF( p_ret ); /* Ah bon ? */
552 return ( PyObject * )p_ret;
557 vlcMediaPlayer_get_spu( PyObject *self, PyObject *args )
559 libvlc_exception_t ex;
562 i_ret = libvlc_video_get_spu( LIBVLC_MEDIAPLAYER(self), &ex);
564 return Py_BuildValue( "i", i_ret );
568 vlcMediaPlayer_set_spu( PyObject *self, PyObject *args )
570 libvlc_exception_t ex;
573 if( !PyArg_ParseTuple( args, "i", &i_spu ) )
577 libvlc_video_set_spu( LIBVLC_MEDIAPLAYER(self), i_spu, &ex);
579 Py_INCREF( Py_None );
584 static PyMethodDef vlcMediaPlayer_methods[] =
586 { "get_length", vlcMediaPlayer_get_length, METH_VARARGS,
587 "get_length() -> long " },
588 { "get_time", vlcMediaPlayer_get_time, METH_VARARGS,
589 "get_time() -> long" },
590 { "set_time", vlcMediaPlayer_set_time, METH_VARARGS,
592 { "get_position", vlcMediaPlayer_get_position, METH_VARARGS,
593 "get_position() -> float" },
594 { "set_position", vlcMediaPlayer_set_position, METH_VARARGS,
595 "set_position(float)" },
596 { "will_play", vlcMediaPlayer_will_play, METH_VARARGS,
597 "will_play() -> int" },
598 { "is_seekable", vlcMediaPlayer_is_seekable, METH_VARARGS,
599 "is_seekable() -> int" },
600 { "can_pause", vlcMediaPlayer_can_pause, METH_VARARGS,
601 "can_pause() -> int" },
602 { "get_rate", vlcMediaPlayer_get_rate, METH_VARARGS,
603 "get_rate() -> float" },
604 { "set_rate", vlcMediaPlayer_set_rate, METH_VARARGS,
606 { "get_state", vlcMediaPlayer_get_state, METH_VARARGS,
607 "get_state() -> int" },
608 { "has_vout", vlcMediaPlayer_has_vout, METH_VARARGS,
609 "has_vout() -> int" },
610 { "get_fps", vlcMediaPlayer_get_fps, METH_VARARGS,
611 "get_fps() -> float" },
612 { "audio_get_track", vlcMediaPlayer_audio_get_track, METH_VARARGS,
613 "audio_get_track() -> int Get current audio track" },
614 { "audio_set_track", vlcMediaPlayer_audio_set_track, METH_VARARGS,
615 "audio_set_track(int) Set current audio track" },
616 { "toggle_fullscreen", vlcMediaPlayer_toggle_fullscreen, METH_VARARGS,
617 "toggle_fullscreen() Toggle fullscreen status on video output" },
618 { "set_fullscreen", vlcMediaPlayer_set_fullscreen, METH_VARARGS,
619 "set_fullscreen(bool) Enable or disable fullscreen on a video output" },
620 { "get_fullscreen", vlcMediaPlayer_get_fullscreen, METH_VARARGS,
621 "get_fullscreen() -> bool Get current fullscreen status" },
622 { "get_height", vlcMediaPlayer_get_height, METH_VARARGS,
623 "get_height() -> int Get current video height" },
624 { "get_width", vlcMediaPlayer_get_width, METH_VARARGS,
625 "get_width() -> int Get current video width" },
626 { "get_aspect_ratio", vlcMediaPlayer_get_aspect_ratio, METH_VARARGS,
627 "get_aspect_ratio() -> str Get current video aspect ratio" },
628 { "set_aspect_ratio", vlcMediaPlayer_set_aspect_ratio, METH_VARARGS,
629 "set_aspect_ratio(str) Set new video aspect ratio" },
630 { "video_take_snapshot", vlcMediaPlayer_video_take_snapshot, METH_VARARGS,
631 "video_take_snapshot(filename=str) Take a snapshot of the current video window" },
633 { "play", vlcMediaPlayer_play, METH_VARARGS,
634 "play() Play the media instance" },
635 { "pause", vlcMediaPlayer_pause, METH_VARARGS,
636 "pause() Pause the media instance" },
637 { "stop", vlcMediaPlayer_stop, METH_VARARGS,
638 "stop() Stop the media instance" },
640 { "set_xwindow", vlcMediaPlayer_set_xwindow, METH_VARARGS,
641 "set_xwindow() Set the X-Window id" },
642 { "set_nsobject", vlcMediaPlayer_set_nsobject, METH_VARARGS,
643 "set_nsobject() Set the NSObject" },
644 { "set_agl", vlcMediaPlayer_set_agl, METH_VARARGS,
645 "set_agl() Set the AGL" },
646 { "set_hwnd", vlcMediaPlayer_set_hwnd, METH_VARARGS,
647 "set_hwndl() Set the HWND" },
649 { "get_xwindow", vlcMediaPlayer_get_xwindow, METH_VARARGS,
650 "get_xwindow() Set the X-Window id" },
651 { "get_nsobject", vlcMediaPlayer_get_nsobject, METH_VARARGS,
652 "get_nsobject() Set the NSObject" },
653 { "get_agl", vlcMediaPlayer_get_agl, METH_VARARGS,
654 "get_agl() Set the AGL" },
655 { "get_hwnd", vlcMediaPlayer_get_hwnd, METH_VARARGS,
656 "get_hwndl() Set the HWND" },
658 { "get_chapter", vlcMediaPlayer_get_chapter, METH_VARARGS,
659 "get_chapter() -> int Get current chapter" },
660 { "set_chapter", vlcMediaPlayer_set_chapter, METH_VARARGS,
661 "set_chapter(int) Set current chapter" },
662 { "get_chapter_count", vlcMediaPlayer_get_chapter_count, METH_VARARGS,
663 "get_chapter_count() -> int Get current chapter count" },
665 { "set_media", vlcMediaPlayer_set_media, METH_VARARGS,
666 "set_media(vlc.Media) Set the media that will be used by the media_player" },
667 { "get_media", vlcMediaPlayer_get_media, METH_VARARGS,
668 "get_media() -> vlc.Media Get the media used by the media_player (if any)." },
670 { "get_spu", vlcMediaPlayer_get_spu, METH_VARARGS,
671 "get_spu() -> int Get current video subtitle" },
672 { "set_spu", vlcMediaPlayer_set_spu, METH_VARARGS,
673 "set_spu(int) Set new video subtitle" },
675 { NULL } /* Sentinel */
678 static PyTypeObject vlcMediaPlayer_Type =
680 PyObject_HEAD_INIT( NULL )
682 "vlc.MediaPlayer", /*tp_name*/
683 sizeof( vlcMediaPlayer_Type ), /*tp_basicsize*/
692 0, /*tp_as_sequence*/
700 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
701 "vlc.MediaPlayer object\n\nIt cannot be instantiated standalone, it must be obtained from an existing vlc.Instance object", /* tp_doc */
704 0, /* tp_richcompare */
705 0, /* tp_weaklistoffset */
708 vlcMediaPlayer_methods, /* tp_methods */
713 0, /* tp_descr_get */
714 0, /* tp_descr_set */
715 0, /* tp_dictoffset */