Music Hub  ..
A session-wide music playback service
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Friends
player.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 #ifndef COM_UBUNTU_MUSIC_PLAYER_H_
19 #define COM_UBUNTU_MUSIC_PLAYER_H_
20 
22 #include "com/ubuntu/music/track.h"
23 
24 #include <chrono>
25 #include <memory>
26 
27 namespace com
28 {
29 namespace ubuntu
30 {
31 namespace music
32 {
33 class Service;
34 class TrackList;
35 
36 class Player
37 {
38  public:
39  typedef double PlaybackRate;
40  typedef double Volume;
41 
43  {
47  };
48 
50  {
54  };
55 
56  Player(const Player&) = delete;
57  ~Player();
58 
59  Player& operator=(const Player&) = delete;
60  bool operator==(const Player&) const = delete;
61 
62  const std::shared_ptr<TrackList>& track_list() const;
63 
64  bool can_go_next();
65  void next();
66 
67  bool can_go_previous();
68  void previous();
69 
70  bool can_play();
71  void play();
72 
73  bool can_pause();
74  void pause();
75 
76  bool can_seek();
77  void seek_to(const std::chrono::microseconds& offset);
78 
79  void stop();
80 
82  Connection on_playback_status_changed(const std::function<void(PlaybackStatus)>& handler);
83 
84  LoopStatus loop_status() const;
85  void set_loop_status(LoopStatus new_status);
86  Connection on_loop_status_changed(const std::function<void(LoopStatus)>& handler);
87 
90  Connection on_playback_rate_changed(const std::function<void(PlaybackRate)>& handler);
91 
92  bool is_shuffle() const;
93  void set_shuffle(bool b);
94  Connection on_shuffle_changed(const std::function<void(bool)>& handler);
95 
97  Connection on_meta_data_for_current_track_changed(const std::function<void(const Track::MetaData&)>& handler);
98 
99  Volume volume() const;
100  void set_volume(Volume new_volume);
101  Connection on_volume_changed(const std::function<void(Volume)>& handler);
102 
105 
106  private:
107  friend class Service;
108 
109  Player(const std::shared_ptr<Service>& parent);
110 
111  struct Private;
112  std::unique_ptr<Private> d;
113 };
114 }
115 }
116 }
117 
118 #endif // COM_UBUNTU_MUSIC_PLAYER_H_