The PySide.QtMultimedia.QAudioOutput class provides an interface for sending audio data to an audio output device.
You can construct an audio output with the system’s default audio output device . It is also possible to create PySide.QtMultimedia.QAudioOutput with a specific PySide.QtMultimedia.QAudioDeviceInfo . When you create the audio output, you should also send in the PySide.QtMultimedia.QAudioFormat to be used for the playback (see the PySide.QtMultimedia.QAudioFormat class description for details).
To play a file:
Starting to play an audio stream is simply a matter of calling PySide.QtMultimedia.QAudioOutput.start() with a PySide.QtCore.QIODevice . PySide.QtMultimedia.QAudioOutput will then fetch the data it needs from the io device. So playing back an audio file is as simple as:
<Code snippet "doc/src/snippets/audio/main.cpp:9" not found> ... <Code snippet "doc/src/snippets/audio/main.cpp:4" not found>The file will start playing assuming that the audio system and output device support it. If you run out of luck, check what’s up with the PySide.QtMultimedia.QAudioOutput.error() function.
After the file has finished playing, we need to stop the device:
<Code snippet "doc/src/snippets/audio/main.cpp:5" not found>At any given time, the PySide.QtMultimedia.QAudioOutput will be in one of four states: active, suspended, stopped, or idle. These states are described by the QAudio.State enum. State changes are reported through the PySide.QtMultimedia.QAudioOutput.stateChanged() signal. You can use this signal to, for instance, update the GUI of the application; the mundane example here being changing the state of a play/pause button. You request a state change directly with PySide.QtMultimedia.QAudioOutput.suspend() , PySide.QtMultimedia.QAudioOutput.stop() , PySide.QtMultimedia.QAudioOutput.reset() , PySide.QtMultimedia.QAudioOutput.resume() , and PySide.QtMultimedia.QAudioOutput.start() .
While the stream is playing, you can set a notify interval in milliseconds with PySide.QtMultimedia.QAudioOutput.setNotifyInterval() . This interval specifies the time between two emissions of the PySide.QtMultimedia.QAudioOutput.notify() signal. This is relative to the position in the stream, i.e., if the PySide.QtMultimedia.QAudioOutput is in the SuspendedState or the IdleState, the PySide.QtMultimedia.QAudioOutput.notify() signal is not emitted. A typical use-case would be to update a slider that allows seeking in the stream. If you want the time since playback started regardless of which states the audio output has been in, PySide.QtMultimedia.QAudioOutput.elapsedUSecs() is the function for you.
If an error occurs, you can fetch the error type with the PySide.QtMultimedia.QAudioOutput.error() function. Please see the QAudio.Error enum for a description of the possible errors that are reported. When an error is encountered, the state changes to QAudio.StoppedState . You can check for errors by connecting to the PySide.QtMultimedia.QAudioOutput.stateChanged() signal:
<Code snippet "doc/src/snippets/audio/main.cpp:8" not found>
Parameters: |
|
---|
Construct a new audio output and attach it to parent . The device referenced by audioDevice is used with the output format parameters.
Construct a new audio output and attach it to parent . The default audio output device is used with the output format parameters.
Return type: | PySide.QtCore.int |
---|
Returns the audio buffer size in bytes.
If called before PySide.QtMultimedia.QAudioOutput.start() , returns platform default value. If called before PySide.QtMultimedia.QAudioOutput.start() but PySide.QtMultimedia.QAudioOutput.setBufferSize() was called prior, returns value set by PySide.QtMultimedia.QAudioOutput.setBufferSize() . If called after PySide.QtMultimedia.QAudioOutput.start() , returns the actual buffer size being used. This may not be what was set previously by PySide.QtMultimedia.QAudioOutput.setBufferSize() .
Return type: | PySide.QtCore.int |
---|
Returns the free space available in bytes in the audio buffer.
NOTE: returned value is only valid while in QAudio.ActiveState or QAudio.IdleState state, otherwise returns zero.
Return type: | PySide.QtCore.qint64 |
---|
Returns the microseconds since PySide.QtMultimedia.QAudioOutput.start() was called, including time in Idle and Suspend states.
Return type: | PySide.QtMultimedia.QAudio.Error |
---|
Returns the error state.
Return type: | PySide.QtMultimedia.QAudioFormat |
---|
Returns the PySide.QtMultimedia.QAudioFormat being used.
Return type: | PySide.QtCore.int |
---|
Returns the notify interval in milliseconds.
Return type: | PySide.QtCore.int |
---|
Returns the period size in bytes.
Note: This is the recommended write size in bytes.
Return type: | PySide.QtCore.qint64 |
---|
Returns the amount of audio data processed by the class since PySide.QtMultimedia.QAudioOutput.start() was called in microseconds.
Note: The amount of audio data played can be determined by subtracting the microseconds of audio data still in the systems audio buffer.
qint64 bytesInBuffer = bufferSize() - bytesFree();
qint64 usInBuffer = (qint64)(1000000) * bytesInBuffer / ( channels() * sampleSize() / 8 ) / frequency();
qint64 usPlayed = processedUSecs() - usInBuffer;
Drops all audio data in the buffers, resets buffers to zero.
Resumes processing audio data after a PySide.QtMultimedia.QAudioOutput.suspend() .
Sets PySide.QtMultimedia.QAudioOutput.error() to QAudio.NoError . Sets PySide.QtMultimedia.QAudioOutput.state() to QAudio.ActiveState if you previously called start( PySide.QtCore.QIODevice *). Sets PySide.QtMultimedia.QAudioOutput.state() to QAudio.IdleState if you previously called PySide.QtMultimedia.QAudioOutput.start() . emits PySide.QtMultimedia.QAudioOutput.stateChanged() signal.
Note: signal will always be emitted during execution of the PySide.QtMultimedia.QAudioOutput.resume() function.
Parameters: | bytes – PySide.QtCore.int |
---|
Sets the audio buffer size to value in bytes.
Note: This function can be called anytime before PySide.QtMultimedia.QAudioOutput.start() , calls to this are ignored after PySide.QtMultimedia.QAudioOutput.start() . It should not be assumed that the buffer size set is the actual buffer size used, calling PySide.QtMultimedia.QAudioOutput.bufferSize() anytime after PySide.QtMultimedia.QAudioOutput.start() will return the actual buffer size being used.
Parameters: | milliSeconds – PySide.QtCore.int |
---|
Sets the interval for PySide.QtMultimedia.QAudioOutput.notify() signal to be emitted. This is based on the ms of audio data processed not on actual real-time. The minimum resolution of the timer is platform specific and values should be checked with PySide.QtMultimedia.QAudioOutput.notifyInterval() to confirm actual value being used.
Parameters: | device – PySide.QtCore.QIODevice |
---|
Uses the device as the PySide.QtCore.QIODevice to transfer data. Passing a PySide.QtCore.QIODevice allows the data to be transferred without any extra code. All that is required is to open the PySide.QtCore.QIODevice .
If able to successfully output audio data to the systems audio device the PySide.QtMultimedia.QAudioOutput.state() is set to QAudio.ActiveState , PySide.QtMultimedia.QAudioOutput.error() is set to QAudio.NoError and the PySide.QtMultimedia.QAudioOutput.stateChanged() signal is emitted.
If a problem occurs during this process the PySide.QtMultimedia.QAudioOutput.error() is set to QAudio.OpenError , PySide.QtMultimedia.QAudioOutput.state() is set to QAudio.StoppedState and PySide.QtMultimedia.QAudioOutput.stateChanged() signal is emitted.
In either case, the PySide.QtMultimedia.QAudioOutput.stateChanged() signal may be emitted either synchronously during execution of the PySide.QtMultimedia.QAudioOutput.start() function or asynchronously after PySide.QtMultimedia.QAudioOutput.start() has returned to the caller.
See also
Return type: | PySide.QtCore.QIODevice |
---|
Returns a pointer to the PySide.QtCore.QIODevice being used to handle the data transfer. This PySide.QtCore.QIODevice can be used to write() audio data directly.
If able to access the systems audio device the PySide.QtMultimedia.QAudioOutput.state() is set to QAudio.IdleState , PySide.QtMultimedia.QAudioOutput.error() is set to QAudio.NoError and the PySide.QtMultimedia.QAudioOutput.stateChanged() signal is emitted.
If a problem occurs during this process the PySide.QtMultimedia.QAudioOutput.error() is set to QAudio.OpenError , PySide.QtMultimedia.QAudioOutput.state() is set to QAudio.StoppedState and PySide.QtMultimedia.QAudioOutput.stateChanged() signal is emitted.
In either case, the PySide.QtMultimedia.QAudioOutput.stateChanged() signal may be emitted either synchronously during execution of the PySide.QtMultimedia.QAudioOutput.start() function or asynchronously after PySide.QtMultimedia.QAudioOutput.start() has returned to the caller.
See also
Return type: | PySide.QtMultimedia.QAudio.State |
---|
Returns the state of audio processing.
Parameters: | arg__1 – PySide.QtMultimedia.QAudio.State |
---|
Stops the audio output, detaching from the system resource.
Sets PySide.QtMultimedia.QAudioOutput.error() to QAudio.NoError , PySide.QtMultimedia.QAudioOutput.state() to QAudio.StoppedState and emit PySide.QtMultimedia.QAudioOutput.stateChanged() signal.
Stops processing audio data, preserving buffered audio data.
Sets PySide.QtMultimedia.QAudioOutput.error() to QAudio.NoError , PySide.QtMultimedia.QAudioOutput.state() to QAudio.SuspendedState and emit PySide.QtMultimedia.QAudioOutput.stateChanged() signal.