• PySide 模块
  • PySide.QtMultimedia
  • 内容表

    上一话题

    QAudioEngineFactoryInterface

    下一话题

    QAudioInput

    QAudioOutput

    概要

    函数

    信号

    详细描述

    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() 采用 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() 函数。

    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() ,和 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 采用 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>
    									
    class PySide.QtMultimedia. QAudioOutput ( audioDeviceInfo [ , format=QAudioFormat() [ , parent=None ] ] )
    class PySide.QtMultimedia. QAudioOutput ( [ format=QAudioFormat() [ , parent=None ] ] )
    参数:

    Construct a new audio output and attach it to parent . The device referenced by audioDevice is used with the output format 参数。

    Construct a new audio output and attach it to parent . The default audio output device is used with the output format 参数。

    PySide.QtMultimedia.QAudioOutput. bufferSize ( )
    返回类型: 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() .

    PySide.QtMultimedia.QAudioOutput. bytesFree ( )
    返回类型: 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.

    PySide.QtMultimedia.QAudioOutput. elapsedUSecs ( )
    返回类型: PySide.QtCore.qint64

    Returns the microseconds since PySide.QtMultimedia.QAudioOutput.start() was called, including time in Idle and Suspend states.

    PySide.QtMultimedia.QAudioOutput. error ( )
    返回类型: PySide.QtMultimedia.QAudio.Error

    Returns the error state.

    PySide.QtMultimedia.QAudioOutput. format ( )
    返回类型: PySide.QtMultimedia.QAudioFormat

    返回 PySide.QtMultimedia.QAudioFormat 被使用。

    PySide.QtMultimedia.QAudioOutput. notify ( )
    PySide.QtMultimedia.QAudioOutput. notifyInterval ( )
    返回类型: PySide.QtCore.int

    Returns the notify interval in milliseconds.

    PySide.QtMultimedia.QAudioOutput. periodSize ( )
    返回类型: PySide.QtCore.int

    Returns the period size in bytes.

    Note: This is the recommended write size in bytes.

    PySide.QtMultimedia.QAudioOutput. processedUSecs ( )
    返回类型: 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;
    										
    PySide.QtMultimedia.QAudioOutput. reset ( )

    Drops all audio data in the buffers, resets buffers to zero.

    PySide.QtMultimedia.QAudioOutput. resume ( )

    Resumes processing audio data after a PySide.QtMultimedia.QAudioOutput.suspend() .

    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() 信号。

    Note: signal will always be emitted during execution of the PySide.QtMultimedia.QAudioOutput.resume() 函数。

    PySide.QtMultimedia.QAudioOutput. setBufferSize ( bytes )
    参数: 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.

    PySide.QtMultimedia.QAudioOutput. setNotifyInterval ( milliSeconds )
    参数: 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.

    PySide.QtMultimedia.QAudioOutput. start ( device )
    参数: device PySide.QtCore.QIODevice

    Uses the device 作为 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 PySide.QtMultimedia.QAudioOutput.stateChanged() 信号被发射。

    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() 信号被发射。

    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.

    PySide.QtMultimedia.QAudioOutput. start ( )
    返回类型: PySide.QtCore.QIODevice

    返回指针指向 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 PySide.QtMultimedia.QAudioOutput.stateChanged() 信号被发射。

    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() 信号被发射。

    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.

    PySide.QtMultimedia.QAudioOutput. state ( )
    返回类型: PySide.QtMultimedia.QAudio.State

    Returns the state of audio processing.

    PySide.QtMultimedia.QAudioOutput. stateChanged ( arg__1 )
    参数: arg__1 PySide.QtMultimedia.QAudio.State
    PySide.QtMultimedia.QAudioOutput. stop ( )

    Stops the audio output, detaching from the system resource.

    PySide.QtMultimedia.QAudioOutput.error() to QAudio.NoError , PySide.QtMultimedia.QAudioOutput.state() to QAudio.StoppedState and emit PySide.QtMultimedia.QAudioOutput.stateChanged() 信号。

    PySide.QtMultimedia.QAudioOutput. suspend ( )

    Stops processing audio data, preserving buffered audio data.

    PySide.QtMultimedia.QAudioOutput.error() to QAudio.NoError , PySide.QtMultimedia.QAudioOutput.state() to QAudio.SuspendedState and emit PySide.QtMultimedia.QAudioOutput.stateChanged() 信号。