1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
|
.. wxPython Phoenix documentation
This file was generated by Phoenix's sphinx generator and associated
tools, do not edit by hand.
Copyright: (c) 2011-2018 by Total Control Software
License: wxWindows License
.. include:: headings.inc
.. _wx.media.MediaCtrl:
==========================================================================================================================================
|phoenix_title| **wx.media.MediaCtrl**
==========================================================================================================================================
:ref:`wx.media.MediaCtrl` is a class for displaying types of media, such as videos, audio files, natively through native codecs.
:ref:`wx.media.MediaCtrl` uses native backends to render media, for example on Windows there is a ActiveMovie/DirectShow backend, and on Macintosh there is a QuickTime backend.
|phoenix_title| Rendering media
===============================
Depending upon the backend, :ref:`wx.media.MediaCtrl` can render and display pretty much any kind of media that the native system can - such as an image, mpeg video, or mp3 (without license restrictions - since it relies on native system calls that may not technically have mp3 decoding available, for example, it falls outside the realm of licensing restrictions). For general operation, all you need to do is call :meth:`~wx.media.MediaCtrl.Load` to load the file you want to render, catch the ``EVT_MEDIA_LOADED`` event, and then call :meth:`~wx.media.MediaCtrl.Play` to show the video/audio of the media in that event. More complex operations are generally more heavily dependent on the capabilities of the backend. For example, QuickTime cannot set the playback rate of certain streaming media - while DirectShow is slightly more flexible in that regard.
|phoenix_title| Operation
=========================
When :ref:`wx.media.MediaCtrl` plays a file, it plays until the stop position is reached (currently the end of the file/stream). Right before it hits the end of the stream, it fires off a ``EVT_MEDIA_STOP`` event to its parent window, at which point the event handler can choose to veto the event, preventing the stream from actually stopping. Example: ::
# connect to the media event
self.Bind(wx.media.EVT_MEDIA_STOP, self.OnMediaStop, self.mediactrl)
# ...
def OnMediaStop(self, evt):
if self.userWantsToSeek:
self.mediactrl.SetPosition(someOtherPosition)
evt.Veto()
When :ref:`wx.media.MediaCtrl` stops, either by the ``EVT_MEDIA_STOP`` not being vetoed, or by manually calling :meth:`~wx.media.MediaCtrl.Stop`, where it actually stops is not at the beginning, rather, but at the beginning of the stream. That is, when it stops and play is called, playback is guaranteed to start at the beginning of the media. This is because some streams are not seekable, and when stop is called on them they return to the beginning, thus :ref:`wx.media.MediaCtrl` tries to keep consistent for all types of media. Note that when changing the state of the media through :meth:`~wx.media.MediaCtrl.Play` and other methods, the media may not actually be in the ``MEDIASTATE_PLAYING`` , for example. If you are relying on the media being in certain state catch the event relevant to the state. See :ref:`wx.media.MediaEvent` for the kinds of events that you can catch.
|phoenix_title| Video size
==========================
By default, :ref:`wx.media.MediaCtrl` will scale the size of the video to the requested amount passed to either its constructor or :meth:`~wx.media.MediaCtrl.Create`. After calling :meth:`wx.media.MediaCtrl.Load` or performing an equivalent operation, you can subsequently obtain the "real" size of the video (if there is any) by calling :meth:`wx.media.MediaCtrl.GetBestSize` . Note that the actual result on the display will be slightly different when :meth:`wx.media.MediaCtrl.ShowPlayerControls` is activated and the actual video size will be less than specified due to the extra controls provided by the native toolkit. In addition, the backend may modify :meth:`wx.media.MediaCtrl.GetBestSize` to include the size of the extra controls - so if you want the real size of the video just disable :meth:`wx.media.MediaCtrl.ShowPlayerControls` . The idea with setting :meth:`wx.media.MediaCtrl.GetBestSize` to the size of the video is that :meth:`~wx.media.MediaCtrl.GetBestSize` is a Window-derived function that is called when sizers on a window recalculate. What this means is that if you use sizers by default the video will show in its original size without any extra assistance needed from the user.
|phoenix_title| Player controls
===============================
Normally, when you use :ref:`wx.media.MediaCtrl` it is just a window for the video to play in. However, some toolkits have their own media player interface. For example, QuickTime generally has a bar below the video with a slider. A special feature available to :ref:`wx.media.MediaCtrl`, you can use the toolkits interface instead of making your own by using the :meth:`~wx.media.MediaCtrl.ShowPlayerControls` function. There are several options for the flags parameter, with the two general flags being ``MEDIACTRLPLAYERCONTROLS_NONE`` which turns off the native interface, and ``MEDIACTRLPLAYERCONTROLS_DEFAULT`` which lets :ref:`wx.media.MediaCtrl` decide what native controls on the interface. Be sure to review the caveats outlined in :ref:`Video size <wx.media.MediaCtrl>` before doing so.
|phoenix_title| Choosing a backend
==================================
Generally, you should almost certainly leave this part up to :ref:`wx.media.MediaCtrl` - but if you need a certain backend for a particular reason, such as QuickTime for playing .mov files, all you need to do to choose a specific backend is to pass the name of the backend class to :meth:`wx.media.MediaCtrl.Create` . The following are valid backend identifiers:
- ``MEDIABACKEND_DIRECTSHOW``: Use ActiveMovie/DirectShow. Uses the native ActiveMovie (I.E. DirectShow) control. Default backend on Windows and supported by nearly all Windows versions, even some Windows ``CE`` versions. May display a windows media player logo while inactive.
- ``MEDIABACKEND_QUICKTIME``: Use QuickTime. Mac Only. ``WARNING``: May not working correctly embedded in a :ref:`wx.Notebook`.
- ``MEDIABACKEND_GSTREAMER``, Use GStreamer. Unix Only. Requires GStreamer 0.8 along with at the very least the xvimagesink, xoverlay, and gst-play modules of gstreamer to function. You need the correct modules to play the relevant files, for example the mad module to play mp3s, etc.
- ``MEDIABACKEND_WMP10``, Uses Windows Media Player 10 (Windows only) - works on mobile machines with Windows Media Player 10 and desktop machines with either Windows Media Player 9 or 10.
Note that other backends such as ``MEDIABACKEND_MCI`` can now be found at Code (`http://wxcode.sourceforge.net/ <http://wxcode.sourceforge.net/>`_).
|phoenix_title| Creating a backend
==================================
Creating a backend for :ref:`wx.media.MediaCtrl` is a rather simple process. Simply derive from MediaBackendCommonBase and implement the methods you want. The methods in MediaBackend correspond to those in :ref:`wx.media.MediaCtrl` except for `MediaCtrl.CreateControl` which does the actual creation of the control, in cases where a custom control is not needed you may simply call :meth:`wx.Control.Create` . You need to make sure to use the ``DECLARE_CLASS`` and ``IMPLEMENT_CLASS`` macros. The only real tricky part is that you need to make sure the file in compiled in, which if there are just backends in there will not happen and you may need to use a force link hack (see `http://www.wxwidgets.org/wiki/index.php/RTTI <http://www.wxwidgets.org/wiki/index.php/RTTI>`_). This is a rather simple example of how to create a backend in the :ref:`ActiveXContainer` documentation.
.. seealso:: :ref:`wx.media.MediaEvent`
|
|class_hierarchy| Class Hierarchy
=================================
.. raw:: html
<div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
<img id="toggleBlock-trigger" src="_static/images/closed.png"/>
Inheritance diagram for class <strong>MediaCtrl</strong>:
</div>
<div id="toggleBlock-summary" style="display:block;"></div>
<div id="toggleBlock-content" style="display:none;">
<p class="graphviz">
<center><img src="_static/images/inheritance/wx.media.MediaCtrl_inheritance.png" alt="Inheritance diagram of MediaCtrl" usemap="#dummy" class="inheritance"/></center>
</div>
<script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
<map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.Control.html" title="wx.Control" alt="" coords="60,237,148,267"/> <area shape="rect" id="node6" href="wx.media.MediaCtrl.html" title="wx.media.MediaCtrl" alt="" coords="31,315,177,344"/> <area shape="rect" id="node2" href="wx.Window.html" title="wx.Window" alt="" coords="59,160,148,189"/> <area shape="rect" id="node3" href="wx.Object.html" title="wx.Object" alt="" coords="5,5,87,35"/> <area shape="rect" id="node4" href="wx.EvtHandler.html" title="wx.EvtHandler" alt="" coords="48,83,159,112"/> <area shape="rect" id="node5" href="wx.Trackable.html" title="wx.Trackable" alt="" coords="112,5,213,35"/> </map>
</p>
|
|method_summary| Methods Summary
================================
================================================================================ ================================================================================
:meth:`~wx.media.MediaCtrl.__init__` Default constructor - you ``MUST`` call :meth:`~MediaCtrl.Create` before calling any other methods of :ref:`wx.media.MediaCtrl`.
:meth:`~wx.media.MediaCtrl.Create` Creates this control.
:meth:`~wx.media.MediaCtrl.GetBestSize` Obtains the best size relative to the original/natural size of the video, if there is any.
:meth:`~wx.media.MediaCtrl.GetPlaybackRate` Obtains the playback rate, or speed of the media.
:meth:`~wx.media.MediaCtrl.GetState` Obtains the state the playback of the media is in.
:meth:`~wx.media.MediaCtrl.GetVolume` Gets the volume of the media from a 0.0 to 1.0 range.
:meth:`~wx.media.MediaCtrl.Length` Obtains the length - the total amount of time the movie has in milliseconds.
:meth:`~wx.media.MediaCtrl.Load` Loads the file that fileName refers to.
:meth:`~wx.media.MediaCtrl.LoadURI` Loads the location that uri refers to.
:meth:`~wx.media.MediaCtrl.LoadURIWithProxy` Loads the location that ``uri`` refers to with the proxy ``proxy`` .
:meth:`~wx.media.MediaCtrl.Pause` Pauses playback of the movie.
:meth:`~wx.media.MediaCtrl.Play` Resumes playback of the movie.
:meth:`~wx.media.MediaCtrl.Seek` Seeks to a position within the movie.
:meth:`~wx.media.MediaCtrl.SetPlaybackRate` Sets the playback rate, or speed of the media, to that referred by `dRate`.
:meth:`~wx.media.MediaCtrl.SetVolume` Sets the volume of the media from a 0.0 to 1.0 range to that referred by ``dVolume`` .
:meth:`~wx.media.MediaCtrl.ShowPlayerControls` A special feature to :ref:`wx.media.MediaCtrl`.
:meth:`~wx.media.MediaCtrl.Stop` Stops the media.
:meth:`~wx.media.MediaCtrl.Tell` Obtains the current position in time within the movie in milliseconds.
================================================================================ ================================================================================
|
|property_summary| Properties Summary
=====================================
================================================================================ ================================================================================
:attr:`~wx.media.MediaCtrl.BestSize` See :meth:`~wx.media.MediaCtrl.GetBestSize`
:attr:`~wx.media.MediaCtrl.PlaybackRate` See :meth:`~wx.media.MediaCtrl.GetPlaybackRate` and :meth:`~wx.media.MediaCtrl.SetPlaybackRate`
:attr:`~wx.media.MediaCtrl.State` See :meth:`~wx.media.MediaCtrl.GetState`
:attr:`~wx.media.MediaCtrl.Volume` See :meth:`~wx.media.MediaCtrl.GetVolume` and :meth:`~wx.media.MediaCtrl.SetVolume`
================================================================================ ================================================================================
|
|api| Class API
===============
.. class:: wx.media.MediaCtrl(Control)
**Possible constructors**::
MediaCtrl()
MediaCtrl(parent, id=-1, fileName="", pos=DefaultPosition,
size=DefaultSize, style=0, szBackend="", validator=DefaultValidator,
name="mediaCtrl")
MediaCtrl is a class for displaying types of media, such as videos,
audio files, natively through native codecs.
.. method:: __init__(self, *args, **kw)
|overload| Overloaded Implementations:
**~~~**
**__init__** `(self)`
Default constructor - you ``MUST`` call :meth:`Create` before calling any other methods of :ref:`wx.media.MediaCtrl`.
**~~~**
**__init__** `(self, parent, id=-1, fileName=EmptyString, pos=DefaultPosition, size=DefaultSize, style=0, szBackend=EmptyString, validator=DefaultValidator, name="mediaCtrl")`
Constructor that calls :meth:`Create` .
You may prefer to call :meth:`Create` directly to check to see if :ref:`wx.media.MediaCtrl` is available on the system.
:param `parent`: parent of this control. Must not be ``None``.
:type `parent`: wx.Window
:param `id`: id to use for events
:type `id`: wx.WindowID
:param `fileName`: If not empty, the path of a file to open.
:type `fileName`: string
:param `pos`: Position to put control at.
:type `pos`: wx.Point
:param `size`: Size to put the control at and to stretch movie to.
:type `size`: wx.Size
:param `style`: Optional styles.
:type `style`: long
:param `szBackend`: Name of backend you want to use, leave blank to make :ref:`wx.media.MediaCtrl` figure it out.
:type `szBackend`: string
:param `validator`: validator to use.
:type `validator`: wx.Validator
:param `name`: Window name.
:type `name`: string
**~~~**
.. method:: Create(self, parent, id=-1, fileName=EmptyString, pos=DefaultPosition, size=DefaultSize, style=0, szBackend=EmptyString, validator=DefaultValidator, name="mediaCtrl")
Creates this control.
Returns ``False`` if it can't load the movie located at `fileName` or it cannot load one of its native backends.
If you specify a file to open via `fileName` and you don't specify a backend to use, :ref:`wx.media.MediaCtrl` tries each of its backends until one that can render the path referred to by `fileName` can be found.
:param `parent`: parent of this control. Must not be ``None``.
:type `parent`: wx.Window
:param `id`: id to use for events
:type `id`: wx.WindowID
:param `fileName`: If not empty, the path of a file to open.
:type `fileName`: string
:param `pos`: Position to put control at.
:type `pos`: wx.Point
:param `size`: Size to put the control at and to stretch movie to.
:type `size`: wx.Size
:param `style`: Optional styles.
:type `style`: long
:param `szBackend`: Name of backend you want to use, leave blank to make :ref:`wx.media.MediaCtrl` figure it out.
:type `szBackend`: string
:param `validator`: validator to use.
:type `validator`: wx.Validator
:param `name`: Window name.
:type `name`: string
:rtype: `bool`
.. method:: GetBestSize(self)
Obtains the best size relative to the original/natural size of the video, if there is any.
See :ref:`Video size <wx.media.MediaCtrl>` for more information.
:rtype: :ref:`Size`
.. method:: GetPlaybackRate(self)
Obtains the playback rate, or speed of the media.
``1.0`` represents normal speed, while ``2.0`` represents twice the normal speed of the media, for example. Not supported on the GStreamer (Unix) backend.
:rtype: `float`
:returns:
zero on failure.
.. method:: GetState(self)
Obtains the state the playback of the media is in.
================================== ==================================
``wx.media.MEDIASTATE_STOPPED`` The movie has stopped.
``wx.media.MEDIASTATE_PAUSED`` The movie is paused.
``wx.media.MEDIASTATE_PLAYING`` The movie is currently playing.
================================== ==================================
|
:rtype: :ref:`wx.media.MediaState`
.. method:: GetVolume(self)
Gets the volume of the media from a 0.0 to 1.0 range.
:rtype: `float`
.. note::
Due to rounding and other errors the value returned may not be the exact value sent to :meth:`SetVolume` .
.. method:: Length(self)
Obtains the length - the total amount of time the movie has in milliseconds.
:rtype: :ref:`wx.FileOffset`
.. method:: Load(self, fileName)
Loads the file that fileName refers to.
Returns ``False`` if loading fails.
:param `fileName`:
:type `fileName`: string
:rtype: `bool`
.. method:: LoadURI(self, uri)
Loads the location that uri refers to.
Note that this is very implementation-dependent, although ``HTTP`` URI/URLs are generally supported, for example. Returns ``False`` if loading fails.
:param `uri`:
:type `uri`: string
:rtype: `bool`
.. method:: LoadURIWithProxy(self, uri, proxy)
Loads the location that ``uri`` refers to with the proxy ``proxy`` .
Not implemented on most backends so it should be called with caution. Returns ``False`` if loading fails.
:param `uri`:
:type `uri`: string
:param `proxy`:
:type `proxy`: string
:rtype: `bool`
.. method:: Pause(self)
Pauses playback of the movie.
:rtype: `bool`
.. method:: Play(self)
Resumes playback of the movie.
:rtype: `bool`
.. method:: Seek(self, where, mode=FromStart)
Seeks to a position within the movie.
:param `where`:
:type `where`: wx.FileOffset
:param `mode`:
:type `mode`: wx.SeekMode
:rtype: :ref:`wx.FileOffset`
.. todo:: Document the SeekMode parameter `mode`, and perhaps also the FileOffset and SeekMode themselves.
.. method:: SetPlaybackRate(self, dRate)
Sets the playback rate, or speed of the media, to that referred by `dRate`.
``1.0`` represents normal speed, while ``2.0`` represents twice the normal speed of the media, for example. Not supported on the GStreamer (Unix) backend. Returns ``True`` if successful.
:param `dRate`:
:type `dRate`: float
:rtype: `bool`
.. method:: SetVolume(self, dVolume)
Sets the volume of the media from a 0.0 to 1.0 range to that referred by ``dVolume`` .
``1.0`` represents full volume, while ``0.5`` represents half (50 percent) volume, for example.
:param `dVolume`:
:type `dVolume`: float
:rtype: `bool`
.. note::
The volume may not be exact due to conversion and rounding errors, although setting the volume to full or none is always exact. Returns ``True`` if successful.
.. method:: ShowPlayerControls(self, flags=MEDIACTRLPLAYERCONTROLS_DEFAULT)
A special feature to :ref:`wx.media.MediaCtrl`.
Applications using native toolkits such as QuickTime usually have a scrollbar, play button, and more provided to them by the toolkit. By default :ref:`wx.media.MediaCtrl` does not do this. However, on the directshow and quicktime backends you can show or hide the native controls provided by the underlying toolkit at will using :meth:`ShowPlayerControls` . Simply calling the function with default parameters tells :ref:`wx.media.MediaCtrl` to use the default controls provided by the toolkit. The function takes a MediaCtrlPlayerControls enumeration, please see available show modes there.
For more info see :ref:`Player controls <wx.media.MediaCtrl>`.
Currently only implemented on the QuickTime and DirectShow backends. The function returns ``True`` on success.
:param `flags`:
:type `flags`: wx.media.MediaCtrlPlayerControls
:rtype: `bool`
.. method:: Stop(self)
Stops the media.
See :ref:`Operation` for an overview of how stopping works.
:rtype: `bool`
.. method:: Tell(self)
Obtains the current position in time within the movie in milliseconds.
:rtype: :ref:`wx.FileOffset`
.. attribute:: BestSize
See :meth:`~wx.media.MediaCtrl.GetBestSize`
.. attribute:: PlaybackRate
See :meth:`~wx.media.MediaCtrl.GetPlaybackRate` and :meth:`~wx.media.MediaCtrl.SetPlaybackRate`
.. attribute:: State
See :meth:`~wx.media.MediaCtrl.GetState`
.. attribute:: Volume
See :meth:`~wx.media.MediaCtrl.GetVolume` and :meth:`~wx.media.MediaCtrl.SetVolume`
|