strawberry-audio-player-win.../src/core/urlhandler.h

99 lines
3.0 KiB
C
Raw Normal View History

2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
2018-09-21 01:12:21 +02:00
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
2018-02-27 18:06:05 +01:00
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Strawberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
2018-08-09 18:39:44 +02:00
*
2018-02-27 18:06:05 +01:00
*/
#ifndef URLHANDLER_H
#define URLHANDLER_H
#include "config.h"
#include <QtGlobal>
2018-02-27 18:06:05 +01:00
#include <QObject>
#include <QString>
2018-02-27 18:06:05 +01:00
#include <QUrl>
2018-09-20 22:13:30 +02:00
#include "song.h"
2018-02-27 18:06:05 +01:00
class UrlHandler : public QObject {
Q_OBJECT
public:
explicit UrlHandler(QObject *parent = nullptr);
// The URL scheme that this handler handles.
virtual QString scheme() const = 0;
// Returned by StartLoading() and LoadNext(), indicates what the player should do when it wants to load a URL.
2018-02-27 18:06:05 +01:00
struct LoadResult {
enum Type {
// There wasn't a track available, and the player should move on to the next playlist item.
2018-02-27 18:06:05 +01:00
NoMoreTracks,
// There might be another track available but the handler needs to do some work (eg. fetching a remote playlist) to find out.
// AsyncLoadComplete will be emitted later with the same original_url.
2018-02-27 18:06:05 +01:00
WillLoadAsynchronously,
// There was a track available. Its url is in stream_url.
2018-02-27 18:06:05 +01:00
TrackAvailable,
// There was a error
Error,
2018-02-27 18:06:05 +01:00
};
2021-06-20 19:04:08 +02:00
explicit LoadResult(const QUrl &original_url = QUrl(), const Type type = NoMoreTracks, const QUrl &stream_url = QUrl(), const Song::FileType filetype = Song::FileType_Stream, const int samplerate = -1, const int bit_depth = -1, const qint64 length_nanosec = -1, const QString &error = QString());
2018-02-27 18:06:05 +01:00
2021-06-20 19:04:08 +02:00
explicit LoadResult(const QUrl &original_url, const Type type, const QString &error);
2020-08-23 18:52:30 +02:00
2018-02-27 18:06:05 +01:00
// The url that the playlist item has in Url().
// Might be something unplayable like lastfm://...
QUrl original_url_;
2021-07-23 21:30:08 +02:00
// Result type
2018-02-27 18:06:05 +01:00
Type type_;
// The actual url to something that gstreamer can play.
QUrl stream_url_;
2018-02-27 18:06:05 +01:00
2018-09-20 22:13:30 +02:00
// The type of the stream
Song::FileType filetype_;
// Track sample rate
int samplerate_;
// Track bit depth
int bit_depth_;
// Track length
2018-02-27 18:06:05 +01:00
qint64 length_nanosec_;
// Error message, if any
QString error_;
2018-02-27 18:06:05 +01:00
};
// Called by the Player when a song starts loading - gives the handler a chance to do something clever to get a playable track.
2018-02-27 18:06:05 +01:00
virtual LoadResult StartLoading(const QUrl &url) { return LoadResult(url); }
2018-09-20 22:13:30 +02:00
signals:
2021-01-26 16:48:04 +01:00
void AsyncLoadComplete(UrlHandler::LoadResult result);
2018-09-20 22:13:30 +02:00
2018-02-27 18:06:05 +01:00
};
#endif // URLHANDLER_H