Pause spotify track (issue 2503)
(patch slightly modified, not sure why it wasn't applied before: it looks good to me)
This commit is contained in:
parent
631c120515
commit
cbc6e5cf4d
@ -292,6 +292,8 @@ void SpotifyClient::MessageArrived(const pb::spotify::Message& message) {
|
||||
SetPlaybackSettings(message.set_playback_settings_request());
|
||||
} else if (message.has_browse_toplist_request()) {
|
||||
BrowseToplist(message.browse_toplist_request());
|
||||
} else if (message.has_pause_request()) {
|
||||
SetPaused(message.pause_request());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1017,6 +1019,10 @@ void SpotifyClient::BrowseToplist(
|
||||
pending_toplist_browses_[browse] = req;
|
||||
}
|
||||
|
||||
void SpotifyClient::SetPaused(const pb::spotify::PauseRequest& req) {
|
||||
sp_session_player_play(session_, !req.paused());
|
||||
}
|
||||
|
||||
void SpotifyClient::ToplistBrowseComplete(sp_toplistbrowse* result,
|
||||
void* userdata) {
|
||||
SpotifyClient* me = reinterpret_cast<SpotifyClient*>(userdata);
|
||||
|
@ -128,6 +128,7 @@ class SpotifyClient : public AbstractMessageHandler<pb::spotify::Message> {
|
||||
void BrowseAlbum(const QString& uri);
|
||||
void BrowseToplist(const pb::spotify::BrowseToplistRequest& req);
|
||||
void SetPlaybackSettings(const pb::spotify::PlaybackSettings& req);
|
||||
void SetPaused(const pb::spotify::PauseRequest& req);
|
||||
|
||||
void SendPlaylistList();
|
||||
|
||||
|
@ -184,6 +184,10 @@ message PlaybackSettings {
|
||||
optional bool volume_normalisation = 2 [default = false];
|
||||
}
|
||||
|
||||
message PauseRequest {
|
||||
optional bool paused = 1 [default = false];
|
||||
}
|
||||
|
||||
// NEXT_ID: 21
|
||||
message Message {
|
||||
// Not currently used
|
||||
@ -208,4 +212,5 @@ message Message {
|
||||
optional PlaybackSettings set_playback_settings_request = 17;
|
||||
optional BrowseToplistRequest browse_toplist_request = 19;
|
||||
optional BrowseToplistResponse browse_toplist_response = 20;
|
||||
optional PauseRequest pause_request = 21;
|
||||
}
|
||||
|
@ -917,6 +917,23 @@ GstState GstEnginePipeline::state() const {
|
||||
}
|
||||
|
||||
QFuture<GstStateChangeReturn> GstEnginePipeline::SetState(GstState state) {
|
||||
if (url_.scheme() == "spotify" && !buffering_) {
|
||||
const GstState current_state = this->state();
|
||||
|
||||
if (state == GST_STATE_PAUSED && current_state == GST_STATE_PLAYING) {
|
||||
SpotifyService* spotify = InternetModel::Service<SpotifyService>();
|
||||
|
||||
// Need to schedule this in the spotify service's thread
|
||||
QMetaObject::invokeMethod(spotify, "SetPaused", Qt::QueuedConnection,
|
||||
Q_ARG(bool, true));
|
||||
} else if (state == GST_STATE_PLAYING && current_state == GST_STATE_PAUSED) {
|
||||
SpotifyService* spotify = InternetModel::Service<SpotifyService>();
|
||||
|
||||
// Need to schedule this in the spotify service's thread
|
||||
QMetaObject::invokeMethod(spotify, "SetPaused", Qt::QueuedConnection,
|
||||
Q_ARG(bool, false));
|
||||
}
|
||||
}
|
||||
return ConcurrentRun::Run<GstStateChangeReturn, GstElement*, GstState>(
|
||||
&set_state_threadpool_, &gst_element_set_state, pipeline_, state);
|
||||
}
|
||||
|
@ -265,3 +265,10 @@ void SpotifyServer::LoadToplist() {
|
||||
|
||||
SendOrQueueMessage(message);
|
||||
}
|
||||
|
||||
void SpotifyServer::SetPaused(const bool paused) {
|
||||
pb::spotify::Message message;
|
||||
pb::spotify::PauseRequest* req = message.mutable_pause_request();
|
||||
req->set_paused(paused);
|
||||
SendOrQueueMessage(message);
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ class SpotifyServer : public AbstractMessageHandler<pb::spotify::Message> {
|
||||
void SetPlaybackSettings(pb::spotify::Bitrate bitrate,
|
||||
bool volume_normalisation);
|
||||
void LoadToplist();
|
||||
void SetPaused(const bool paused);
|
||||
|
||||
int server_port() const;
|
||||
|
||||
|
@ -529,7 +529,7 @@ void SpotifyService::SongFromProtobuf(const pb::spotify::Track& track,
|
||||
}
|
||||
|
||||
PlaylistItem::Options SpotifyService::playlistitem_options() const {
|
||||
return PlaylistItem::PauseDisabled | PlaylistItem::SeekDisabled;
|
||||
return PlaylistItem::SeekDisabled;
|
||||
}
|
||||
|
||||
QWidget* SpotifyService::HeaderWidget() const {
|
||||
@ -697,6 +697,11 @@ void SpotifyService::LoadImage(const QString& id) {
|
||||
server_->LoadImage(id);
|
||||
}
|
||||
|
||||
void SpotifyService::SetPaused(const bool paused) {
|
||||
EnsureServerCreated();
|
||||
server_->SetPaused(paused);
|
||||
}
|
||||
|
||||
void SpotifyService::SyncPlaylistProgress(
|
||||
const pb::spotify::SyncPlaylistProgress& progress) {
|
||||
qLog(Debug) << "Sync progress:" << progress.sync_progress();
|
||||
|
@ -59,6 +59,7 @@ class SpotifyService : public InternetService {
|
||||
void Logout();
|
||||
void Login(const QString& username, const QString& password);
|
||||
Q_INVOKABLE void LoadImage(const QString& id);
|
||||
Q_INVOKABLE void SetPaused(const bool paused);
|
||||
|
||||
SpotifyServer* server() const;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user