Merge lp:~jhodapp/media-hub/player-add-prev-next into lp:media-hub

Proposed by Jim Hodapp
Status: Merged
Approved by: Nick Dedekind
Approved revision: 139
Merged at revision: 143
Proposed branch: lp:~jhodapp/media-hub/player-add-prev-next
Merge into: lp:media-hub
Diff against target: 187 lines (+73/-5)
8 files modified
include/core/media/track_list.h (+12/-0)
src/core/media/gstreamer/playbin.cpp (+0/-1)
src/core/media/player_implementation.cpp (+16/-2)
src/core/media/track_list.cpp (+10/-0)
src/core/media/track_list_skeleton.cpp (+17/-1)
src/core/media/track_list_skeleton.h (+3/-1)
src/core/media/track_list_stub.cpp (+12/-0)
src/core/media/track_list_stub.h (+3/-0)
To merge this branch: bzr merge lp:~jhodapp/media-hub/player-add-prev-next
Reviewer Review Type Date Requested Status
Nick Dedekind (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+257824@code.launchpad.net

Commit message

Add next/previous track implementation for the Player and can_go_next/previous.

Description of the change

Add next/previous track implementation for the Player and can_go_next/previous.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

Added a couple of inline comments.

review: Needs Fixing
Revision history for this message
Jim Hodapp (jhodapp) :
Revision history for this message
Nick Dedekind (nick-dedekind) :
review: Needs Fixing
Revision history for this message
Jim Hodapp (jhodapp) :
Revision history for this message
Jim Hodapp (jhodapp) :
138. By Jim Hodapp

Move has_previous/has/next into base class instead of impl since it called the parent class anyway.

139. By Jim Hodapp

Merged with trunk.

Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/core/media/track_list.h'
2--- include/core/media/track_list.h 2015-04-20 15:45:51 +0000
3+++ include/core/media/track_list.h 2015-05-22 21:20:47 +0000
4@@ -70,6 +70,18 @@
5 /** Skip to the specified TrackId. Calls stop() and play() on the player if toggle_player_state is true. */
6 virtual void go_to(const Track::Id& track, bool toggle_player_state) = 0;
7
8+ /** Returns true if there is a next track in the TrackList after the current one playing */
9+ bool has_next() const;
10+
11+ /** Returns true if there is a previous track in the TrackList before the current one playing */
12+ bool has_previous() const;
13+
14+ /** Skip to the next Track in the TrackList if there is one. */
15+ virtual Track::Id next() = 0;
16+
17+ /** Skip to the previous Track in the TrackList if there is one. */
18+ virtual Track::Id previous() = 0;
19+
20
21 /** Reorders the tracks such that they are in a random order. */
22 virtual void shuffle_tracks() = 0;
23
24=== modified file 'src/core/media/gstreamer/playbin.cpp'
25--- src/core/media/gstreamer/playbin.cpp 2015-04-15 17:13:58 +0000
26+++ src/core/media/gstreamer/playbin.cpp 2015-05-22 21:20:47 +0000
27@@ -510,7 +510,6 @@
28 return std::string();
29
30 std::string filename(uri);
31- std::cout << "filename: " << filename << std::endl;
32 size_t pos = uri.find("file://");
33 if (pos != std::string::npos)
34 filename = uri.substr(pos + 7, std::string::npos);
35
36=== modified file 'src/core/media/player_implementation.cpp'
37--- src/core/media/player_implementation.cpp 2015-05-11 19:20:42 +0000
38+++ src/core/media/player_implementation.cpp 2015-05-22 21:20:47 +0000
39@@ -316,8 +316,8 @@
40 Parent::can_play().set(true);
41 Parent::can_pause().set(true);
42 Parent::can_seek().set(true);
43- Parent::can_go_previous().set(true);
44- Parent::can_go_next().set(true);
45+ Parent::can_go_previous().set(false);
46+ Parent::can_go_next().set(false);
47 Parent::is_video_source().set(false);
48 Parent::is_audio_source().set(false);
49 Parent::shuffle().set(false);
50@@ -360,6 +360,18 @@
51 };
52 Parent::is_audio_source().install(audio_type_getter);
53
54+ std::function<bool()> can_go_next_getter = [this]()
55+ {
56+ return d->track_list->has_next();
57+ };
58+ Parent::can_go_next().install(can_go_next_getter);
59+
60+ std::function<bool()> can_go_previous_getter = [this]()
61+ {
62+ return d->track_list->has_previous();
63+ };
64+ Parent::can_go_previous().install(can_go_previous_getter);
65+
66 // When the client changes the loop status, make sure to update the TrackList
67 Parent::loop_status().changed().connect([this](media::Player::LoopStatus loop_status)
68 {
69@@ -590,11 +602,13 @@
70 template<typename Parent>
71 void media::PlayerImplementation<Parent>::next()
72 {
73+ d->track_list->next();
74 }
75
76 template<typename Parent>
77 void media::PlayerImplementation<Parent>::previous()
78 {
79+ d->track_list->previous();
80 }
81
82 template<typename Parent>
83
84=== modified file 'src/core/media/track_list.cpp'
85--- src/core/media/track_list.cpp 2014-01-13 21:51:14 +0000
86+++ src/core/media/track_list.cpp 2015-05-22 21:20:47 +0000
87@@ -33,3 +33,13 @@
88 media::TrackList::~TrackList()
89 {
90 }
91+
92+bool media::TrackList::has_next() const
93+{
94+ return false;
95+}
96+
97+bool media::TrackList::has_previous() const
98+{
99+ return false;
100+}
101
102=== modified file 'src/core/media/track_list_skeleton.cpp'
103--- src/core/media/track_list_skeleton.cpp 2015-04-20 17:56:05 +0000
104+++ src/core/media/track_list_skeleton.cpp 2015-05-22 21:20:47 +0000
105@@ -206,7 +206,17 @@
106 return next_track != tracks().get().end();
107 }
108
109-const media::Track::Id& media::TrackListSkeleton::next()
110+bool media::TrackListSkeleton::has_previous() const
111+{
112+ // If we are looping over the entire list, then there is always a previous track
113+ if (d->loop_status == media::Player::LoopStatus::playlist)
114+ return true;
115+
116+ std::cout << "has_previous track? " << (d->current_track != tracks().get().begin() ? "yes" : "no") << std::endl;
117+ return d->current_track != tracks().get().begin();
118+}
119+
120+media::Track::Id media::TrackListSkeleton::next()
121 {
122 std::cout << __PRETTY_FUNCTION__ << std::endl;
123 if (tracks().get().empty())
124@@ -235,6 +245,12 @@
125 return *(d->current_track);
126 }
127
128+media::Track::Id media::TrackListSkeleton::previous()
129+{
130+ // TODO: Add logic to calculate the previous track
131+ return *(d->current_track);
132+}
133+
134 const media::Track::Id& media::TrackListSkeleton::current()
135 {
136 // Prevent the TrackList from sitting at the end which will cause
137
138=== modified file 'src/core/media/track_list_skeleton.h'
139--- src/core/media/track_list_skeleton.h 2015-04-20 17:48:48 +0000
140+++ src/core/media/track_list_skeleton.h 2015-05-22 21:20:47 +0000
141@@ -42,7 +42,9 @@
142 ~TrackListSkeleton();
143
144 bool has_next() const;
145- const Track::Id& next();
146+ bool has_previous() const;
147+ Track::Id next();
148+ Track::Id previous();
149 const Track::Id& current();
150
151 const core::Property<bool>& can_edit_tracks() const;
152
153=== modified file 'src/core/media/track_list_stub.cpp'
154--- src/core/media/track_list_stub.cpp 2015-04-20 17:48:48 +0000
155+++ src/core/media/track_list_stub.cpp 2015-05-22 21:20:47 +0000
156@@ -137,6 +137,18 @@
157 throw std::runtime_error("Problem adding track: " + op.error());
158 }
159
160+media::Track::Id media::TrackListStub::next()
161+{
162+ // TODO: Add this to the dbus interface on the server and implement a proper dbus method call
163+ return media::Track::Id{"/empty/track/id"};
164+}
165+
166+media::Track::Id media::TrackListStub::previous()
167+{
168+ // TODO: Add this to the dbus interface on the server and implement a proper dbus method call
169+ return media::Track::Id{"/empty/track/id"};
170+}
171+
172 void media::TrackListStub::shuffle_tracks()
173 {
174 std::cerr << "shuffle_tracks() does nothing from the client side" << std::endl;
175
176=== modified file 'src/core/media/track_list_stub.h'
177--- src/core/media/track_list_stub.h 2015-04-20 15:45:51 +0000
178+++ src/core/media/track_list_stub.h 2015-05-22 21:20:47 +0000
179@@ -51,6 +51,9 @@
180
181 void go_to(const Track::Id& track, bool toggle_player_state);
182
183+ Track::Id next();
184+ Track::Id previous();
185+
186 void shuffle_tracks();
187 void unshuffle_tracks();
188

Subscribers

People subscribed via source and target branches