wxMediaCtrl is a class that allows a way to convieniently display types of media, such as videos, audio files, natively through native codecs.
wxMediaCtrl uses native backends to render media, for example on Windows there is a ActiveMovie/DirectShow backend, and on Macintosh there is a QuickTime backend.
Derived from
Include files
<wx/mediactrl.h>
Members
Rendering media
Operation
Choosing a backend
wxMediaCtrl::wxMediaCtrl
wxMediaCtrl::Create
wxMediaCtrl::Length
wxMediaCtrl::Tell
wxMediaCtrl::GetState
wxMediaCtrl::Load
wxMediaCtrl::Load
wxMediaCtrl::Pause
wxMediaCtrl::Play
wxMediaCtrl::Seek
wxMediaCtrl::Stop
wxMediaCtrl::SetVolume
wxMediaCtrl::GetVolume
wxMediaCtrl::GetPlaybackRate
wxMediaCtrl::SetPlaybackRate
wxMediaCtrl::ShowPlayerControls
Depending upon the backend, wxMediaCtrl 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 wxMediaCtrl::Load to load the file you want to render, catch the EVT_MEDIA_LOADED event, and then call wxMediaCtrl::Play to show the video/audio of the media in that event.
More complex operations are generally more heavily dependant 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.
When wxMediaCtrl 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 this->Connect(wxMY_ID, wxEVT_MEDIA_STOP, (wxObjectEventFunction) (wxEventFunction)(wxMediaEventFunction) &MyFrame::OnMediaStop); //... void MyFrame::OnMediaStop(const wxMediaEvent& evt) { if(bUserWantsToSeek) { m_mediactrl->SetPosition( m_mediactrl->GetDuration() << 1 ); evt.Veto(); } }When wxMediaCtrl stops, either by the EVT_MEDIA_STOP not being vetoed, or by manually calling wxMediaCtrl::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 gauranteed 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 wxMediaCtrl tries to keep consistant for all types of media.
Generally, you should almost certainly leave this part up to wxMediaCtrl - 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 wxMediaCtrl::Create.
The following are valid backend identifiers -
wxMEDIABACKEND_DIRECTSHOW | Use ActiveMovie/DirectShow. Requires wxUSE_DIRECTSHOW to be enabled, requires linkage with the static library strmiids.lib, and is available on Windows Only. |
wxMEDIABACKEND_QUICKTIME | Use QuickTime. Windows and Mac Only. NOTE: On Mac Systems lower than OSX 10.2 this defaults to emulating window positioning and suffers from several bugs, including not working correctly embedded in a wxNotebook. |
wxMEDIABACKEND_MCI | Use Media Command Interface. Windows Only. |
wxMEDIABACKEND_GSTREAMER | Use GStreamer. Unix Only. |
wxMediaCtrl()
Default constructor - you must call Create before calling any other methods of wxMediaCtrl.
wxMediaCtrl( wxWindow* parent, const wxString& fileName = wxT(""), wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& szBackend = wxT(""), const wxValidatorvalidator = wxDefaultValidator, const wxString& name = wxPanelNameStr )
Constructor that calls Create. You may prefer to call Create directly to check to see if wxMediaCtrl is available on the system.
parent
bool Create( wxWindow* parent, const wxString& fileName = wxT(""), wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& szBackend = wxT(""), const wxValidatorvalidator = wxDefaultValidator, const wxString& name = wxPanelNameStr )
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, wxMediaCtrl tries each of its backends until one that can render the path referred to by fileName can be found.
parent
wxFileOffset GetDuration()
Obtains the length - the total amount of time the movie has in milliseconds.
wxFileOffset GetPosition()
Obtains the current position in time within the movie in milliseconds.
wxMediaCtrlState GetState()
Obtains the state the playback of the movie is in -
wxMEDIASTATE_STOPPED | The movie has stopped. |
wxMEDIASTATE_PAUSED | The movie is paused. |
wxMEDIASTATE_PLAYING | The movie is currently playing. |
bool Load(const wxString& fileName)
Loads the file that fileName refers to. Returns false if loading fails.
bool Load(const wxURI& location)
Loads the url that location refers to. Returns false if loading fails.
bool Pause()
Pauses playback of the movie.
bool Play()
Resumes playback of the movie.
wxFileOffset Seek(wxFileOffset where, wxSeekMode mode)
Seeks to a position within the movie.
bool Stop()
Stops the media.
See Operation for an overview of how stopping works.
bool SetVolume(double dVolume)
Sets the volume of the media from a 0.0 to 1.0 range.
double GetVolume()
Gets the volume of the media from a 0.0 to 1.0 range.
double GetPlaybackrate()
Gets the playback rate of the media; for example 2.0 is double speed. Not implemented on MCI or GStreamer.
bool SetPlaybackrate(double dVolume)
Sets the rate that the media plays; for example 0.5 is half speed.
bool ShowPlayerControls(wxMediaCtrlPlayerControls flags)
Normally, when you use wxMediaCtrl it is just a window for the video to play in. However, platforms generally have their own media player interface, like quicktime has a bar below the video with a slider etc.. If you want that native interface instead of making your own use this function. There are several options for the flags parameter, however you can look at the mediactrl header for these. The two general flags are wxMEDIACTRLPLAYERCONTROLS_NONE which turns off the native interface, and wxMEDIACTRLPLAYERCONTROLS_DEFAULT which lets wxMediaCtrl decide what native controls on the interface.