1.10
Public Member Functions | Protected Attributes | List of all members
AudioPlayer Class Reference

Audio player. More...

#include <audio.h>

Inheritance diagram for AudioPlayer:
Inheritance graph
[legend]

Public Member Functions

 AudioPlayer ()
 
 AudioPlayer (AudioPlayer &&)=default
 
 AudioPlayer (const AudioPlayer &)=delete
 
 AudioPlayer (const std::string &uri)
 Construct and set the media file URI to the current pipeline.
 
 ~AudioPlayer () noexcept override
 
EGT_NODISCARD uint64_t duration () const
 Get the duration of the audio stream.
 
bool media (const std::string &uri)
 Sets the media file URI to the current pipeline.
 
bool mute (bool mute)
 Mutes the audio being played.
 
AudioPlayeroperator= (AudioPlayer &&)=default
 
AudioPlayeroperator= (const AudioPlayer &)=delete
 
bool pause ()
 pause Send Pipeline to pause state
 
bool play ()
 Send pipeline to play state.
 
EGT_NODISCARD bool playing () const
 Returns true if the stream is currently playing.
 
EGT_NODISCARD uint64_t position () const
 Get the current position of the audio stream.
 
bool seek (uint64_t pos)
 Seek to a position.
 
EGT_NODISCARD int volume () const
 Get the volume.
 
bool volume (int volume)
 Adjusts the volume of the audio being played.
 
- Public Member Functions inherited from Object
 Object () noexcept=default
 
 Object (const Object &)=delete
 
 Object (Object &&)=default
 
virtual ~Object () noexcept=default
 
void clear_handlers ()
 Clear all registered event handlers.
 
void invoke_handlers (Event &event)
 Invoke all handlers with the specified event.
 
void invoke_handlers (EventId event)
 Invoke all handlers with the specified EventId.
 
EGT_NODISCARD const std::string & name () const
 Get the name of the Object.
 
void name (const std::string &name)
 Set the name of the Object.
 
RegisterHandle on_event (const EventCallback &handler, const FilterFlags &mask={})
 Add an event handler to be called when the widget generates an event.
 
Objectoperator= (const Object &)=delete
 
Objectoperator= (Object &&)=default
 
void remove_handler (RegisterHandle handle)
 Remove an event handler.
 

Public Attributes

SignalW< int64_t > on_position_changed
 Event signal.
 
SignalW< const std::string & > on_error
 Invoked when an error occurs.
 
SignalW on_eos
 Invoked on end of stream.
 
SignalW on_state_changed
 Invoked when the state of the player changes.
 

Protected Attributes

std::unique_ptr< detail::GstDecoderImpl > m_impl
 Implementation pointer.
 
- Protected Attributes inherited from Object
detail::CopyOnWriteAllocate< CallbackArraym_callbacks
 Array of callbacks.
 
RegisterHandle m_handle_counter {0}
 Counter used to generate unique handles for each callback registration.
 
std::string m_name
 A user defined name for the Object.
 

Additional Inherited Members

- Public Types inherited from Object
using EventCallback = std::function< void(Event &event)>
 Event handler callback function.
 
using FilterFlags = FlagsBase< EventId >
 Event handler EventId filter.
 
using RegisterHandle = uint64_t
 Handle type.
 
- Protected Types inherited from Object
using CallbackArray = std::vector< CallbackMeta >
 Helper type for an array of callbacks.
 

Detailed Description

Audio player.

Constructor & Destructor Documentation

◆ AudioPlayer() [1/4]

◆ AudioPlayer() [2/4]

AudioPlayer ( const std::string &  uri)
explicit

Construct and set the media file URI to the current pipeline.

Parameters
urifile URI

◆ AudioPlayer() [3/4]

AudioPlayer ( const AudioPlayer )
delete

◆ AudioPlayer() [4/4]

AudioPlayer ( AudioPlayer &&  )
default

◆ ~AudioPlayer()

~AudioPlayer ( )
overridenoexcept

Member Function Documentation

◆ duration()

EGT_NODISCARD uint64_t duration ( ) const

Get the duration of the audio stream.

Returns
Time duration in nanoseconds.

◆ media()

bool media ( const std::string &  uri)

Sets the media file URI to the current pipeline.

Parameters
urifile URI
Returns
true on success

◆ mute()

bool mute ( bool  mute)

Mutes the audio being played.

Parameters
muteWhen true, audio is to be muted.
Returns
true on success

◆ operator=() [1/2]

AudioPlayer & operator= ( AudioPlayer &&  )
default

◆ operator=() [2/2]

AudioPlayer & operator= ( const AudioPlayer )
delete

◆ pause()

bool pause ( )

pause Send Pipeline to pause state

Returns
true on success

◆ play()

bool play ( )

Send pipeline to play state.

Returns
true on success

◆ playing()

EGT_NODISCARD bool playing ( ) const

Returns true if the stream is currently playing.

◆ position()

EGT_NODISCARD uint64_t position ( ) const

Get the current position of the audio stream.

Returns
Time duration in nanoseconds.

◆ seek()

bool seek ( uint64_t  pos)

Seek to a position.

The position is given by the position() function and the duration is given by the duration() method.

Parameters
posPosition in nanoseconds.
Returns
true on success

◆ volume() [1/2]

EGT_NODISCARD int volume ( ) const

Get the volume.

Returns
Value in the range 0 - 100.

◆ volume() [2/2]

bool volume ( int  volume)

Adjusts the volume of the audio being played.

Parameters
volumeValue in the range 0 - 100.
Returns
true on success

Member Data Documentation

◆ m_impl

std::unique_ptr<detail::GstDecoderImpl> m_impl
protected

Implementation pointer.

◆ on_eos

SignalW on_eos

Invoked on end of stream.

◆ on_error

SignalW<const std::string&> on_error

Invoked when an error occurs.

◆ on_position_changed

SignalW<int64_t> on_position_changed

Event signal.

Invoked when the position of the player changes.

◆ on_state_changed

SignalW on_state_changed

Invoked when the state of the player changes.