mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-17 04:20:47 +00:00
Added notification from server -> client if playback time is changed by
the user.
This commit is contained in:
parent
a40fea7b21
commit
d7cbec1058
@ -353,6 +353,10 @@ void PlaybackService::ProcessMessage(IMessage &message) {
|
||||
}
|
||||
else if (type == MESSAGE_TIME_CHANGED) {
|
||||
this->TimeChanged(transport.Position());
|
||||
double volume = transport.Volume();
|
||||
for (auto remote : this->remotes) {
|
||||
remote->OnPlaybackTimeChanged(transport.Position());
|
||||
}
|
||||
}
|
||||
else if (type == MESSAGE_NOTIFY_EDITED ||
|
||||
type == MESSAGE_NOTIFY_RESET)
|
||||
|
@ -45,6 +45,7 @@ namespace musik { namespace core { namespace sdk {
|
||||
virtual void SetPlaybackService(IPlaybackService* playback) = 0;
|
||||
virtual void OnTrackChanged(ITrack* track) = 0;
|
||||
virtual void OnPlaybackStateChanged(PlaybackState state) = 0;
|
||||
virtual void OnPlaybackTimeChanged(double time) = 0;
|
||||
virtual void OnVolumeChanged(double volume) = 0;
|
||||
virtual void OnModeChanged(RepeatMode repeatMode, bool shuffled) = 0;
|
||||
virtual void OnPlayQueueChanged() = 0;
|
||||
|
@ -137,6 +137,7 @@ namespace request {
|
||||
static const std::string seek_relative = "seek_relative";
|
||||
static const std::string toggle_mute = "toggle_mute";
|
||||
static const std::string get_playback_overview = "get_playback_overview";
|
||||
static const std::string get_current_time = "get_current_time";
|
||||
static const std::string query_category = "query_category";
|
||||
static const std::string query_tracks = "query_tracks";
|
||||
static const std::string query_albums = "query_albums";
|
||||
|
@ -142,6 +142,10 @@ void WebSocketServer::OnPlaybackStateChanged(PlaybackState state) {
|
||||
this->BroadcastPlaybackOverview();
|
||||
}
|
||||
|
||||
void WebSocketServer::OnPlaybackTimeChanged(double time) {
|
||||
this->BroadcastPlaybackOverview();
|
||||
}
|
||||
|
||||
void WebSocketServer::OnVolumeChanged(double volume) {
|
||||
this->BroadcastPlaybackOverview();
|
||||
}
|
||||
@ -320,6 +324,11 @@ void WebSocketServer::HandleRequest(connection_hdl connection, json& request) {
|
||||
}
|
||||
else if (name == request::get_environment) {
|
||||
this->RespondWithEnvironment(connection, request);
|
||||
return;
|
||||
}
|
||||
else if (name == request::get_current_time) {
|
||||
this->RespondWithCurrentTime(connection, request);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -752,6 +761,15 @@ void WebSocketServer::RespondWithEnvironment(connection_hdl connection, json& re
|
||||
});
|
||||
}
|
||||
|
||||
void WebSocketServer::RespondWithCurrentTime(connection_hdl connection, json& request) {
|
||||
auto track = context.playback->GetPlayingTrack();
|
||||
|
||||
this->RespondWithOptions(connection, request, {
|
||||
{ key::playing_current_time, context.playback->GetPosition() },
|
||||
{ key::id, track ? track->GetId() : -1 }
|
||||
});
|
||||
}
|
||||
|
||||
void WebSocketServer::BroadcastPlaybackOverview() {
|
||||
{
|
||||
auto rl = connectionLock.Read();
|
||||
|
@ -58,6 +58,7 @@ class WebSocketServer {
|
||||
|
||||
void OnTrackChanged(musik::core::sdk::ITrack* track);
|
||||
void OnPlaybackStateChanged(musik::core::sdk::PlaybackState state);
|
||||
void OnPlaybackTimeChanged(double time);
|
||||
void OnVolumeChanged(double volume);
|
||||
void OnModeChanged(musik::core::sdk::RepeatMode repeatMode, bool shuffled);
|
||||
void OnPlayQueueChanged();
|
||||
@ -123,30 +124,33 @@ class WebSocketServer {
|
||||
void ThreadProc();
|
||||
void HandleAuthentication(connection_hdl connection, json& request);
|
||||
void HandleRequest(connection_hdl connection, json& request);
|
||||
|
||||
void Broadcast(const std::string& name, json& options);
|
||||
void RespondWithOptions(connection_hdl connection, json& request, json& options);
|
||||
void RespondWithOptions(connection_hdl connection, json& request, json&& options = json({}));
|
||||
void RespondWithSetVolume(connection_hdl connection, json& request);
|
||||
void RespondWithPlaybackOverview(connection_hdl connection, json& reuest);
|
||||
bool RespondWithTracks(connection_hdl connection, json& request, ITrackList* tracks, int limit, int offset);
|
||||
void GetLimitAndOffset(json& options, int& limit, int& offset);
|
||||
void RespondWithQueryTracks(connection_hdl connection, json& request);
|
||||
void RespondWithPlayQueueTracks(connection_hdl connection, json& request);
|
||||
void RespondWithQueryAlbums(connection_hdl connection, json& request);
|
||||
void RespondWithPlayTracks(connection_hdl connection, json& request);
|
||||
|
||||
void RespondWithInvalidRequest(connection_hdl connection, const std::string& name, const std::string& id);
|
||||
void RespondWithSuccess(connection_hdl connection, json& request);
|
||||
void RespondWithFailure(connection_hdl connection, json& request);
|
||||
void RespondWithSuccess(connection_hdl connection, const std::string& name, const std::string& id);
|
||||
|
||||
void RespondWithSetVolume(connection_hdl connection, json& request);
|
||||
void RespondWithPlaybackOverview(connection_hdl connection, json& reuest);
|
||||
bool RespondWithTracks(connection_hdl connection, json& request, ITrackList* tracks, int limit, int offset);
|
||||
void RespondWithQueryTracks(connection_hdl connection, json& request);
|
||||
void RespondWithPlayQueueTracks(connection_hdl connection, json& request);
|
||||
void RespondWithQueryAlbums(connection_hdl connection, json& request);
|
||||
void RespondWithPlayTracks(connection_hdl connection, json& request);
|
||||
void RespondWithQueryTracksByCategory(connection_hdl connection, json& request);
|
||||
void RespondWithQueryCategory(connection_hdl connection, json& request);
|
||||
void RespondWithPlayAllTracks(connection_hdl connection, json& request);
|
||||
void RespondWithPlayTracksByCategory(connection_hdl connection, json& request);
|
||||
void RespondWithEnvironment(connection_hdl connection, json& request);
|
||||
void RespondWithCurrentTime(connection_hdl connection, json& request);
|
||||
|
||||
void BroadcastPlaybackOverview();
|
||||
void BroadcastPlayQueueChanged();
|
||||
|
||||
void GetLimitAndOffset(json& options, int& limit, int& offset);
|
||||
ITrackList* QueryTracksByCategory(json& request, int& limit, int& offset);
|
||||
json ReadTrackMetadata(IRetainedTrack* track);
|
||||
void BuildPlaybackOverview(json& options);
|
||||
|
@ -104,6 +104,10 @@ static class PlaybackRemote : public IPlaybackRemote {
|
||||
webSocketServer.OnVolumeChanged(volume);
|
||||
}
|
||||
|
||||
virtual void OnPlaybackTimeChanged(double time) {
|
||||
webSocketServer.OnPlaybackTimeChanged(time);
|
||||
}
|
||||
|
||||
virtual void OnModeChanged(RepeatMode repeatMode, bool shuffled) {
|
||||
webSocketServer.OnModeChanged(repeatMode, shuffled);
|
||||
}
|
||||
|
@ -208,6 +208,10 @@ class MMShellHook:
|
||||
|
||||
}
|
||||
|
||||
virtual void OnPlaybackTimeChanged(double time) {
|
||||
|
||||
}
|
||||
|
||||
virtual void OnVolumeChanged(double volume) {
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user