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

Audio player. More...

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

Public Attributes

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

Protected Member Functions

bool createPipeline (const std::string &uri)
 Create the pipeline. More...
 
void destroyPipeline ()
 Destroy the pipeline. More...
 
bool null ()
 Send pipeline to null state. More...
 

Protected Attributes

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

Additional Inherited Members

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

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

◆ createPipeline()

bool createPipeline ( const std::string &  uri)
protected

Create the pipeline.

◆ destroyPipeline()

void destroyPipeline ( )
protected

Destroy the pipeline.

◆ 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

◆ null()

bool null ( )
protected

Send pipeline to null state.

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::AudioPlayerImpl> m_impl
protected

Implementation pointer.

◆ on_eos

Signal on_eos

Invoked on end of stream.

◆ on_error

Signal<const std::string&> on_error

Invoked when an error occurs.

◆ on_position_changed

Signal<uint64_t> on_position_changed

Event signal.

Invoked when the position of the player changes.

◆ on_state_changed

Signal on_state_changed

Invoked when the state of the player changes.