Move HTTP streaming into its own class
This commit is contained in:
committed by
craig.p.drummond
parent
6e83445b76
commit
d7750cc1f3
@@ -325,6 +325,11 @@ if (ENABLE_HTTP_SERVER)
|
||||
set(CANTATA_UIS ${CANTATA_UIS} http/httpserversettings.ui)
|
||||
endif (ENABLE_HTTP_SERVER)
|
||||
|
||||
if (ENABLE_HTTP_STREAM_PLAYBACK)
|
||||
set(CANTATA_SRCS ${CANTATA_SRCS} mpd/httpstream.cpp)
|
||||
set(CANTATA_MOC_HDRS ${CANTATA_MOC_HDRS} mpd/httpstream.h)
|
||||
endif (ENABLE_HTTP_STREAM_PLAYBACK)
|
||||
|
||||
if (ENABLE_MODEL_TEST AND NOT ENABLE_KDE AND NOT ENABLE_QT5)
|
||||
set(QTLIBS ${QTLIBS} ${QT_QTTEST_LIBRARY})
|
||||
set(CANTATA_SRCS ${CANTATA_SRCS} models/modeltest.cpp)
|
||||
@@ -696,7 +701,7 @@ if ((ENABLE_DEVICES_SUPPORT AND ENABLE_REMOTE_DEVICES) OR ENABLE_HTTP_STREAM_PLA
|
||||
endif (ENABLE_REMOTE_DEVICES)
|
||||
if (ENABLE_EXTERNAL_TAGS)
|
||||
message(" * External Tags - Use external helper app to read/write tags. EXPERIMENTAL - AND *NOT* FULLY FUNCTIONAL!")
|
||||
endif (ENABLE_PROXY_CONFIG)
|
||||
endif (ENABLE_EXTERNAL_TAGS)
|
||||
message("")
|
||||
endif ((ENABLE_DEVICES_SUPPORT AND ENABLE_REMOTE_DEVICES) OR ENABLE_HTTP_STREAM_PLAYBACK OR ENABLE_EXTERNAL_TAGS OR (NOT ENABLE_KDE AND ENABLE_PROXY_CONFIG))
|
||||
|
||||
|
||||
@@ -51,9 +51,6 @@
|
||||
#include "localize.h"
|
||||
#include "qtplural.h"
|
||||
#include "mainwindow.h"
|
||||
#if defined ENABLE_HTTP_STREAM_PLAYBACK && QT_VERSION < 0x050000
|
||||
#include <phonon/audiooutput.h>
|
||||
#endif
|
||||
#include "thread.h"
|
||||
#include "trayitem.h"
|
||||
#include "messagebox.h"
|
||||
@@ -128,6 +125,9 @@
|
||||
#include "action.h"
|
||||
#include "actioncollection.h"
|
||||
#include "stdactions.h"
|
||||
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
|
||||
#include "httpstream.h"
|
||||
#endif
|
||||
#ifdef Q_OS_WIN
|
||||
static void raiseWindow(QWidget *w);
|
||||
#endif
|
||||
@@ -186,6 +186,9 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
, lastState(MPDState_Inactive)
|
||||
, lastSongId(-1)
|
||||
, autoScrollPlayQueue(true)
|
||||
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
|
||||
, httpStream(new HttpStream(this))
|
||||
#endif
|
||||
, currentPage(0)
|
||||
#ifdef QT_QTDBUS_FOUND
|
||||
, mpris(0)
|
||||
@@ -201,10 +204,6 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
, origVolume(0)
|
||||
, lastVolume(0)
|
||||
, stopState(StopState_None)
|
||||
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
|
||||
, httpStreamEnabled(false)
|
||||
, httpStream(0)
|
||||
#endif
|
||||
{
|
||||
QPoint p=pos();
|
||||
ActionCollection::setMainWidget(this);
|
||||
@@ -481,6 +480,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
consumePlayQueueAction->setCheckable(true);
|
||||
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
|
||||
streamPlayAction->setCheckable(true);
|
||||
streamPlayAction->setChecked(false);
|
||||
streamPlayAction->setVisible(false);
|
||||
#endif
|
||||
|
||||
songInfoButton->setDefaultAction(songInfoAction);
|
||||
@@ -528,10 +529,6 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
repeatPlayQueueAction->setChecked(false);
|
||||
singlePlayQueueAction->setChecked(false);
|
||||
consumePlayQueueAction->setChecked(false);
|
||||
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
|
||||
streamPlayAction->setChecked(false);
|
||||
streamPlayAction->setVisible(false);
|
||||
#endif
|
||||
|
||||
MusicLibraryItemAlbum::setCoverSize((MusicLibraryItemAlbum::CoverSize)Settings::self()->libraryCoverSize());
|
||||
MusicLibraryItemAlbum::setShowDate(Settings::self()->libraryYear());
|
||||
@@ -764,8 +761,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
connect(singlePlayQueueAction, SIGNAL(triggered(bool)), MPDConnection::self(), SLOT(setSingle(bool)));
|
||||
connect(consumePlayQueueAction, SIGNAL(triggered(bool)), MPDConnection::self(), SLOT(setConsume(bool)));
|
||||
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
|
||||
connect(streamPlayAction, SIGNAL(triggered(bool)), this, SLOT(toggleStream(bool)));
|
||||
connect(MPDConnection::self(), SIGNAL(streamUrl(QString)), SLOT(streamUrl(QString)));
|
||||
connect(streamPlayAction, SIGNAL(triggered(bool)), httpStream, SLOT(setEnabled(bool)));
|
||||
#endif
|
||||
connect(StdActions::self()->backAction, SIGNAL(triggered(bool)), this, SLOT(goBack()));
|
||||
connect(playQueueSearchWidget, SIGNAL(returnPressed()), this, SLOT(searchPlayQueue()));
|
||||
@@ -1157,17 +1153,6 @@ void MainWindow::connectToMpd()
|
||||
connectToMpd(Settings::self()->connectionDetails());
|
||||
}
|
||||
|
||||
void MainWindow::streamUrl(const QString &u)
|
||||
{
|
||||
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
|
||||
streamPlayAction->setVisible(!u.isEmpty());
|
||||
streamPlayAction->setChecked(streamPlayAction->isVisible() && Settings::self()->playStream());
|
||||
toggleStream(streamPlayAction->isChecked(), u);
|
||||
#else
|
||||
Q_UNUSED(u)
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::refreshDbPromp()
|
||||
{
|
||||
if (QDialogButtonBox::GnomeLayout==style()->styleHint(QStyle::SH_DialogButtonLayout)) {
|
||||
@@ -1588,53 +1573,6 @@ void MainWindow::showServerInfo()
|
||||
i18n("Server Information"));
|
||||
}
|
||||
|
||||
void MainWindow::toggleStream(bool s, const QString &url)
|
||||
{
|
||||
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
|
||||
MPDStatus * const status = MPDStatus::self();
|
||||
httpStreamEnabled = s;
|
||||
if (!s){
|
||||
if (httpStream) {
|
||||
httpStream->stop();
|
||||
}
|
||||
} else {
|
||||
static const char *constUrlProperty="url";
|
||||
if (httpStream && httpStream->property(constUrlProperty).toString()!=url) {
|
||||
httpStream->stop();
|
||||
httpStream->deleteLater();
|
||||
httpStream=0;
|
||||
}
|
||||
if (httpStream) {
|
||||
switch (status->state()) {
|
||||
case MPDState_Playing:
|
||||
httpStream->play();
|
||||
break;
|
||||
case MPDState_Inactive:
|
||||
case MPDState_Stopped:
|
||||
httpStream->stop();
|
||||
break;
|
||||
case MPDState_Paused:
|
||||
httpStream->pause();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
#if QT_VERSION < 0x050000
|
||||
httpStream=new Phonon::MediaObject(this);
|
||||
Phonon::createPath(httpStream, new Phonon::AudioOutput(Phonon::MusicCategory, this));
|
||||
httpStream->setCurrentSource(url);
|
||||
#else
|
||||
httpStream=new QMediaPlayer(this);
|
||||
httpStream->setMedia(QUrl(url));
|
||||
#endif
|
||||
httpStream->setProperty(constUrlProperty, url);
|
||||
}
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(s) Q_UNUSED(url)
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::enableStopActions(bool enable)
|
||||
{
|
||||
StdActions::self()->stopAfterCurrentTrackAction->setEnabled(enable);
|
||||
@@ -2003,11 +1941,6 @@ void MainWindow::updateStatus(MPDStatus * const status)
|
||||
playQueueModel.setState(status->state());
|
||||
switch (status->state()) {
|
||||
case MPDState_Playing:
|
||||
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
|
||||
if (httpStreamEnabled && httpStream) {
|
||||
httpStream->play();
|
||||
}
|
||||
#endif
|
||||
StdActions::self()->playPauseTrackAction->setIcon(Icons::self()->toolbarPauseIcon);
|
||||
StdActions::self()->playPauseTrackAction->setEnabled(0!=status->playlistLength());
|
||||
//playPauseTrackButton->setChecked(false);
|
||||
@@ -2020,11 +1953,6 @@ void MainWindow::updateStatus(MPDStatus * const status)
|
||||
break;
|
||||
case MPDState_Inactive:
|
||||
case MPDState_Stopped:
|
||||
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
|
||||
if (httpStreamEnabled && httpStream) {
|
||||
httpStream->stop();
|
||||
}
|
||||
#endif
|
||||
StdActions::self()->playPauseTrackAction->setIcon(Icons::self()->toolbarPlayIcon);
|
||||
StdActions::self()->playPauseTrackAction->setEnabled(0!=status->playlistLength());
|
||||
enableStopActions(false);
|
||||
@@ -2042,20 +1970,13 @@ void MainWindow::updateStatus(MPDStatus * const status)
|
||||
positionSlider->stopTimer();
|
||||
break;
|
||||
case MPDState_Paused:
|
||||
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
|
||||
if (httpStreamEnabled && httpStream) {
|
||||
httpStream->pause();
|
||||
}
|
||||
#endif
|
||||
StdActions::self()->playPauseTrackAction->setIcon(Icons::self()->toolbarPlayIcon);
|
||||
StdActions::self()->playPauseTrackAction->setEnabled(0!=status->playlistLength());
|
||||
enableStopActions(0!=status->playlistLength());
|
||||
StdActions::self()->nextTrackAction->setEnabled(status->playlistLength()>1);
|
||||
StdActions::self()->prevTrackAction->setEnabled(status->playlistLength()>1);
|
||||
positionSlider->stopTimer();
|
||||
break;
|
||||
default:
|
||||
qDebug("Invalid state");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,13 +46,6 @@
|
||||
#include "mpdconnection.h"
|
||||
#include "song.h"
|
||||
#include "config.h"
|
||||
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
|
||||
#if QT_VERSION < 0x050000
|
||||
#include <phonon/mediaobject.h>
|
||||
#else
|
||||
#include <QtMultimedia/QMediaPlayer>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class Action;
|
||||
class ActionCollection;
|
||||
@@ -85,6 +78,7 @@ class QActionGroup;
|
||||
class QDateTime;
|
||||
class TrayItem;
|
||||
class GtkProxyStyle;
|
||||
class HttpStream;
|
||||
|
||||
// Dummy classes so that when class name is saved to the config file, we get a more meaningful name than QWidget!!!
|
||||
class PlayQueuePage : public QWidget
|
||||
@@ -204,13 +198,11 @@ public Q_SLOTS:
|
||||
void changeConnection();
|
||||
void connectToMpd();
|
||||
void connectToMpd(const MPDConnectionDetails &details);
|
||||
void streamUrl(const QString &u);
|
||||
void refreshDbPromp();
|
||||
#ifndef ENABLE_KDE_SUPPORT
|
||||
void showAboutDialog();
|
||||
#endif
|
||||
void showServerInfo();
|
||||
void toggleStream(bool s, const QString &url=QString());
|
||||
void stopPlayback();
|
||||
void stopAfterCurrentTrack();
|
||||
void stopAfterTrack();
|
||||
@@ -352,6 +344,7 @@ private:
|
||||
Action *searchPlayQueueAction;
|
||||
Action *setPriorityAction;
|
||||
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
|
||||
HttpStream *httpStream;
|
||||
Action *streamPlayAction;
|
||||
#endif
|
||||
Action *expandInterfaceAction;
|
||||
@@ -442,14 +435,6 @@ private:
|
||||
int origVolume;
|
||||
int lastVolume;
|
||||
StopState stopState;
|
||||
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
|
||||
bool httpStreamEnabled;
|
||||
#if QT_VERSION < 0x050000
|
||||
Phonon::MediaObject *httpStream;
|
||||
#else
|
||||
QMediaPlayer *httpStream;
|
||||
#endif
|
||||
#endif
|
||||
friend class CoverEventHandler;
|
||||
friend class TrayItem;
|
||||
};
|
||||
|
||||
110
mpd/httpstream.cpp
Normal file
110
mpd/httpstream.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Cantata
|
||||
*
|
||||
* Copyright (c) 2011-2014 Craig Drummond <craig.p.drummond@gmail.com>
|
||||
*
|
||||
* ----
|
||||
*
|
||||
* This program 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "httpstream.h"
|
||||
#include "mpdconnection.h"
|
||||
#include "mpdstatus.h"
|
||||
#if QT_VERSION < 0x050000
|
||||
#include <phonon/audiooutput.h>
|
||||
#endif
|
||||
|
||||
HttpStream::HttpStream(QObject *p)
|
||||
: QObject(p)
|
||||
, enabled(false)
|
||||
, player(0)
|
||||
{
|
||||
}
|
||||
|
||||
void HttpStream::setEnabled(bool e)
|
||||
{
|
||||
if (e==enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
connect(MPDConnection::self(), SIGNAL(streamUrl(QString)), this, SLOT(streamUrl(QString)));
|
||||
connect(MPDStatus::self(), SIGNAL(updated()), this, SLOT(updateStatus()));
|
||||
} else {
|
||||
disconnect(MPDConnection::self(), SIGNAL(streamUrl(QString)), this, SLOT(streamUrl(QString)));
|
||||
disconnect(MPDStatus::self(), SIGNAL(updated()), this, SLOT(updateStatus()));
|
||||
if (player) {
|
||||
player->stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HttpStream::streamUrl(const QString &url)
|
||||
{
|
||||
MPDStatus * const status = MPDStatus::self();
|
||||
static const char *constUrlProperty="url";
|
||||
if (player && player->property(constUrlProperty).toString()!=url) {
|
||||
player->stop();
|
||||
player->deleteLater();
|
||||
player=0;
|
||||
}
|
||||
if (player) {
|
||||
switch (status->state()) {
|
||||
case MPDState_Playing:
|
||||
player->play();
|
||||
break;
|
||||
case MPDState_Inactive:
|
||||
case MPDState_Stopped:
|
||||
player->stop();
|
||||
break;
|
||||
case MPDState_Paused:
|
||||
player->pause();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (!url.isEmpty()) {
|
||||
#if QT_VERSION < 0x050000
|
||||
player=new Phonon::MediaObject(this);
|
||||
Phonon::createPath(player, new Phonon::AudioOutput(Phonon::MusicCategory, this));
|
||||
player->setCurrentSource(url);
|
||||
#else
|
||||
player=new QMediaPlayer(this);
|
||||
player->setMedia(QUrl(url));
|
||||
#endif
|
||||
player->setProperty(constUrlProperty, url);
|
||||
}
|
||||
}
|
||||
|
||||
void HttpStream::updateStatus()
|
||||
{
|
||||
if (!player) {
|
||||
return;
|
||||
}
|
||||
switch (MPDStatus::self()->state()) {
|
||||
case MPDState_Playing:
|
||||
player->play();
|
||||
break;
|
||||
case MPDState_Inactive:
|
||||
case MPDState_Stopped:
|
||||
player->stop();
|
||||
break;
|
||||
case MPDState_Paused:
|
||||
player->pause();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
60
mpd/httpstream.h
Normal file
60
mpd/httpstream.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Cantata
|
||||
*
|
||||
* Copyright (c) 2011-2014 Craig Drummond <craig.p.drummond@gmail.com>
|
||||
*
|
||||
* ----
|
||||
*
|
||||
* This program 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef HTTP_STREAM_H
|
||||
#define HTTP_STREAM_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
#include <phonon/mediaobject.h>
|
||||
#else
|
||||
#include <QtMultimedia/QMediaPlayer>
|
||||
#endif
|
||||
|
||||
class HttpStream : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
HttpStream(QObject *p);
|
||||
virtual ~HttpStream() { }
|
||||
|
||||
public Q_SLOTS:
|
||||
void setEnabled(bool e);
|
||||
|
||||
private Q_SLOTS:
|
||||
void updateStatus();
|
||||
void streamUrl(const QString &url);
|
||||
|
||||
private:
|
||||
bool enabled;
|
||||
#if QT_VERSION < 0x050000
|
||||
Phonon::MediaObject *player;
|
||||
#else
|
||||
QMediaPlayer *player;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user