Fix Clementine getting stuck when transitioning from a local track to a Spotify track with crossfade disabled.

Two problems here:
- the first was that "StartPlaybackLater" wasn't called from the thread which created SpotifyServer, so the timer never started.
- then the playback sometimes failed or started with an offset: just hack to ignore sourcedrained signal in this case.
This commit is contained in:
Arnaud Bienner 2015-11-03 23:20:44 +01:00
parent a7ae275153
commit d9150ec165
3 changed files with 14 additions and 13 deletions

View File

@ -174,8 +174,12 @@ bool GstEnginePipeline::ReplaceDecodeBin(const QUrl& url) {
gst_object_unref(GST_OBJECT(pad));
// Tell spotify to start sending data to us.
InternetModel::Service<SpotifyService>()->server()->StartPlaybackLater(
url.toString(), port);
SpotifyServer* spotify_server = InternetModel::Service<SpotifyService>()->server();
// Need to schedule this in the spotify server's thread
QMetaObject::invokeMethod(spotify_server, "StartPlayback",
Qt::QueuedConnection,
Q_ARG(QString, url.toString()),
Q_ARG(quint16, port));
} else {
new_bin = engine_->CreateElement("uridecodebin");
g_object_set(G_OBJECT(new_bin), "uri", url.toEncoded().constData(),
@ -920,7 +924,14 @@ void GstEnginePipeline::SourceDrainedCallback(GstURIDecodeBin* bin,
gpointer self) {
GstEnginePipeline* instance = reinterpret_cast<GstEnginePipeline*>(self);
if (instance->has_next_valid_url()) {
if (instance->has_next_valid_url() &&
// I'm not sure why, but calling this when previous track is a local song
// and the next track is a Spotify song is buggy: the Spotify song will
// not start or with some offset. So just do nothing here: when the song
// finished, EndOfStreamReached/TrackEnded will be emitted anyway so
// NextItem will be called.
!(instance->url_.scheme() != "spotify" &&
instance->next_url_.scheme() == "spotify")) {
instance->TransitionToNext();
}
}

View File

@ -260,15 +260,6 @@ void SpotifyServer::RemoveSongsFromPlaylist(
SendOrQueueMessage(message);
}
void SpotifyServer::StartPlaybackLater(const QString& uri, quint16 port) {
QTimer* timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), timer, SLOT(deleteLater()));
timer->start(100); // lol
NewClosure(timer, SIGNAL(timeout()), this,
SLOT(StartPlayback(QString, quint16)), uri, port);
}
void SpotifyServer::StartPlayback(const QString& uri, quint16 port) {
pb::spotify::Message message;
pb::spotify::PlaybackRequest* req = message.mutable_playback_request();

View File

@ -53,7 +53,6 @@ class SpotifyServer : public AbstractMessageHandler<pb::spotify::Message> {
void RemoveSongsFromUserPlaylist(int playlist_index,
const QList<int>& songs_indices_to_remove);
void RemoveSongsFromStarred(const QList<int>& songs_indices_to_remove);
void StartPlaybackLater(const QString& uri, quint16 port);
void Search(const QString& text, int limit, int limit_album = 0);
void LoadImage(const QString& id);
void AlbumBrowse(const QString& uri);