17
17
* Jim Hodapp <jim.hodapp@canonical.com>
20
#include <core/media/service.h>
20
22
#include "player_implementation.h"
23
#include "service_skeleton.h"
21
24
#include "util/timeout.h"
23
26
#include <unistd.h>
304
void update_mpris_properties(void)
307
void update_mpris_properties()
306
bool has_previous = track_list->has_previous()
309
const bool has_previous = track_list->has_previous()
307
310
or parent->Parent::loop_status() != Player::LoopStatus::none;
308
bool has_next = track_list->has_next()
311
const bool has_next = track_list->has_next()
309
312
or parent->Parent::loop_status() != Player::LoopStatus::none;
310
auto n_tracks = track_list->tracks()->size();
311
bool has_tracks = (n_tracks > 0) ? true : false;
313
const auto n_tracks = track_list->tracks()->size();
314
const bool has_tracks = (n_tracks > 0) ? true : false;
313
316
MH_INFO("Updating MPRIS TrackList properties:");
314
317
MH_INFO("\tTracks: %d", n_tracks);
322
325
parent->can_go_next().set(has_next);
328
bool pause_other_players(media::Player::PlayerKey key)
330
if (not config.parent.player_service)
333
media::ServiceSkeleton* skel {
334
reinterpret_cast<media::ServiceSkeleton*>(config.parent.player_service)
336
skel->pause_other_sessions(key);
340
bool update_current_player(media::Player::PlayerKey key)
342
if (not config.parent.player_service)
345
media::ServiceSkeleton* skel {
346
reinterpret_cast<media::ServiceSkeleton*>(config.parent.player_service)
348
skel->set_current_player(key);
352
bool is_current_player() const
354
if (not config.parent.player_service)
357
media::ServiceSkeleton* skel {
358
reinterpret_cast<media::ServiceSkeleton*>(config.parent.player_service)
360
return skel->is_current_player(parent->key());
363
bool is_multimedia_role() const
365
return parent->audio_stream_role() == media::Player::AudioStreamRole::multimedia;
368
bool reset_current_player()
370
if (not config.parent.player_service)
373
media::ServiceSkeleton* skel {
374
reinterpret_cast<media::ServiceSkeleton*>(config.parent.player_service)
376
skel->reset_current_player();
325
380
// Our link back to our parent.
326
381
media::PlayerImplementation<Parent>* parent;
327
382
// We just store the parameters passed on construction.
479
534
d->clear_wakelocks();
480
535
d->track_list->reset();
537
// This is not a fatal error but merely a warning that should
539
if (d->is_multimedia_role() and d->is_current_player())
541
MH_DEBUG("==== Resetting current player");
542
if (not d->reset_current_player())
543
MH_WARNING("Failed to reset current player");
481
546
// And tell the outside world that the client has gone away
482
547
d->on_client_disconnected();
697
763
// Don't set new track as the current track to play since we're calling open_resource_for_uri above
698
764
static const bool make_current = false;
699
765
d->track_list->add_track_with_uri_at(uri, media::TrackList::after_empty_track(), make_current);
722
789
void media::PlayerImplementation<Parent>::play()
792
if (d->is_multimedia_role())
794
MH_DEBUG("==== Pausing all other multimedia player sessions");
795
if (not d->pause_other_players(d->config.key))
796
MH_WARNING("Failed to pause other player sessions");
798
MH_DEBUG("==== Updating the current player");
799
// This player will begin playing so make sure it's the current player. If
800
// this operation fails it is not a fatal condition but should be logged
801
if (not d->update_current_player(d->config.key))
802
MH_WARNING("Failed to update current player");
725
805
d->engine->play();