4.1.1 Sound Objects

class Sound

Sound objects have the following functions:

play( [times=1, interval=0, callback=None])

Starts playback of an audio file from the beginning. Without the parameters times and interval it plays the audio file one time. times defines the number of times the audio file is played, the default being 1. If the audio file is played several times, interval gives the time interval between the subsequent plays in microseconds.

The optional callback is called when the playing starts and when the end of the sound file is reached. The callback should take three parameters: the previous state, the current state and the possible error code. The possible states given as parameters to the callback are data items in the module audio.

Other issues:

  • Calling play(audio.KMdaRepeatForever) will repeat the file forever.
  • If an audio file is played but not stopped before exiting, the Python script will leave audio playing on; therefore stop needs to be called explicitly prior to exit.
  • Currently the module does not support playing simultaneous audio files, calling play to a second Sound instance while another audio file is playing, stops the earlier audio file and starts to play the second Sound instance.
  • Calling play while a telephone call is ongoing plays the sound file to uplink. In some devices the sound file is also played to the device speaker.
  • Calling play when already playing or recording results in RuntimeError. Calling stop prior to play will prevent this from happening.

stop( )
Stops playback or recording of an audio file.

record( )
Starts recording audio data to a file. If the file already exists, the operation appends to the file. For Nokia devices, WAV is typically supported for recording. For more information on the audio types supported by different devices, see the Forum Nokia Web site [5] and S60 Platform Web site [6]. Other issues:

  • Calling record while a telephone call is ongoing starts the recording of the telephone call.
  • Calling record when already playing or recording results in RuntimeError. Calling stop prior to record will prevent this from happening.

close( )
Closes an opened audio file.

state( )
Returns the current state of the Sound type instance. The different states (constants) are defined in the audio module. The possible states4.2 are:

  • ENotReady
    The Sound object has been constructed but no audio file is open.
  • EOpen
    An audio file is open but no playing or recording operation is in progress.
  • EPlaying
    An audio file is playing.
  • ERecording
    An audio file is being recorded.

max_volume( )
Returns the maximum volume of the device.

set_volume( volume)

Sets the volume. If the given volume is negative, then the volume is set to zero which mutes the device. If the volume is greater than max_volume, then max_volume is used.

current_volume( )
Returns the current volume set.

duration( )
Returns the duration of the file in microseconds.

set_position( microseconds)
Set the position for the playhead.

current_position( )
Returns the current playhead position in microseconds.



Footnotes

... states4.2
Descriptions for these options are based on information found in S60 SDK documentation [4].
See About this document... for information on suggesting changes.