Merge lp:~phablet-team/media-hub/mpris into lp:media-hub/stable

Proposed by Jim Hodapp
Status: Merged
Approved by: Alfonso Sanchez-Beato
Approved revision: 172
Merged at revision: 159
Proposed branch: lp:~phablet-team/media-hub/mpris
Merge into: lp:media-hub/stable
Diff against target: 528 lines (+117/-120)
14 files modified
CMakeLists.txt (+1/-1)
README (+9/-0)
debian/changelog (+10/-0)
include/core/media/service.h (+3/-0)
src/core/media/mpris/service.h (+1/-0)
src/core/media/player_implementation.cpp (+4/-2)
src/core/media/service_implementation.cpp (+5/-0)
src/core/media/service_implementation.h (+1/-0)
src/core/media/service_skeleton.cpp (+72/-113)
src/core/media/service_skeleton.h (+1/-0)
src/core/media/service_stub.cpp (+9/-1)
src/core/media/service_stub.h (+1/-0)
src/core/media/track_list_implementation.cpp (+0/-2)
src/core/media/track_list_skeleton.cpp (+0/-1)
To merge this branch: bzr merge lp:~phablet-team/media-hub/mpris
Reviewer Review Type Date Requested Status
Alfonso Sanchez-Beato Approve
Review via email: mp+269755@code.launchpad.net

Commit message

Re-enable MPRIS player controls and improves background playlists.

Description of the change

Re-enable MPRIS player controls and improves background playlists.

To post a comment you must log in.
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) :
review: Approve
lp:~phablet-team/media-hub/mpris updated
173. By Jim Hodapp

Make sure the correct player is set as the current player controled by MPRIS. Also improved the can_go_next() and can_go_previous() logic to always return true if the loop_status is currently set to loop over the entire playlist.

174. By Jim Hodapp

Bump version for change in interface

175. By Jim Hodapp

Merged with upstream

176. By Jim Hodapp

Bumped the package version.

Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

Some minor fixes required. A MP for trunk would be good too.

review: Needs Fixing
lp:~phablet-team/media-hub/mpris updated
177. By Jim Hodapp

Added link to a coding standard for this code base and fixed line length in debian/changelog entry.

Revision history for this message
Jim Hodapp (jhodapp) wrote :

Comments addressed.

lp:~phablet-team/media-hub/mpris updated
178. By Jim Hodapp

Address code review comments

179. By Jim Hodapp

Addressed review comment - check for if (sp) is now moved into is_multimedia_role()

Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2015-04-10 16:21:16 +0000
+++ CMakeLists.txt 2015-09-09 16:32:06 +0000
@@ -3,7 +3,7 @@
3project(ubuntu-media-hub)3project(ubuntu-media-hub)
44
5set(UBUNTU_MEDIA_HUB_VERSION_MAJOR 3)5set(UBUNTU_MEDIA_HUB_VERSION_MAJOR 3)
6set(UBUNTU_MEDIA_HUB_VERSION_MINOR 1)6set(UBUNTU_MEDIA_HUB_VERSION_MINOR 2)
7set(UBUNTU_MEDIA_HUB_VERSION_PATCH 0)7set(UBUNTU_MEDIA_HUB_VERSION_PATCH 0)
88
9set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -fPIC -pthread")9set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -fPIC -pthread")
1010
=== modified file 'README'
--- README 2014-08-08 14:36:29 +0000
+++ README 2015-09-09 16:32:06 +0000
@@ -1,3 +1,12 @@
1Coding Convention:
2------------------
3
4NOTE: the media-hub code did not start out with the following coding convention, but it is being introduced to try and
5converge on a standard from this point forward:
6
7https://google-styleguide.googlecode.com/svn/trunk/cppguide.html
8
9
1To Build:10To Build:
2---------11---------
312
413
=== modified file 'debian/changelog'
--- debian/changelog 2015-09-04 18:51:23 +0000
+++ debian/changelog 2015-09-09 16:32:06 +0000
@@ -1,3 +1,13 @@
1media-hub (3.2.0+15.04.20150904-0ubuntu1) UNRELEASED; urgency=medium
2
3 * Make sure the correct player is set as the current player controled by
4 MPRIS.
5 * Improved the can_go_next() and can_go_previous() logic to always return
6 true if the loop_status is currently set to loop over the entire
7 playlist.
8
9 -- phablet <phablet@ubuntu-phablet> Tue, 08 Sep 2015 17:18:15 -0400
10
1media-hub (3.1.0+15.04.20150904-0ubuntu1) vivid; urgency=medium11media-hub (3.1.0+15.04.20150904-0ubuntu1) vivid; urgency=medium
212
3 [ Alfonso Sanchez-Beato (email Canonical) ]13 [ Alfonso Sanchez-Beato (email Canonical) ]
414
=== modified file 'include/core/media/service.h'
--- include/core/media/service.h 2015-04-14 02:43:56 +0000
+++ include/core/media/service.h 2015-09-09 16:32:06 +0000
@@ -60,6 +60,9 @@
60 /** @brief Resumes a fixed-name session directly by player key. */60 /** @brief Resumes a fixed-name session directly by player key. */
61 virtual std::shared_ptr<Player> resume_session(Player::PlayerKey) = 0;61 virtual std::shared_ptr<Player> resume_session(Player::PlayerKey) = 0;
6262
63 /** @brief Sets the current player that the MPRIS interface will control */
64 virtual void set_current_player(Player::PlayerKey) = 0;
65
63 /** @brief Pauses sessions other than the supplied one. */66 /** @brief Pauses sessions other than the supplied one. */
64 virtual void pause_other_sessions(Player::PlayerKey) = 0;67 virtual void pause_other_sessions(Player::PlayerKey) = 0;
6568
6669
=== modified file 'src/core/media/mpris/service.h'
--- src/core/media/mpris/service.h 2015-04-10 16:13:55 +0000
+++ src/core/media/mpris/service.h 2015-09-09 16:32:06 +0000
@@ -115,6 +115,7 @@
115 DBUS_CPP_METHOD_WITH_TIMEOUT_DEF(DestroySession, Service, 1000)115 DBUS_CPP_METHOD_WITH_TIMEOUT_DEF(DestroySession, Service, 1000)
116 DBUS_CPP_METHOD_WITH_TIMEOUT_DEF(CreateFixedSession, Service, 1000)116 DBUS_CPP_METHOD_WITH_TIMEOUT_DEF(CreateFixedSession, Service, 1000)
117 DBUS_CPP_METHOD_WITH_TIMEOUT_DEF(ResumeSession, Service, 1000)117 DBUS_CPP_METHOD_WITH_TIMEOUT_DEF(ResumeSession, Service, 1000)
118 DBUS_CPP_METHOD_WITH_TIMEOUT_DEF(SetCurrentPlayer, Service, 1000)
118 DBUS_CPP_METHOD_WITH_TIMEOUT_DEF(PauseOtherSessions, Service, 1000)119 DBUS_CPP_METHOD_WITH_TIMEOUT_DEF(PauseOtherSessions, Service, 1000)
119};120};
120}121}
121122
=== modified file 'src/core/media/player_implementation.cpp'
--- src/core/media/player_implementation.cpp 2015-07-27 22:15:33 +0000
+++ src/core/media/player_implementation.cpp 2015-09-09 16:32:06 +0000
@@ -376,13 +376,15 @@
376376
377 std::function<bool()> can_go_next_getter = [this]()377 std::function<bool()> can_go_next_getter = [this]()
378 {378 {
379 return d->track_list->has_next();379 // If LoopStatus == playlist, then there is always a next track
380 return d->track_list->has_next() or Parent::loop_status() == Player::LoopStatus::playlist;
380 };381 };
381 Parent::can_go_next().install(can_go_next_getter);382 Parent::can_go_next().install(can_go_next_getter);
382383
383 std::function<bool()> can_go_previous_getter = [this]()384 std::function<bool()> can_go_previous_getter = [this]()
384 {385 {
385 return d->track_list->has_previous();386 // If LoopStatus == playlist, then there is always a next previous
387 return d->track_list->has_previous() or Parent::loop_status() == Player::LoopStatus::playlist;
386 };388 };
387 Parent::can_go_previous().install(can_go_previous_getter);389 Parent::can_go_previous().install(can_go_previous_getter);
388390
389391
=== modified file 'src/core/media/service_implementation.cpp'
--- src/core/media/service_implementation.cpp 2015-04-17 16:44:30 +0000
+++ src/core/media/service_implementation.cpp 2015-09-09 16:32:06 +0000
@@ -246,6 +246,11 @@
246 return std::shared_ptr<media::Player>();246 return std::shared_ptr<media::Player>();
247}247}
248248
249void media::ServiceImplementation::set_current_player(Player::PlayerKey key)
250{
251 // no impl
252}
253
249void media::ServiceImplementation::pause_other_sessions(media::Player::PlayerKey key)254void media::ServiceImplementation::pause_other_sessions(media::Player::PlayerKey key)
250{255{
251 if (not d->configuration.player_store->has_player_for_key(key))256 if (not d->configuration.player_store->has_player_for_key(key))
252257
=== modified file 'src/core/media/service_implementation.h'
--- src/core/media/service_implementation.h 2015-04-16 15:19:35 +0000
+++ src/core/media/service_implementation.h 2015-09-09 16:32:06 +0000
@@ -49,6 +49,7 @@
49 void destroy_session(const std::string&, const Player::Configuration&);49 void destroy_session(const std::string&, const Player::Configuration&);
50 std::shared_ptr<Player> create_fixed_session(const std::string& name, const Player::Configuration&);50 std::shared_ptr<Player> create_fixed_session(const std::string& name, const Player::Configuration&);
51 std::shared_ptr<Player> resume_session(Player::PlayerKey key);51 std::shared_ptr<Player> resume_session(Player::PlayerKey key);
52 void set_current_player(Player::PlayerKey key);
52 void pause_other_sessions(Player::PlayerKey key);53 void pause_other_sessions(Player::PlayerKey key);
5354
54private:55private:
5556
=== modified file 'src/core/media/service_skeleton.cpp'
--- src/core/media/service_skeleton.cpp 2015-08-11 16:10:14 +0000
+++ src/core/media/service_skeleton.cpp 2015-09-09 16:32:06 +0000
@@ -91,6 +91,11 @@
91 &Private::handle_resume_session,91 &Private::handle_resume_session,
92 this,92 this,
93 std::placeholders::_1));93 std::placeholders::_1));
94 object->install_method_handler<mpris::Service::SetCurrentPlayer>(
95 std::bind(
96 &Private::handle_set_current_player,
97 this,
98 std::placeholders::_1));
94 object->install_method_handler<mpris::Service::PauseOtherSessions>(99 object->install_method_handler<mpris::Service::PauseOtherSessions>(
95 std::bind(100 std::bind(
96 &Private::handle_pause_other_sessions,101 &Private::handle_pause_other_sessions,
@@ -102,7 +107,7 @@
102 {107 {
103 static unsigned int session_counter = 0;108 static unsigned int session_counter = 0;
104109
105 unsigned int current_session = session_counter++;110 const unsigned int current_session = session_counter++;
106 boost::uuids::uuid uuid = gen();111 boost::uuids::uuid uuid = gen();
107112
108 std::stringstream ss;113 std::stringstream ss;
@@ -134,7 +139,8 @@
134 configuration.player_store->add_player_for_key(key, impl->create_session(config));139 configuration.player_store->add_player_for_key(key, impl->create_session(config));
135 uuid_player_map.insert(std::make_pair(uuid, key));140 uuid_player_map.insert(std::make_pair(uuid, key));
136141
137 request_context_resolver->resolve_context_for_dbus_name_async(msg->sender(), [this, key, msg](const media::apparmor::ubuntu::Context& context)142 request_context_resolver->resolve_context_for_dbus_name_async(msg->sender(),
143 [this, key, msg](const media::apparmor::ubuntu::Context& context)
138 {144 {
139 fprintf(stderr, "%s():%d -- app_name='%s', attached\n", __func__, __LINE__, context.str().c_str());145 fprintf(stderr, "%s():%d -- app_name='%s', attached\n", __func__, __LINE__, context.str().c_str());
140 player_owner_map.insert(std::make_pair(key, std::make_tuple(context.str(), true, msg->sender())));146 player_owner_map.insert(std::make_pair(key, std::make_tuple(context.str(), true, msg->sender())));
@@ -213,7 +219,8 @@
213 ss << "/core/ubuntu/media/Service/sessions/" << key;219 ss << "/core/ubuntu/media/Service/sessions/" << key;
214 dbus::types::ObjectPath op{ss.str()};220 dbus::types::ObjectPath op{ss.str()};
215221
216 request_context_resolver->resolve_context_for_dbus_name_async(msg->sender(), [this, msg, key, op](const media::apparmor::ubuntu::Context& context)222 request_context_resolver->resolve_context_for_dbus_name_async(msg->sender(),
223 [this, msg, key, op](const media::apparmor::ubuntu::Context& context)
217 {224 {
218 auto info = player_owner_map.at(key);225 auto info = player_owner_map.at(key);
219 fprintf(stderr, "%s():%d -- reattach app_name='%s', info='%s', '%s'\n", __func__, __LINE__, context.str().c_str(), std::get<0>(info).c_str(), std::get<2>(info).c_str());226 fprintf(stderr, "%s():%d -- reattach app_name='%s', info='%s', '%s'\n", __func__, __LINE__, context.str().c_str(), std::get<0>(info).c_str(), std::get<2>(info).c_str());
@@ -224,6 +231,12 @@
224 // Signal player reconnection231 // Signal player reconnection
225 auto player = configuration.player_store->player_for_key(key);232 auto player = configuration.player_store->player_for_key(key);
226 player->reconnect();233 player->reconnect();
234 // We only care to allow the MPRIS controls to apply to multimedia player (i.e. audio, video)
235 if (player->audio_stream_role() == media::Player::AudioStreamRole::multimedia)
236 {
237 std::cout << "Setting current_player" << std::endl;
238 exported.set_current_player(player);
239 }
227240
228 auto reply = dbus::Message::make_method_return(msg);241 auto reply = dbus::Message::make_method_return(msg);
229 reply->writer() << op;242 reply->writer() << op;
@@ -280,7 +293,8 @@
280 // the session is no longer usable.293 // the session is no longer usable.
281 uuid_player_map.erase(uuid);294 uuid_player_map.erase(uuid);
282295
283 request_context_resolver->resolve_context_for_dbus_name_async(msg->sender(), [this, msg, key](const media::apparmor::ubuntu::Context& context)296 request_context_resolver->resolve_context_for_dbus_name_async(msg->sender(),
297 [this, msg, key](const media::apparmor::ubuntu::Context& context)
284 {298 {
285 auto info = player_owner_map.at(key);299 auto info = player_owner_map.at(key);
286 fprintf(stderr, "%s():%d -- Destroying app_name='%s', info='%s', '%s'\n", __func__, __LINE__, context.str().c_str(), std::get<0>(info).c_str(), std::get<2>(info).c_str());300 fprintf(stderr, "%s():%d -- Destroying app_name='%s', info='%s', '%s'\n", __func__, __LINE__, context.str().c_str(), std::get<0>(info).c_str(), std::get<2>(info).c_str());
@@ -424,9 +438,18 @@
424 }438 }
425 }439 }
426440
441 void handle_set_current_player(const core::dbus::Message::Ptr& msg)
442 {
443 Player::PlayerKey key;
444 msg->reader() >> key;
445 impl->set_current_player(key);
446
447 auto reply = dbus::Message::make_method_return(msg);
448 impl->access_bus()->send(reply);
449 }
450
427 void handle_pause_other_sessions(const core::dbus::Message::Ptr& msg)451 void handle_pause_other_sessions(const core::dbus::Message::Ptr& msg)
428 {452 {
429 std::cout << __PRETTY_FUNCTION__ << std::endl;
430 Player::PlayerKey key;453 Player::PlayerKey key;
431 msg->reader() >> key;454 msg->reader() >> key;
432 impl->pause_other_sessions(key);455 impl->pause_other_sessions(key);
@@ -477,20 +500,10 @@
477 return defaults;500 return defaults;
478 }501 }
479502
480 static std::string service_name()
481 {
482 static const bool export_to_indicator_sound_via_mpris
483 {
484 core::posix::this_process::env::get("UBUNTU_MEDIA_HUB_EXPORT_TO_INDICATOR_VIA_MPRIS", "0") == "1"
485 };
486
487 return export_to_indicator_sound_via_mpris ? "org.mpris.MediaPlayer2.MediaHub" :
488 "hidden.org.mpris.MediaPlayer2.MediaHub";
489 }
490
491 explicit Exported(const dbus::Bus::Ptr& bus, const media::CoverArtResolver& cover_art_resolver)503 explicit Exported(const dbus::Bus::Ptr& bus, const media::CoverArtResolver& cover_art_resolver)
492 : bus{bus},504 : bus{bus},
493 service{dbus::Service::add_service(bus, service_name())},505 /* Export MediaHub service interface on dbus */
506 service{dbus::Service::add_service(bus, "org.mpris.MediaPlayer2.MediaHub")},
494 object{service->add_object_for_path(dbus::types::ObjectPath{"/org/mpris/MediaPlayer2"})},507 object{service->add_object_for_path(dbus::types::ObjectPath{"/org/mpris/MediaPlayer2"})},
495 media_player{mpris::MediaPlayer2::Skeleton::Configuration{bus, object, media_player_defaults()}},508 media_player{mpris::MediaPlayer2::Skeleton::Configuration{bus, object, media_player_defaults()}},
496 player{mpris::Player::Skeleton::Configuration{bus, object, player_defaults()}},509 player{mpris::Player::Skeleton::Configuration{bus, object, player_defaults()}},
@@ -500,14 +513,15 @@
500 object->install_method_handler<core::dbus::interfaces::Properties::GetAll>([this](const core::dbus::Message::Ptr& msg)513 object->install_method_handler<core::dbus::interfaces::Properties::GetAll>([this](const core::dbus::Message::Ptr& msg)
501 {514 {
502 // Extract the interface515 // Extract the interface
503 std::string itf; msg->reader() >> itf;516 std::string interface;
517 msg->reader() >> interface;
504 core::dbus::Message::Ptr reply = core::dbus::Message::make_method_return(msg);518 core::dbus::Message::Ptr reply = core::dbus::Message::make_method_return(msg);
505519
506 if (itf == mpris::Player::name())520 if (interface == mpris::Player::name())
507 reply->writer() << player.get_all_properties();521 reply->writer() << player.get_all_properties();
508 else if (itf == mpris::MediaPlayer2::name())522 else if (interface == mpris::MediaPlayer2::name())
509 reply->writer() << media_player.get_all_properties();523 reply->writer() << media_player.get_all_properties();
510 else if (itf == mpris::Playlists::name())524 else if (interface == mpris::Playlists::name())
511 reply->writer() << playlists.get_all_properties();525 reply->writer() << playlists.get_all_properties();
512526
513 Exported::bus->send(reply);527 Exported::bus->send(reply);
@@ -516,9 +530,9 @@
516 // Setup method handlers for mpris::Player methods.530 // Setup method handlers for mpris::Player methods.
517 auto next = [this](const core::dbus::Message::Ptr& msg)531 auto next = [this](const core::dbus::Message::Ptr& msg)
518 {532 {
519 auto sp = current_player.lock();533 const auto sp = current_player.lock();
520534
521 if (sp)535 if (is_multimedia_role())
522 sp->next();536 sp->next();
523537
524 Exported::bus->send(core::dbus::Message::make_method_return(msg));538 Exported::bus->send(core::dbus::Message::make_method_return(msg));
@@ -527,9 +541,9 @@
527541
528 auto previous = [this](const core::dbus::Message::Ptr& msg)542 auto previous = [this](const core::dbus::Message::Ptr& msg)
529 {543 {
530 auto sp = current_player.lock();544 const auto sp = current_player.lock();
531545
532 if (sp)546 if (is_multimedia_role())
533 sp->previous();547 sp->previous();
534548
535 Exported::bus->send(core::dbus::Message::make_method_return(msg));549 Exported::bus->send(core::dbus::Message::make_method_return(msg));
@@ -538,9 +552,9 @@
538552
539 auto pause = [this](const core::dbus::Message::Ptr& msg)553 auto pause = [this](const core::dbus::Message::Ptr& msg)
540 {554 {
541 auto sp = current_player.lock();555 const auto sp = current_player.lock();
542556
543 if (sp)557 if (is_multimedia_role() and sp->can_pause())
544 sp->pause();558 sp->pause();
545559
546 Exported::bus->send(core::dbus::Message::make_method_return(msg));560 Exported::bus->send(core::dbus::Message::make_method_return(msg));
@@ -549,9 +563,9 @@
549563
550 auto stop = [this](const core::dbus::Message::Ptr& msg)564 auto stop = [this](const core::dbus::Message::Ptr& msg)
551 {565 {
552 auto sp = current_player.lock();566 const auto sp = current_player.lock();
553567
554 if (sp)568 if (is_multimedia_role())
555 sp->stop();569 sp->stop();
556570
557 Exported::bus->send(core::dbus::Message::make_method_return(msg));571 Exported::bus->send(core::dbus::Message::make_method_return(msg));
@@ -560,9 +574,9 @@
560574
561 auto play = [this](const core::dbus::Message::Ptr& msg)575 auto play = [this](const core::dbus::Message::Ptr& msg)
562 {576 {
563 auto sp = current_player.lock();577 const auto sp = current_player.lock();
564578
565 if (sp)579 if (is_multimedia_role() and sp->can_play())
566 sp->play();580 sp->play();
567581
568 Exported::bus->send(core::dbus::Message::make_method_return(msg));582 Exported::bus->send(core::dbus::Message::make_method_return(msg));
@@ -571,13 +585,15 @@
571585
572 auto play_pause = [this](const core::dbus::Message::Ptr& msg)586 auto play_pause = [this](const core::dbus::Message::Ptr& msg)
573 {587 {
574 auto sp = current_player.lock();588 const auto sp = current_player.lock();
575589
576 if (sp)590 if (is_multimedia_role())
577 {591 {
578 if (sp->playback_status() == media::Player::PlaybackStatus::playing)592 if (sp->playback_status() == media::Player::PlaybackStatus::playing
593 and sp->can_pause())
579 sp->pause();594 sp->pause();
580 else if (sp->playback_status() != media::Player::PlaybackStatus::null)595 else if (sp->playback_status() != media::Player::PlaybackStatus::null
596 and sp->can_play())
581 sp->play();597 sp->play();
582 }598 }
583599
@@ -586,94 +602,29 @@
586 object->install_method_handler<mpris::Player::PlayPause>(play_pause);602 object->install_method_handler<mpris::Player::PlayPause>(play_pause);
587 }603 }
588604
605 inline bool is_multimedia_role()
606 {
607 const auto sp = current_player.lock();
608
609 return (sp ? sp->audio_stream_role() == media::Player::AudioStreamRole::multimedia : false);
610 }
611
589 void set_current_player(const std::shared_ptr<media::Player>& cp)612 void set_current_player(const std::shared_ptr<media::Player>& cp)
590 {613 {
591 unset_current_player();614 std::cout << "*** " << __PRETTY_FUNCTION__ << std::endl;
592
593 // We will not keep the object alive.615 // We will not keep the object alive.
594 current_player = cp;616 current_player = cp;
595617
596 // And announce that we can be controlled again.618 // And announce that we can be controlled again.
597 player.properties.can_control->set(false);619 player.properties.can_control->set(true);
598
599 // We wire up player state changes
600 connections.seeked_to = cp->seeked_to().connect([this](std::uint64_t position)
601 {
602 player.signals.seeked_to->emit(position);
603 });
604
605 connections.duration_changed = cp->duration().changed().connect([this](std::uint64_t duration)
606 {
607 player.properties.duration->set(duration);
608 });
609
610 connections.position_changed = cp->position().changed().connect([this](std::uint64_t position)
611 {
612 player.properties.position->set(position);
613 });
614
615 connections.playback_status_changed = cp->playback_status().changed().connect([this](core::ubuntu::media::Player::PlaybackStatus status)
616 {
617 player.properties.playback_status->set(mpris::Player::PlaybackStatus::from(status));
618 });
619
620 connections.loop_status_changed = cp->loop_status().changed().connect([this](core::ubuntu::media::Player::LoopStatus status)
621 {
622 player.properties.loop_status->set(mpris::Player::LoopStatus::from(status));
623 });
624
625 connections.meta_data_changed = cp->meta_data_for_current_track().changed().connect([this](const core::ubuntu::media::Track::MetaData& md)
626 {
627 mpris::Player::Dictionary dict;
628
629 bool has_title = md.count(xesam::Title::name) > 0;
630 bool has_album_name = md.count(xesam::Album::name) > 0;
631 bool has_artist_name = md.count(xesam::Artist::name) > 0;
632
633 if (has_title)
634 dict[xesam::Title::name] = dbus::types::Variant::encode(md.get(xesam::Title::name));
635 if (has_album_name)
636 dict[xesam::Album::name] = dbus::types::Variant::encode(md.get(xesam::Album::name));
637 if (has_artist_name)
638 dict[xesam::Artist::name] = dbus::types::Variant::encode(md.get(xesam::Artist::name));
639
640 dict[mpris::metadata::ArtUrl::name] = dbus::types::Variant::encode(
641 cover_art_resolver(
642 has_title ? md.get(xesam::Title::name) : "",
643 has_album_name ? md.get(xesam::Album::name) : "",
644 has_artist_name ? md.get(xesam::Artist::name) : ""));
645
646 mpris::Player::Dictionary wrap;
647 wrap[mpris::Player::Properties::Metadata::name()] = dbus::types::Variant::encode(dict);
648
649 player.signals.properties_changed->emit(
650 std::make_tuple(
651 dbus::traits::Service<mpris::Player::Properties::Metadata::Interface>::interface_name(),
652 wrap,
653 std::vector<std::string>()));
654 });
655 }620 }
656621
657 void unset_current_player()622 void reset_current_player()
658 {623 {
624 std::cout << __PRETTY_FUNCTION__ << std::endl;
625 // And announce that we can no longer be controlled.
626 player.properties.can_control->set(false);
659 current_player.reset();627 current_player.reset();
660
661 // We disconnect all previous event connections.
662 connections.seeked_to.disconnect();
663 connections.duration_changed.disconnect();
664 connections.position_changed.disconnect();
665 connections.playback_status_changed.disconnect();
666 connections.loop_status_changed.disconnect();
667 connections.meta_data_changed.disconnect();
668
669 // And announce that we cannot be controlled anymore.
670 player.properties.can_control->set(false);
671 }
672
673 void unset_if_current(const std::shared_ptr<media::Player>& cp)
674 {
675 if (cp == current_player.lock())
676 unset_current_player();
677 }628 }
678629
679 dbus::Bus::Ptr bus;630 dbus::Bus::Ptr bus;
@@ -759,6 +710,14 @@
759 return d->configuration.impl->resume_session(key);710 return d->configuration.impl->resume_session(key);
760}711}
761712
713void media::ServiceSkeleton::set_current_player(media::Player::PlayerKey key)
714{
715 const auto player = d->configuration.player_store->player_for_key(key);
716 // We only care to allow the MPRIS controls to apply to multimedia player (i.e. audio, video)
717 if (player->audio_stream_role() == media::Player::AudioStreamRole::multimedia)
718 d->exported.set_current_player(player);
719}
720
762void media::ServiceSkeleton::pause_other_sessions(media::Player::PlayerKey key)721void media::ServiceSkeleton::pause_other_sessions(media::Player::PlayerKey key)
763{722{
764 d->configuration.impl->pause_other_sessions(key);723 d->configuration.impl->pause_other_sessions(key);
765724
=== modified file 'src/core/media/service_skeleton.h'
--- src/core/media/service_skeleton.h 2015-04-16 15:19:35 +0000
+++ src/core/media/service_skeleton.h 2015-09-09 16:32:06 +0000
@@ -59,6 +59,7 @@
59 void destroy_session(const std::string&, const media::Player::Configuration&);59 void destroy_session(const std::string&, const media::Player::Configuration&);
60 std::shared_ptr<Player> create_fixed_session(const std::string& name, const Player::Configuration&);60 std::shared_ptr<Player> create_fixed_session(const std::string& name, const Player::Configuration&);
61 std::shared_ptr<Player> resume_session(Player::PlayerKey);61 std::shared_ptr<Player> resume_session(Player::PlayerKey);
62 void set_current_player(Player::PlayerKey key);
62 void pause_other_sessions(Player::PlayerKey key);63 void pause_other_sessions(Player::PlayerKey key);
6364
64 void run();65 void run();
6566
=== modified file 'src/core/media/service_stub.cpp'
--- src/core/media/service_stub.cpp 2015-04-17 16:44:30 +0000
+++ src/core/media/service_stub.cpp 2015-09-09 16:32:06 +0000
@@ -139,9 +139,17 @@
139 });139 });
140}140}
141141
142void media::ServiceStub::set_current_player(Player::PlayerKey key)
143{
144 auto op = d->object->invoke_method_synchronously<mpris::Service::SetCurrentPlayer,
145 void>(key);
146
147 if (op.is_error())
148 throw std::runtime_error("Problem setting current player: " + op.error());
149}
150
142void media::ServiceStub::pause_other_sessions(media::Player::PlayerKey key)151void media::ServiceStub::pause_other_sessions(media::Player::PlayerKey key)
143{152{
144 std::cout << __PRETTY_FUNCTION__ << std::endl;
145 auto op = d->object->invoke_method_synchronously<mpris::Service::PauseOtherSessions,153 auto op = d->object->invoke_method_synchronously<mpris::Service::PauseOtherSessions,
146 void>(key);154 void>(key);
147155
148156
=== modified file 'src/core/media/service_stub.h'
--- src/core/media/service_stub.h 2015-04-10 16:13:55 +0000
+++ src/core/media/service_stub.h 2015-09-09 16:32:06 +0000
@@ -45,6 +45,7 @@
45 void destroy_session(const std::string& uuid, const Player::Configuration&);45 void destroy_session(const std::string& uuid, const Player::Configuration&);
46 std::shared_ptr<Player> create_fixed_session(const std::string& name, const Player::Configuration&);46 std::shared_ptr<Player> create_fixed_session(const std::string& name, const Player::Configuration&);
47 std::shared_ptr<Player> resume_session(Player::PlayerKey key);47 std::shared_ptr<Player> resume_session(Player::PlayerKey key);
48 void set_current_player(Player::PlayerKey key);
48 void pause_other_sessions(Player::PlayerKey key);49 void pause_other_sessions(Player::PlayerKey key);
4950
50 private:51 private:
5152
=== modified file 'src/core/media/track_list_implementation.cpp'
--- src/core/media/track_list_implementation.cpp 2015-08-11 15:25:50 +0000
+++ src/core/media/track_list_implementation.cpp 2015-09-09 16:32:06 +0000
@@ -215,8 +215,6 @@
215215
216void media::TrackListImplementation::reset()216void media::TrackListImplementation::reset()
217{217{
218 std::cout << __PRETTY_FUNCTION__ << std::endl;
219
220 // Make sure playback stops218 // Make sure playback stops
221 on_end_of_tracklist()();219 on_end_of_tracklist()();
222220
223221
=== modified file 'src/core/media/track_list_skeleton.cpp'
--- src/core/media/track_list_skeleton.cpp 2015-08-11 15:25:50 +0000
+++ src/core/media/track_list_skeleton.cpp 2015-09-09 16:32:06 +0000
@@ -521,7 +521,6 @@
521521
522void media::TrackListSkeleton::reset()522void media::TrackListSkeleton::reset()
523{523{
524 std::cout << __PRETTY_FUNCTION__ << std::endl;
525 d->current_track = d->empty_iterator;524 d->current_track = d->empty_iterator;
526}525}
527526

Subscribers

People subscribed via source and target branches

to all changes: