diff --git a/src/devices/cddadevice.h b/src/devices/cddadevice.h index 60b0e1a20..5ebfdb916 100644 --- a/src/devices/cddadevice.h +++ b/src/devices/cddadevice.h @@ -45,6 +45,17 @@ class CddaDevice : public ConnectedDevice { static QStringList url_schemes() { return QStringList() << "cdda"; } + // QUrl interprets a single number as an ip address, so the QString cdda://1 + // would become the QUrl cdda://0.0.0.1. For this reason, we append a single + // character to strings when converting to URLs and strip that character + // when doing the reverse conversion. + static QUrl TrackStrToUrl(const QString& name) { return QUrl(name + "a"); } + static QString TrackUrlToStr(const QUrl& url) { + QString str = url.toString(); + str.remove(str.lastIndexOf(QChar('a')), 1); + return str; + } + signals: void SongsDiscovered(const SongList& songs); diff --git a/src/devices/cddasongloader.cpp b/src/devices/cddasongloader.cpp index 7b92c5d07..cb43b3e74 100644 --- a/src/devices/cddasongloader.cpp +++ b/src/devices/cddasongloader.cpp @@ -23,6 +23,7 @@ #include "core/logging.h" #include "core/timeconstants.h" +#include "cddadevice.h" #include "cddasongloader.h" CddaSongLoader::CddaSongLoader(const QUrl& url, QObject* parent) @@ -36,11 +37,13 @@ CddaSongLoader::~CddaSongLoader() { } QUrl CddaSongLoader::GetUrlFromTrack(int track_number) const { + QString track; if (url_.isEmpty()) { - return QUrl(QString("cdda://%1a").arg(track_number)); + track = QString("cdda://%1").arg(track_number); } else { - return QUrl(QString("cdda://%1/%2").arg(url_.path()).arg(track_number)); + track = QString("cdda://%1/%2").arg(url_.path()).arg(track_number); } + return CddaDevice::TrackStrToUrl(track); } void CddaSongLoader::LoadSongs() { diff --git a/src/engines/gstenginepipeline.cpp b/src/engines/gstenginepipeline.cpp index 79ac73217..15f4ca143 100644 --- a/src/engines/gstenginepipeline.cpp +++ b/src/engines/gstenginepipeline.cpp @@ -34,6 +34,7 @@ #include "core/mac_startup.h" #include "core/signalchecker.h" #include "core/utilities.h" +#include "devices/cddadevice.h" #include "internet/core/internetmodel.h" #ifdef HAVE_SPOTIFY # include "internet/spotify/spotifyserver.h" @@ -203,9 +204,7 @@ GstElement* GstEnginePipeline::CreateDecodeBinFromUrl(const QUrl& url) { #endif QByteArray uri; if (url.scheme() == "cdda") { - QString str = url.toString(); - str.remove(str.lastIndexOf(QChar('a')), 1); - uri = str.toUtf8(); + uri = CddaDevice::TrackUrlToStr(url).toUtf8(); } else { uri = Utilities::GetUriForGstreamer(url); }