mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2025-02-03 02:47:36 +01:00
Add error handling/message for url handler
This commit is contained in:
parent
a9304a840f
commit
c91cef3507
@ -235,6 +235,12 @@ void Player::HandleLoadResult(const UrlHandler::LoadResult &result) {
|
||||
if (item->Url() != result.original_url_) return;
|
||||
|
||||
switch (result.type_) {
|
||||
case UrlHandler::LoadResult::Error:
|
||||
loading_async_ = QUrl();
|
||||
EngineStateChanged(Engine::Error);
|
||||
FatalError();
|
||||
emit Error(result.error_);
|
||||
break;
|
||||
case UrlHandler::LoadResult::NoMoreTracks:
|
||||
qLog(Debug) << "URL handler for" << result.original_url_ << "said no more tracks";
|
||||
|
||||
@ -703,13 +709,17 @@ void Player::TrackAboutToEnd() {
|
||||
if (url_handlers_.contains(url.scheme()) && !(engine_->type() == Engine::Deezer && url.scheme() == "dzmedia")) {
|
||||
UrlHandler::LoadResult result = url_handlers_[url.scheme()]->LoadNext(url);
|
||||
switch (result.type_) {
|
||||
case UrlHandler::LoadResult::Error:
|
||||
loading_async_ = QUrl();
|
||||
EngineStateChanged(Engine::Error);
|
||||
FatalError();
|
||||
emit Error(result.error_);
|
||||
return;
|
||||
case UrlHandler::LoadResult::NoMoreTracks:
|
||||
return;
|
||||
|
||||
case UrlHandler::LoadResult::WillLoadAsynchronously:
|
||||
loading_async_ = url;
|
||||
return;
|
||||
|
||||
case UrlHandler::LoadResult::TrackAvailable:
|
||||
url = result.media_url_;
|
||||
break;
|
||||
|
@ -28,6 +28,6 @@
|
||||
#include "song.h"
|
||||
#include "urlhandler.h"
|
||||
|
||||
UrlHandler::LoadResult::LoadResult(const QUrl &original_url, Type type, const QUrl &media_url, const Song::FileType &filetype, qint64 length_nanosec) : original_url_(original_url), type_(type), media_url_(media_url), filetype_(filetype), length_nanosec_(length_nanosec) {}
|
||||
UrlHandler::LoadResult::LoadResult(const QUrl &original_url, Type type, const QUrl &media_url, const Song::FileType &filetype, const qint64 length_nanosec, const QString error) : original_url_(original_url), type_(type), media_url_(media_url), filetype_(filetype), length_nanosec_(length_nanosec), error_(error) {}
|
||||
|
||||
UrlHandler::UrlHandler(QObject *parent) : QObject(parent) {}
|
||||
|
@ -52,9 +52,12 @@ class UrlHandler : public QObject {
|
||||
|
||||
// There was a track available. Its url is in media_url.
|
||||
TrackAvailable,
|
||||
|
||||
// There was a error
|
||||
Error,
|
||||
};
|
||||
|
||||
LoadResult(const QUrl &original_url = QUrl(), Type type = NoMoreTracks, const QUrl &media_url = QUrl(), const Song::FileType &filetype = Song::FileType_Stream, qint64 length_nanosec_ = -1);
|
||||
LoadResult(const QUrl &original_url = QUrl(), Type type = NoMoreTracks, const QUrl &media_url = QUrl(), const Song::FileType &filetype = Song::FileType_Stream, const qint64 length_nanosec_ = -1, const QString error = QString());
|
||||
|
||||
// The url that the playlist item has in Url().
|
||||
// Might be something unplayable like lastfm://...
|
||||
@ -70,6 +73,9 @@ class UrlHandler : public QObject {
|
||||
|
||||
// Track length, if we are able to get it only now
|
||||
qint64 length_nanosec_;
|
||||
|
||||
// Error message, if any
|
||||
QString error_;
|
||||
};
|
||||
|
||||
// Called by the Player when a song starts loading - gives the handler a chance to do something clever to get a playable track.
|
||||
|
@ -911,7 +911,7 @@ void TidalService::Error(QString error, QVariant debug) {
|
||||
CheckFinish();
|
||||
}
|
||||
if (!stream_request_url_.isEmpty() && !login_sent_) {
|
||||
emit StreamURLFinished(stream_request_url_, Song::FileType_Stream);
|
||||
emit StreamURLFinished(stream_request_url_, Song::FileType_Stream, error);
|
||||
stream_request_url_ = QUrl();
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ class TidalService : public InternetService {
|
||||
void ProgressSetMaximum(int max);
|
||||
void UpdateProgress(int max);
|
||||
void GetStreamURLFinished(QNetworkReply *reply, const QUrl url);
|
||||
void StreamURLFinished(const QUrl url, const Song::FileType);
|
||||
void StreamURLFinished(const QUrl url, const Song::FileType, QString error = QString());
|
||||
|
||||
public slots:
|
||||
void ShowConfig();
|
||||
|
@ -33,7 +33,7 @@ TidalUrlHandler::TidalUrlHandler(
|
||||
Application *app, TidalService *service)
|
||||
: UrlHandler(service), app_(app), service_(service), task_id_(-1) {
|
||||
|
||||
connect(service, SIGNAL(StreamURLFinished(QUrl, Song::FileType)), this, SLOT(GetStreamURLFinished(QUrl, Song::FileType)));
|
||||
connect(service, SIGNAL(StreamURLFinished(QUrl, Song::FileType, QString)), this, SLOT(GetStreamURLFinished(QUrl, Song::FileType, QString)));
|
||||
|
||||
}
|
||||
|
||||
@ -49,11 +49,14 @@ UrlHandler::LoadResult TidalUrlHandler::StartLoading(const QUrl &url) {
|
||||
|
||||
}
|
||||
|
||||
void TidalUrlHandler::GetStreamURLFinished(QUrl url, Song::FileType filetype) {
|
||||
void TidalUrlHandler::GetStreamURLFinished(QUrl url, Song::FileType filetype, QString error) {
|
||||
|
||||
if (task_id_ == -1) return;
|
||||
CancelTask();
|
||||
emit AsyncLoadComplete(LoadResult(last_original_url_, LoadResult::TrackAvailable, url, filetype));
|
||||
if (error.isEmpty())
|
||||
emit AsyncLoadComplete(LoadResult(last_original_url_, LoadResult::TrackAvailable, url, filetype));
|
||||
else
|
||||
emit AsyncLoadComplete(LoadResult(last_original_url_, LoadResult::Error, url, filetype, -1, error));
|
||||
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ class TidalUrlHandler : public UrlHandler {
|
||||
void CancelTask();
|
||||
|
||||
private slots:
|
||||
void GetStreamURLFinished(QUrl url, Song::FileType filetype);
|
||||
void GetStreamURLFinished(QUrl url, Song::FileType filetype, QString error = QString());
|
||||
|
||||
private:
|
||||
Application *app_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user