Merge lp:~morphis/media-hub/previous-to-same-after-four-secs into lp:media-hub/stable

Proposed by Simon Fels
Status: Merged
Merged at revision: 163
Proposed branch: lp:~morphis/media-hub/previous-to-same-after-four-secs
Merge into: lp:media-hub/stable
Diff against target: 90 lines (+26/-2)
3 files modified
src/core/media/player_implementation.cpp (+5/-0)
src/core/media/track_list_skeleton.cpp (+19/-2)
src/core/media/track_list_skeleton.h (+2/-0)
To merge this branch: bzr merge lp:~morphis/media-hub/previous-to-same-after-four-secs
Reviewer Review Type Date Requested Status
Jim Hodapp (community) code Needs Fixing
Review via email: mp+275872@code.launchpad.net

Commit message

When calling previous and we already have played more than four seconds of the track we repeat the same track again. Switching to the previous track is possible when being issued before the first four seconds are over.

Description of the change

When calling previous and we already have played more than four seconds of the track we repeat the same track again. Switching to the previous track is possible when being issued before the first four seconds are over.

To post a comment you must log in.
Revision history for this message
Jim Hodapp (jhodapp) wrote :

A few minor suggestions inline.

review: Needs Fixing (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/core/media/player_implementation.cpp'
2--- src/core/media/player_implementation.cpp 2015-10-22 17:31:32 +0000
3+++ src/core/media/player_implementation.cpp 2015-10-27 15:54:53 +0000
4@@ -375,6 +375,11 @@
5 };
6 Parent::position().install(position_getter);
7
8+ d->engine->position().changed().connect([this](uint64_t position)
9+ {
10+ d->track_list->on_position_changed(position);
11+ });
12+
13 // Make sure that the Duration property gets updated from the Engine
14 // every time the client requests duration
15 std::function<uint64_t()> duration_getter = [this]()
16
17=== modified file 'src/core/media/track_list_skeleton.cpp'
18--- src/core/media/track_list_skeleton.cpp 2015-10-23 15:30:47 +0000
19+++ src/core/media/track_list_skeleton.cpp 2015-10-27 15:54:53 +0000
20@@ -56,6 +56,7 @@
21 current_track(skeleton.properties.tracks->get().begin()),
22 empty_iterator(skeleton.properties.tracks->get().begin()),
23 loop_status(media::Player::LoopStatus::none),
24+ current_position(0),
25 signals
26 {
27 skeleton.signals.track_added,
28@@ -212,6 +213,7 @@
29 TrackList::ConstIterator current_track;
30 TrackList::ConstIterator empty_iterator;
31 media::Player::LoopStatus loop_status;
32+ uint64_t current_position;
33
34 struct Signals
35 {
36@@ -423,9 +425,18 @@
37 }
38
39 bool do_go_to_previous_track = false;
40+ bool repeat_current_track = false;
41+ const uint64_t max_position = 4 * 1000;
42
43+ // If we're playing the current already for some time we will
44+ // repeat it from the beginning
45+ if (d->current_position > max_position)
46+ {
47+ std::cout << "Repeating current track..." << std::endl;
48+ repeat_current_track = true;
49+ }
50 // Loop on the current track forever
51- if (d->loop_status == media::Player::LoopStatus::track)
52+ else if (d->loop_status == media::Player::LoopStatus::track)
53 {
54 std::cout << "Looping on the current track..." << std::endl;
55 do_go_to_previous_track = true;
56@@ -454,7 +465,7 @@
57 }
58 }
59
60- if (do_go_to_previous_track)
61+ if (do_go_to_previous_track && !repeat_current_track)
62 {
63 on_track_changed()(*(current_iterator()));
64 // Don't automatically call stop() and play() in player_implementation.cpp on_go_to_track()
65@@ -514,6 +525,12 @@
66 return *d->skeleton.properties.tracks;
67 }
68
69+void media::TrackListSkeleton::on_position_changed(uint64_t position)
70+{
71+ std::cout << "TrackListSkeleton::on_position_changed: position = " << position << std::endl;
72+ d->current_position = position;
73+}
74+
75 void media::TrackListSkeleton::on_loop_status_changed(const media::Player::LoopStatus& loop_status)
76 {
77 d->loop_status = loop_status;
78
79=== modified file 'src/core/media/track_list_skeleton.h'
80--- src/core/media/track_list_skeleton.h 2015-10-21 19:40:20 +0000
81+++ src/core/media/track_list_skeleton.h 2015-10-27 15:54:53 +0000
82@@ -69,6 +69,8 @@
83 void on_loop_status_changed(const core::ubuntu::media::Player::LoopStatus& loop_status);
84 core::ubuntu::media::Player::LoopStatus loop_status() const;
85
86+ void on_position_changed(uint64_t position);
87+
88 /** Gets called when the shuffle property on the Player interface is changed
89 * by the client */
90 void on_shuffle_changed(bool shuffle);

Subscribers

People subscribed via source and target branches