d3d11.Media

This object does not have that much to do with Direct3D, but it is provided anyway. This uses Microsoft Media Foundation to play media, so any format limitations etc. apply. This is also a relatively resource intensive object so you might want to consider using some other library for your sound effects.

Because Media is asynchronous you might encounter some surprises. For example when starting to play a media this might happen:

>>> media = d3d11.Media("somefile.mp3", None)
>>> media.hasAudio()
False
>>> #Wait...
>>> media.hasAudio()
True
>>> #Audio has "magically" appeared.

This is because Media does not know what kind of streams it will get until they have been processed. Also attempting to set media position etc. can fail if all streams are not yet initialized. XXX Write abot events.

Methods

class Media
Media(path, window) → Media
Parameters:
  • path – Media file to be loaded. This can be an URL.
  • window – A d3d11.Window which will be used to play the media. This can be None, for example music media does not require a window. If a window is given it will will receive event notifications (WM_DP_MEDIAEVENT).

Creates a new Media.

getDuration() → int

Returns the duration of the media as a reference time.

getEvents() → list

Returns all events that have occurred. There is usually no need to call this method, these events are sent to the parent window and received from d3d11.Window.getMessages(). This is useful if you are using some third party windowing toolkit.

getPosition() → int

Returns the current play position as a reference time.

getTexture() → Texture

Returns the current video image as a Texture. If no video is available an exception is raised. This is very slow, so don’t attempt to do any real-time operations with this. The width and height of the texture will be the width and height of the output area.

getVideoSize() → width, height

Returns the native video size.

getVolume() → float

Returns the current volume as a normalized float. Can be from 0.0 (silent) to 1.0 (maximum).

hasAudio() → bool

Returns True if the Media currently has an audio stream.

hasVideo() → bool

Returns True if the Media currently has a video stream.

pause() → None

Pauses the media.

play() → None

Starts playing the media.

setPosition(position) → None

Sets playback position. This also starts to play the media.

setVolume(volume) → None

Sets media volume.

Table Of Contents

Get DirectPython 11 at SourceForge.net. Fast, secure and Free Open Source software downloads