57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <giomm.h>
|
|
#include <sigc++/sigc++.h>
|
|
#include <vector>
|
|
#include "services/dbus/messages.hpp"
|
|
|
|
class MprisController {
|
|
public:
|
|
struct PlayerState {
|
|
std::string title;
|
|
std::vector<std::string> artist;
|
|
std::string artwork_url;
|
|
int64_t length_ms;
|
|
};
|
|
enum class PlaybackStatus {
|
|
Playing,
|
|
Paused,
|
|
Stopped,
|
|
};
|
|
|
|
static std::shared_ptr<MprisController> getInstance();
|
|
|
|
void toggle_play();
|
|
void next_song();
|
|
void previous_song();
|
|
void emit_seeked(int64_t position_us);
|
|
|
|
sigc::signal<void(const MprisPlayer2Message &)> &signal_mpris_updated();
|
|
sigc::signal<void(PlaybackStatus)> &signal_playback_status_changed();
|
|
sigc::signal<void(int64_t)> &signal_playback_position_changed();
|
|
|
|
private:
|
|
MprisController();
|
|
std::map<std::string, PlaybackStatus> playbackStatusMap = {
|
|
{"Playing", PlaybackStatus::Playing},
|
|
{"Paused", PlaybackStatus::Paused},
|
|
{"Stopped", PlaybackStatus::Stopped},
|
|
};
|
|
|
|
PlaybackStatus currentPlaybackStatus = PlaybackStatus::Stopped;
|
|
|
|
Glib::RefPtr<Gio::DBus::Connection> m_connection;
|
|
Glib::RefPtr<Gio::DBus::Proxy> m_proxy;
|
|
|
|
sigc::signal<void(const MprisPlayer2Message &)> mprisUpdatedSignal;
|
|
sigc::signal<void(PlaybackStatus)> playbackStatusChangedSignal;
|
|
sigc::signal<void(int64_t)> playbackPositionChangedSignal;
|
|
|
|
void on_bus_connected(const Glib::RefPtr<Gio::AsyncResult> &result);
|
|
void signalNotification();
|
|
|
|
// Called when the song changes
|
|
void on_properties_changed(const Gio::DBus::Proxy::MapChangedProperties &changed_properties,
|
|
const std::vector<Glib::ustring> &invalidated_properties);
|
|
}; |