pymedia.player
index
c:\python23\lib\site-packages\pymedia\player.py

 
Modules
       
Queue
pymedia.audio.acodec
pymedia.muxer
os
pymedia.audio.sound
sys
thread
time
traceback
pymedia.video.vcodec

 
Classes
       
Player

 
class Player
    Player is a class that plays all audio/video formats supported by pymedia
It provides very simple interface and many features such as:
- seeking
- extracting metadata
- multiple sound cards support
- different sources for video rendering
- error handling
- volume operations
 
Here is the simple way of calling Player:
  player= pymedia.Player()
  player.start()
  player.startPlayback( '<YOUR_MP3_FILE>' )
  while player.isPlaying():
    time.sleep( 0.01 )
 
Player supports the following callback:
  class Callback:
    # called _before_ the audio frame is rendered
    # return your audio data after you process the audio frame
    # or return none for using the default sound processing
    def onAudioReady( self, afr ):
      pass
    
    # Called when the video frame is about to be rendered
    def onVideoReady( self, vfr ):
      pass
 
Use the callback like below:
  c= Callback()
  player= pymedia.Player( c )
 
  Methods defined here:
__init__(self, callback=None)
Create new Player instance. In case if you want to play video you have to supply the callback class instance
which will get video data and will be able to display it properly ( onVideoReady() call ).
For audio data the playback is done through the pymedia.sound.Output object.
Before playing audio the onAudioReady( afr ) callback is called so you can modify audio data.
Just return None if you do not wish to modify that data or return a sound data as string in case if you do.
Remember that sampling frequency and number of channels should remain the same as in afr object.
getLength(self)
Get length of the media file in seconds
Note: length may be unknown for up to 1 second after you call startPlayback() !
getMetaData(self)
Get meta data from the media file as dictionary
Note: metadata may be unknown for up to 1 second after you call startPlayback() !
getPictureSize(self)
Whenever the file containing video is played, this function returns the actual picture size for the
video part. It may be None if no video is found in the media file.
Note: picture size may be unknown for up to 1 second after you call startPlayback() !
isActive(self)
Returns whether Player object can do the playback.
It will return False after you issue stop()
isPaused(self)
Returns whether playback is paused
isPlaying(self)
Returns whether playback is active
pausePlayback(self)
Pause playing the current file
seekTo(self, secs)
Seeks the file playback position to a given number of seconds from the beginning.
Seek may position not exactly as specified especially in video files.
It will look for a first key frame and start playing from that position.
In some files key frames could resides up to 10 seconds apart.
setEndTime(self, timePos)
Set end time for the media track.
Whenever file is reached the endTime it will stop playing.
setLoops(self, loops)
Set number of loops the player will play current file
setStartTime(self, timePosSec)
Set start time for the media track to start playing.
Whenever file is played it will start from the timePosSec position in the file.
setVolume(self, volume)
Set volume for the media track to play
volume = [ 0..255 ]
start(self)
Start player object. It starts internal loop only, no physical playback is started.
You have to call start only once for the player instance.
If you wish to play multiple files just call startPlayback() subsequently.
startPlayback(self, file, paused=False)
Starts playback of the file passed as string or file like object.
Player should already be started otherwise this call has no effect.
If any file is already playing it will stop the playback and start playing the file you pass.
'paused' parameter can specifiy if the playback should not start until unpausePlayback() is called.
'paused' parameter is helpfull when you want to start your playback exactly at a certain time avoiding any delays
caused by the file opening or codec initilizations.
stop(self)
Stop player object. It stops internmal loop and any playing file.
Once the internal loop is stopped the further playback is not possible until you issue start() again.
stopPlayback(self)
Stops file playback. If media file is not playing currently, it does nothing.
If file was paused it will unpause it first.
unpausePlayback(self)
Resume playing the current file

 
Data
        PAUSE_SLEEP = 0.0030000000000000001
SEEK_IN_PROGRESS = -1
VIDEO_FILE_CHUNK = 300000