wxMediaCtrl

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

wxControl

Include files

<wx/mediactrl.h>



Rendering media

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 - sense 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, then call wxMediaCtrl::Play to show the video/audio of the media.

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.



Operation

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.



Choosing a backend

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. WARNING: 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::wxMediaCtrl



wxMediaCtrl(void)

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 wxValidator& validator = 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
parent of this control. Must not be NULL.
id
id to use for events
fileName
If not empty, the path of a file to open.
pos
Position to put control at.
size
Size to put the control at and to stretch movie to.
style
Optional styles.
szBackend
Name of backend you want to use, leave blank to make wxMediaCtrl figure it out.
validator
validator to use.
name
Window name.



wxMediaCtrl::Create



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 wxValidator& validator = 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
parent of this control. Must not be NULL.
id
id to use for events
fileName
If not empty, the path of a file to open.
pos
Position to put control at.
size
Size to put the control at and to stretch movie to.
style
Optional styles.
szBackend
Name of backend you want to use, leave blank to make wxMediaCtrl figure it out.
validator
validator to use.
name
Window name.



wxMediaCtrl::Length



wxFileOffset GetDuration(void)

Obtains the length - the total amount of time the movie has in milliseconds.



wxMediaCtrl::Tell



wxFileOffset GetPosition(void)

Obtains the current position in time within the movie in milliseconds.



wxMediaCtrl::GetState



wxMediaCtrlState GetState(void)

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.



wxMediaCtrl::Load



bool Load(const wxString& fileName)

Loads the file that fileName refers to. Returns false if loading fails.



wxMediaCtrl::Pause



bool Pause(void)

Pauses playback of the movie.



wxMediaCtrl::Play



bool Play(void)

Resumes playback of the movie.



wxMediaCtrl::Seek



wxFileOffset SetPosition(wxFileOffset where, wxSeekMode mode)

Seeks to a position within the movie.



wxMediaCtrl::Stop



bool Stop(void)

Stops the media.

See Operation for an overview of how stopping works.

ymasuda 平成17年11月19日