C

QMediaSessionController Class

The QMediaSessionController class controls the current media being played on a device. More...

Header: #include <QMediaSessionController>
CMake: find_package(Qt6 REQUIRED COMPONENTS AndroidAutomotiveMedia)
target_link_libraries(mytarget PRIVATE Qt6::AndroidAutomotiveMedia)
Since: QtAndroidAutomotive 6.5
Inherits: QObject

Public Types

enum PlaybackAction { NoAction, PlayAction, PauseAction, StopAction, SkipToNextAction, …, PositionAction }
flags PlaybackActions
enum PlaybackState { NoState, PausedState, PlayingState, StoppedState, BufferingState, …, ErrorState }

Public Functions

QMediaSessionController::PlaybackActions availableActions() const
float bufferProgress() const
qint64 duration() const
QMediaMetaData metaData() const
qreal playbackRate() const
QMediaSessionController::PlaybackState playbackState() const
qint64 position() const

Public Slots

void pause()
void play()
void setPlaybackRate(qreal rate)
void setPosition(qint64 position)
void skipToNext()
void skipToPrevious()
void stop()

Signals

Detailed Description

QMediaSessionController provides functions to control media playback, and retrieve media information, such as metadata.

This class is instantiated by QMediaSessionManager when it gets notified by the system about a new media controller being added or deleted. To get access to the controllers, use QMediaSessionManager::activeControllers().

Member Type Documentation

enum QMediaSessionController::PlaybackAction
flags QMediaSessionController::PlaybackActions

These flags indicate the actions that the controller can have, and use to hide UI controls if the media does not support that action. For example, if the media supports play, pause, stop actions.

ConstantValueDescription
QMediaSessionController::NoAction0Unknown or undefined action
QMediaSessionController::PlayAction1 << 0The media can be played
QMediaSessionController::PauseAction1 << 1The media can be paused
QMediaSessionController::StopAction1 << 2The media can be stopped
QMediaSessionController::SkipToNextAction1 << 3The media supports skipping to next media
QMediaSessionController::SkipToPreviousAction1 << 4The media supports skipping to previous media
QMediaSessionController::PlaybackRateAction1 << 5The media supports changing the playback rate
QMediaSessionController::PositionAction1 << 6The media supports changing the current playback position

Note: For Android, the PlaybackRateAction action requires minimum SDK version 31 (Android 12)

The PlaybackActions type is a typedef for QFlags<PlaybackAction>. It stores an OR combination of PlaybackAction values.

enum QMediaSessionController::PlaybackState

This enum specifies the states that the controller can have. For example, if the media is playing, paused, etc.

ConstantValueDescription
QMediaSessionController::NoState0The media is in an unknown state or the state cannot be retrieved
QMediaSessionController::PausedState1The media is paused
QMediaSessionController::PlayingState2The media is playing
QMediaSessionController::StoppedState3The media is stopped
QMediaSessionController::BufferingState4The media is buffering
QMediaSessionController::SkippingToNextState5The media is skipping to the next track
QMediaSessionController::SkippingToPreviousState6The media is skipping to the previous track
QMediaSessionController::ErrorState7There was an error in the media or while retrieving the state of the media

Member Function Documentation

QMediaSessionController::PlaybackActions QMediaSessionController::availableActions() const

Returns the available actions for the media.

[signal] void QMediaSessionController::availableActionsChanged()

This signal is emitted when the available actions for the media have changed.

float QMediaSessionController::bufferProgress() const

Returns how much of the media playback buffer is currently filled, from 0.0 (empty) to 1.0 (full).

[signal] void QMediaSessionController::bufferProgressChanged()

This signal is emitted when the buffer progress of the media has changed.

qint64 QMediaSessionController::duration() const

Returns the duration of the media in milliseconds. Can also be retrieved from QMediaMetaData::Duration.

[signal] void QMediaSessionController::durationChanged()

This signal is emitted when the duration of the media has changed.

QMediaMetaData QMediaSessionController::metaData() const

Returns the metadata of the media.

[signal] void QMediaSessionController::metaDataChanged()

This signal is emitted when the metaData has changed for the media.

[slot] void QMediaSessionController::pause()

Pauses the media.

[slot] void QMediaSessionController::play()

Starts or resumes the media.

qreal QMediaSessionController::playbackRate() const

Returns the playback rate of the media. 1 means that the media is playing at the normal rate. 2 means that media is playing at double rate. Negative values mean that the media is rewinding.

Returns 1 if failed to retrieve a valid playbackRate for the media.

See also QMediaSessionController::setPlaybackRate(qreal rate).

[signal] void QMediaSessionController::playbackRateChanged()

This signal is emitted when the playback rate of the media has changed.

QMediaSessionController::PlaybackState QMediaSessionController::playbackState() const

Returns the Playback State of the media.

Returns QMediaSessionController::NoState if unknown state or failed to retrieve a valid state.

[signal] void QMediaSessionController::playbackStateChanged()

This signal is emitted when the playback state has changed for the media.

qint64 QMediaSessionController::position() const

Returns the current playback position of the media in milliseconds.

Returns 0 if failed to retrieve a valid position.

See also QMediaSessionController::setPosition(qint64 position).

[signal] void QMediaSessionController::positionChanged()

This signal is emitted when the playback position of the media has changed.

It is emitted every 100 milliseconds while the media is playing.

[slot] void QMediaSessionController::setPlaybackRate(qreal rate)

Sets the playback rate of the media.

On Android, passing the rate as 0 is ignored as it is not valid.

See also playbackRate().

[slot] void QMediaSessionController::setPosition(qint64 position)

Sets the playback position of the media in milliseconds.

The value is ignored if position is less than 0 or greater than duration

See also QMediaSessionController::position().

[slot] void QMediaSessionController::skipToNext()

Plays the next media in the queue of the application playing the media.

[slot] void QMediaSessionController::skipToPrevious()

Plays the previous media in the queue of the application playing the media.

[slot] void QMediaSessionController::stop()

Stops the media.

Available under certain Qt licenses.
Find out more.