foobar2000 SDK  2015-08-03
Public Types | Public Member Functions | Static Public Attributes | Private Member Functions
playback_controlabstract

#include <playback_control.h>

+ Inheritance diagram for playback_control:

Public Types

enum  t_display_level { display_level_none, display_level_basic, display_level_titles, display_level_all }
 
enum  t_stop_reason { stop_reason_user = 0, stop_reason_eof, stop_reason_starting_another, stop_reason_shutting_down }
 
enum  t_track_command {
  track_command_default = 0, track_command_play, track_command_next, track_command_prev,
  track_command_settrack, track_command_rand, track_command_resume
}
 
- Public Types inherited from service_base
typedef service_base t_interface
 

Public Member Functions

virtual bool get_now_playing (metadb_handle_ptr &p_out)=0
 
virtual bool get_stop_after_current ()=0
 
virtual float get_volume ()=0
 
bool is_muted ()
 
virtual bool is_paused ()=0
 
virtual bool is_playing ()=0
 
void next ()
 
virtual void pause (bool p_state)=0
 
void play_or_pause ()
 
void play_or_unpause ()
 
void play_start (t_track_command p_command=track_command_play, bool p_paused=false)
 
void play_stop ()
 
virtual bool playback_can_seek ()=0
 
virtual bool playback_format_title (titleformat_hook *p_hook, pfc::string_base &p_out, const service_ptr_t< class titleformat_object > &p_script, titleformat_text_filter *p_filter, t_display_level p_level)=0
 
bool playback_format_title_ex (metadb_handle_ptr p_item, titleformat_hook *p_hook, pfc::string_base &p_out, const service_ptr_t< class titleformat_object > &p_script, titleformat_text_filter *p_filter, t_display_level p_level)
 
double playback_get_length ()
 
double playback_get_length_ex ()
 
virtual double playback_get_position ()=0
 
virtual void playback_seek (double p_time)=0
 
virtual void playback_seek_delta (double p_delta)=0
 
void previous ()
 
virtual void set_stop_after_current (bool p_state)=0
 
virtual void set_volume (float p_value)=0
 
virtual void start (t_track_command p_command=track_command_play, bool p_paused=false)=0
 
virtual void stop ()=0
 
void toggle_pause ()
 
void toggle_stop_after_current ()
 
virtual void volume_down ()=0
 
virtual void volume_mute_toggle ()=0
 
virtual void volume_up ()=0
 
- Public Member Functions inherited from service_base
template<typename outPtr_t >
bool cast (outPtr_t &outPtr)
 
virtual int service_add_ref ()=0 throw ()
 
virtual bool service_query (service_ptr_t< service_base > &p_out, const GUID &p_guid)
 
template<class T >
bool service_query_t (service_ptr_t< T > &p_out)
 
virtual int service_release ()=0 throw ()
 

Static Public Attributes

static const int volume_mute = -100
 

Private Member Functions

 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT (playback_control)
 

Additional Inherited Members

- Protected Member Functions inherited from service_base
 service_base ()
 
 ~service_base ()
 

Detailed Description

Provides control for various playback-related operations. All methods provided by this interface work from main app thread only. Calling from another thread will do nothing or trigger an exception. If you need to trigger one of playback_control methods from another thread, see main_thread_callback. Do not call playback_control methods from inside any kind of global callback (e.g. playlist callback), otherwise race conditions may occur. Use static_api_ptr_t to instantiate. See static_api_ptr_t documentation for more info.

Definition at line 5 of file playback_control.h.

Member Enumeration Documentation

Type used to indicate level of dynamic playback-related info displayed. Safe to use with <> opereators, e.g. level above N always includes information rendered by level N.

Enumerator
display_level_none 

No playback-related info.

display_level_basic 

Static info and is_playing/is_paused stats.

display_level_titles 

display_level_basic + dynamic track titles on e.g. live streams

display_level_all 

display_level_titles + timing + VBR bitrate display etc

Definition at line 80 of file playback_control.h.

80  {
89  };
display_level_basic + dynamic track titles on e.g. live streams
display_level_titles + timing + VBR bitrate display etc
Static info and is_playing/is_paused stats.
No playback-related info.
Enumerator
stop_reason_user 
stop_reason_eof 
stop_reason_starting_another 
stop_reason_shutting_down 

Definition at line 10 of file playback_control.h.

Enumerator
track_command_default 
track_command_play 
track_command_next 

Plays the next track from the current playlist according to the current playback order.

track_command_prev 

Plays the previous track from the current playlist according to the current playback order.

track_command_settrack 

For internal use only, do not use.

track_command_rand 

Plays a random track from the current playlist.

track_command_resume 

For internal use only, do not use.

Definition at line 18 of file playback_control.h.

18  {
29 
32  };
For internal use only, do not use.
Plays the next track from the current playlist according to the current playback order.
For internal use only, do not use.
Plays a random track from the current playlist.
Plays the previous track from the current playlist according to the current playback order...

Member Function Documentation

playback_control::FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT ( playback_control  )
private
virtual bool playback_control::get_now_playing ( metadb_handle_ptr p_out)
pure virtual

Retrieves now playing item handle.

Returns
true on success, false on failure (not playing).
virtual bool playback_control::get_stop_after_current ( )
pure virtual

Retrieves stop-after-current-track option state.

virtual float playback_control::get_volume ( )
pure virtual

Retrieves playback volume level.

Returns
current playback volume level, in dB; 0 for full volume.
bool playback_control::is_muted ( )
inline

Definition at line 137 of file playback_control.h.

137 {return get_volume() == volume_mute;}
static const int volume_mute
virtual float get_volume()=0
Retrieves playback volume level.
virtual bool playback_control::is_paused ( )
pure virtual

Returns whether playback is active and in paused state.

virtual bool playback_control::is_playing ( )
pure virtual

Returns whether playback is active.

void playback_control::next ( )
inline

Definition at line 130 of file playback_control.h.

virtual void start(t_track_command p_command=track_command_play, bool p_paused=false)=0
Starts playback. If playback is already active, existing process is stopped first.
Plays the next track from the current playlist according to the current playback order.
virtual void playback_control::pause ( bool  p_state)
pure virtual

Toggles pause state if playback is active.

Parameters
p_stateset to true when pausing or to false when unpausing.
void playback_control::play_or_pause ( )
inline

Starts playback if playback is inactive, otherwise toggles pause.

Definition at line 126 of file playback_control.h.

126 {if (is_playing()) toggle_pause(); else start();}
virtual bool is_playing()=0
Returns whether playback is active.
void toggle_pause()
Toggles pause state.
virtual void start(t_track_command p_command=track_command_play, bool p_paused=false)=0
Starts playback. If playback is already active, existing process is stopped first.
void playback_control::play_or_unpause ( )
inline

Definition at line 127 of file playback_control.h.

127 { if (is_playing()) pause(false); else start();}
virtual bool is_playing()=0
Returns whether playback is active.
virtual void start(t_track_command p_command=track_command_play, bool p_paused=false)=0
Starts playback. If playback is already active, existing process is stopped first.
virtual void pause(bool p_state)=0
Toggles pause state if playback is active.
void playback_control::play_start ( t_track_command  p_command = track_command_play,
bool  p_paused = false 
)
inline

Definition at line 133 of file playback_control.h.

133 {start(p_command,p_paused);}
virtual void start(t_track_command p_command=track_command_play, bool p_paused=false)=0
Starts playback. If playback is already active, existing process is stopped first.
void playback_control::play_stop ( )
inline

Definition at line 135 of file playback_control.h.

135 {stop();}
virtual void stop()=0
Stops playback.
virtual bool playback_control::playback_can_seek ( )
pure virtual

Returns whether currently played track is seekable. If it's not, playback_seek/playback_seek_delta calls will be ignored.

virtual bool playback_control::playback_format_title ( titleformat_hook p_hook,
pfc::string_base p_out,
const service_ptr_t< class titleformat_object > &  p_script,
titleformat_text_filter p_filter,
t_display_level  p_level 
)
pure virtual

Renders information about currently playing item.

Parameters
p_hookOptional callback object overriding fields and functions; set to NULL if not used.
p_outString receiving the output on success.
p_scriptTitleformat script to use. Use titleformat_compiler service to create one.
p_filterOptional callback object allowing input to be filtered according to context (i.e. removal of linebreak characters present in tags when rendering playlist lines). Set to NULL when not used.
p_levelIndicates level of dynamic playback-related info displayed. See t_display_level enum for more details.
Returns
true on success, false when no item is currently being played.
bool playback_control::playback_format_title_ex ( metadb_handle_ptr  p_item,
titleformat_hook p_hook,
pfc::string_base p_out,
const service_ptr_t< class titleformat_object > &  p_script,
titleformat_text_filter p_filter,
t_display_level  p_level 
)
inline

Helper; renders info about any item, including currently playing item info if the item is currently played.

Definition at line 103 of file playback_control.h.

103  {
104  if (p_item.is_empty()) return playback_format_title(p_hook,p_out,p_script,p_filter,p_level);
105  metadb_handle_ptr temp;
106  if (get_now_playing(temp)) {
107  if (temp == p_item) {
108  return playback_format_title(p_hook,p_out,p_script,p_filter,p_level);
109  }
110  }
111  p_item->format_title(p_hook,p_out,p_script,p_filter);
112  return true;
113  }
bool is_empty() const
Definition: service.h:120
virtual bool get_now_playing(metadb_handle_ptr &p_out)=0
Retrieves now playing item handle.
virtual bool playback_format_title(titleformat_hook *p_hook, pfc::string_base &p_out, const service_ptr_t< class titleformat_object > &p_script, titleformat_text_filter *p_filter, t_display_level p_level)=0
Renders information about currently playing item.
double playback_control::playback_get_length ( )

Helper; retrieves length of currently playing item.

Definition at line 33 of file playback_control.cpp.

34 {
35  double rv = 0;
37  if (get_now_playing(ptr))
38  {
39  rv = ptr->get_length();
40  }
41  return rv;
42 }
virtual bool get_now_playing(metadb_handle_ptr &p_out)=0
Retrieves now playing item handle.
double playback_control::playback_get_length_ex ( )

Definition at line 44 of file playback_control.cpp.

44  {
45  double rv = 0;
47  if (get_now_playing(ptr))
48  {
49  rv = ptr->get_length();
50  if (rv <= 0) {
51  pfc::string8 temp;
52  titleformat_object::ptr script;
53  static_api_ptr_t<titleformat_compiler>()->compile_force(script, "[%length_ex%]");
54  this->playback_format_title(NULL, temp, script, NULL, display_level_titles);
55  if (temp.length() > 0) rv = parse_time(temp);
56  }
57  }
58  return rv;
59 }
display_level_basic + dynamic track titles on e.g. live streams
virtual bool get_now_playing(metadb_handle_ptr &p_out)=0
Retrieves now playing item handle.
virtual bool playback_format_title(titleformat_hook *p_hook, pfc::string_base &p_out, const service_ptr_t< class titleformat_object > &p_script, titleformat_text_filter *p_filter, t_display_level p_level)=0
Renders information about currently playing item.
static double parse_time(const char *time)
Helper template used to easily access core services. Usage: static_api_ptr_t<myclass> api; api->doso...
Definition: service.h:533
t_size length() const
For compatibility with old conventions.
Definition: string_base.h:209
virtual double playback_control::playback_get_position ( )
pure virtual

Returns current playback position within currently played track, in seconds.

virtual void playback_control::playback_seek ( double  p_time)
pure virtual

Seeks in currenly played track to specified time.

Parameters
p_timetarget time in seconds.
virtual void playback_control::playback_seek_delta ( double  p_delta)
pure virtual

Seeks in currently played track by specified time forward or back.

Parameters
p_deltatime in seconds to seek by; can be positive to seek forward or negative to seek back.
void playback_control::previous ( )
inline

Definition at line 129 of file playback_control.h.

virtual void start(t_track_command p_command=track_command_play, bool p_paused=false)=0
Starts playback. If playback is already active, existing process is stopped first.
Plays the previous track from the current playlist according to the current playback order...
virtual void playback_control::set_stop_after_current ( bool  p_state)
pure virtual

Alters stop-after-current-track option state.

virtual void playback_control::set_volume ( float  p_value)
pure virtual

Alters playback volume level.

Parameters
p_valuevolume in dB; 0 for full volume.
virtual void playback_control::start ( t_track_command  p_command = track_command_play,
bool  p_paused = false 
)
pure virtual

Starts playback. If playback is already active, existing process is stopped first.

Parameters
p_commandSpecifies what track to start playback from. See t_track_Command enum for more info.
p_pausedSpecifies whether playback should be started as paused.
virtual void playback_control::stop ( )
pure virtual

Stops playback.

void playback_control::toggle_pause ( )
inline

Toggles pause state.

Definition at line 123 of file playback_control.h.

123 {pause(!is_paused());}
virtual void pause(bool p_state)=0
Toggles pause state if playback is active.
virtual bool is_paused()=0
Returns whether playback is active and in paused state.
void playback_control::toggle_stop_after_current ( )
inline

Toggles stop-after-current state.

Definition at line 121 of file playback_control.h.

virtual bool get_stop_after_current()=0
Retrieves stop-after-current-track option state.
virtual void set_stop_after_current(bool p_state)=0
Alters stop-after-current-track option state.
virtual void playback_control::volume_down ( )
pure virtual

Alters playback volume level one step down.

virtual void playback_control::volume_mute_toggle ( )
pure virtual

Toggles playback mute state.

virtual void playback_control::volume_up ( )
pure virtual

Alters playback volume level one step up.

Field Documentation

const int playback_control::volume_mute = -100
static

Definition at line 139 of file playback_control.h.


The documentation for this class was generated from the following files: