Media

This module contains useful objects for easy use of video and audio.

Video

class core.media.Screen(obj=None)

The base object used in this widget will become a screen.

Parameters:object (KX_GameObject or string) – Object to apply the changes.
obj

The KX_GameObject used as screen.

speaker

The AudioFile of the video if used, otherwise None.

frame

The number of the frame being played.

callback

A function to call once the reproduction ends. Will be overwrited with the paramater specified on the play method, even if it’s None.

replaceTexture(filepath)

Change the texture of the object by another, external, texture.

Parameters:filepath (string) – The relative path (from the data folder) of the texture/image to replace.
play(video, callback=None)

Plays a video on this screen, also makes the speaker aviable.

Parameters:
  • video (string) – The relative path (from the data folder) of the video to use.
  • callback (function) – Function to call once the video ends.
fadeIn(time)

Starts to make fadein now. It actuates over the alpha chanel of the KX_GameObject representing this screen. In order to work it needs object color enabled on the material.

Parameters:time (float) – How long the fadein lasts.
fadeOut(time)

Starts to make fadeout now. It actuates over the alpha chanel of the KX_GameObject representing this screen. In order to work it needs object color enabled on the material.

Parameters:time (float) – How long the fadein lasts.

Audio

core.media.device

The master device of the audio of the game.

See: aud.Device (External Link)

core.media.music

Default instance of AudioFile for music.

class core.media.AudioFile(filepath='', callback=None)

A object representating an audio file. Initializating this won’t play the file.

  • Recomended formats: .mp3
  • Supported Formats: .mp3, .ogg, .wav

Note

This is done in a new thread, changing scenes or a low framerate won’t alter the sound.

Parameters:
  • filepath (string) – Relative path (from the data folder) of the audio file to use.
  • callback (function) – Function to call once the playback ends.
handle

The aud.Handle, be coutious while tweaking with this.

volume_min

Minium volume of the audio.

volume_max

Maxium volume of the audio.

time

The amount of time in seconds since the file start playing.

play(filepath=None, loop=False, volume=None, pitch=1, callback=None, transition=(3, 2, 3))

Method to play an audio file.

If an audio file is being played while calling this, it will be replaced by a new one. During the transation a fadeOut->FadeIn effect will occur.

Parameters:
  • filepath (string) – Relative path (from the data folder) of the audio file to use.
  • loop (bool) – If true the audio will be played in loop.
  • volume (float) – The volume of the audio file relative to the master device. (Default = 1.0)
  • pitch (float) – The pitch.
  • callback (function) – Function to call once the playback ends.
  • transition (tuple) – The times for the fade effect during transations. In order: Duration of the fadeout, time for the fadein to start, duration of the fadein. In sconds.
fadeOut(time, stop=False)

Starts to make fadeout now.

Parameters:
  • time (float) – How long the fadeout lasts.
  • stop (bool) – If True it will automatically stop the reproduction at the end.
fadeIn(time)

Starts to make fadein now.

Parameters:time (float) – How long the fadein lasts.
moveInstance()

Returns a new instance of this class and gives it control over the audiofile, this instance returns to its original state.

Note

This function is used internally to replace sounds with a fadeIn/fadeOut effect were they can be mixed during the transition.

stop()

Stops the sound.

volume
class core.media.RandomMusic(directory='media/music', loop=True, audiofile=<core.media.AudioFile object at 0x03F6A210>, transition=(5, 2, 4))

Plays random music from a directory.

To use it correctly initialize it somewere and call play() when you want to start playing music or you want to go to the next song.

Parameters:
  • directory (string) – The path of the directory.
  • loop (bool) – If true it continues playing new songs until stop() is called.
  • audiofile (AudioFile) – The AudioFile object to use. By the default media.music.
  • transition – The times for the fade effect when changing songs.
playing

No songs will be played if it is not True. :type: bool

ignore

List of filenames to ignore.

play(directory=None)

Plays a song, or replaces the current song.

stop()

Stops playing songs and stops the current song

next()

Plays a song, or replaces the current song.

getRandomFileTrack()

Returns a random filename with any extension.