Enable MPD HTTP stream playback using QtMultiMedia for Qt5 builds. Thanks to Marcel Bosling for the patch. Disabled by default, to enable pass -DENABLE_HTTP_STREAM_PLAYBACK=ON to cmake.

This commit is contained in:
craig.p.drummond
2013-06-11 17:46:19 +00:00
parent a32658a688
commit 88f26a5462
11 changed files with 95 additions and 71 deletions

View File

@@ -23,7 +23,7 @@ include(CPack)
OPTION(ENABLE_TAGLIB "Enable TagLib library (required for tag editing, replaygain calculation, device support, etc)" ON)
OPTION(ENABLE_TAGLIB_EXTRAS "Enable TagLib-Extras library (used by tag editing, replaygain calculation, device support, etc)" ON)
OPTION(ENABLE_PHONON "Enable Phonon library (required to playback MPD HTTP streams)" OFF)
OPTION(ENABLE_HTTP_STREAM_PLAYBACK "Enable playback of MPD HTTP streams (Phonon required for Qt4, QtMultimedia for Qt5)" OFF)
OPTION(ENABLE_KDE "Enable KDE libraries" ON)
OPTION(ENABLE_QT5 "Build against Qt5" OFF)
OPTION(ENABLE_MTP "Enable MTP library (required to support MTP devices)" ON)
@@ -39,7 +39,6 @@ OPTION(ENABLE_MUSICBRAINZ "Enable MusicBrianz libraries (either this or CDDB req
OPTION(ENABLE_LAME "Enable LAME libraries (required for AudioCD playback support)" ON)
if (ENABLE_QT5)
set(ENABLE_PHONON FALSE)
set(ENABLE_KDE FALSE)
endif (ENABLE_QT5)
@@ -252,18 +251,21 @@ if(NOT WIN32)
endif(NOT WIN32)
IF( ENABLE_KDE )
FIND_PACKAGE( KDE4 )
IF( KDE4_FOUND )
ADD_DEFINITIONS( -DENABLE_KDE_SUPPORT )
SET( ENABLE_KDE_SUPPORT TRUE )
ENDIF( KDE4_FOUND )
FIND_PACKAGE( KDE4 REQUIRED)
ADD_DEFINITIONS( -DENABLE_KDE_SUPPORT )
SET( ENABLE_KDE_SUPPORT TRUE )
ENDIF( ENABLE_KDE )
if (ENABLE_PHONON)
FIND_PACKAGE( Phonon )
else (ENABLE_PHONON)
set(PHONON_FOUND 0)
endif (ENABLE_PHONON)
if (ENABLE_HTTP_STREAM_PLAYBACK)
if (ENABLE_QT5)
find_package(Qt5Multimedia REQUIRED)
set (QTLIBS ${QTLIBS} ${Qt5Multimedia_LIBRARIES})
set (QTINCLUDES ${QTINCLUDES} ${Qt5Multimedia_INCLUDES})
add_definitions (${Qt5Multimedia_DEFINITIONS})
else (ENABLE_QT5)
find_package( Phonon REQUIRED)
endif (ENABLE_QT5)
endif (ENABLE_HTTP_STREAM_PLAYBACK)
if (TAGLIB_FOUND)
set(ENABLE_TAGEDITOR_SUPPORT 1)
@@ -464,6 +466,11 @@ ELSE( ENABLE_KDE_SUPPORT )
endif (WIN32)
ENDIF( ENABLE_KDE_SUPPORT )
if (ENABLE_HTTP_STREAM_PLAYBACK AND NOT ENABLE_QT5)
target_link_libraries(cantata ${PHONON_LIBS})
include_directories( ${PHONON_INCLUDES})
endif (ENABLE_HTTP_STREAM_PLAYBACK AND NOT ENABLE_QT5)
if (NOT WIN32)
install(PROGRAMS dynamic/cantata-dynamic DESTINATION ${CMAKE_INSTALL_PREFIX}/share/${CMAKE_PROJECT_NAME}/scripts)
if (MTP_FOUND)
@@ -569,7 +576,7 @@ if (TAGLIB_FOUND)
set(AUDIOCD_SUPPORT 1)
endif (CDDB_FOUND OR MUSICBRAINZ5_FOUND)
if (ENABLE_REMOTE_DEVICES OR PHONON_FOUND OR AUDIOCD_SUPPORT OR MTP_FOUND)
if (ENABLE_REMOTE_DEVICES OR ENABLE_HTTP_STREAM_PLAYBACK OR AUDIOCD_SUPPORT OR MTP_FOUND)
message(" Extra enabled features:")
if (ENABLE_ONLINE_SERVICES)
message(" - Online services (Jamendo and Magnatune)")
@@ -586,21 +593,21 @@ if (TAGLIB_FOUND)
if (ENABLE_REMOTE_DEVICES)
message(" - Remote device sync (EXPERIMENTAL)")
endif (ENABLE_REMOTE_DEVICES)
if (PHONON_FOUND)
if (ENABLE_HTTP_STREAM_PLAYBACK)
message(" - MPD HTTP stream playback")
endif (PHONON_FOUND)
endif (ENABLE_HTTP_STREAM_PLAYBACK)
if (ENABLE_REPLAYGAIN_SUPPORT)
message(" - ReplayGain calculation")
endif (ENABLE_REPLAYGAIN_SUPPORT)
endif (ENABLE_REMOTE_DEVICES OR PHONON_FOUND OR AUDIOCD_SUPPORT OR MTP_FOUND)
if (NOT TAGLIB_FOUND OR NOT MTP_FOUND OR NOT AUDIOCD_SUPPORT OR NOT ENABLE_REPLAYGAIN_SUPPORT OR NOT PHONON_FOUND OR NOT ENABLE_REMOTE_DEVICES OR NOT ENABLE_ONLINE_SERVICES OR (AUDIOCD_SUPPORT AND NOT LAME_FOUND))
endif (ENABLE_REMOTE_DEVICES OR ENABLE_HTTP_STREAM_PLAYBACK OR AUDIOCD_SUPPORT OR MTP_FOUND)
if (NOT TAGLIB_FOUND OR NOT MTP_FOUND OR NOT AUDIOCD_SUPPORT OR NOT ENABLE_REPLAYGAIN_SUPPORT OR NOT ENABLE_HTTP_STREAM_PLAYBACK OR NOT ENABLE_REMOTE_DEVICES OR NOT ENABLE_ONLINE_SERVICES OR (AUDIOCD_SUPPORT AND NOT LAME_FOUND))
message(" Disabled features:")
if (NOT ENABLE_ONLINE_SERVICES)
message(" - Online services (Jamendo and Magnatune)")
endif (NOT ENABLE_ONLINE_SERVICES)
if (NOT PHONON_FOUND)
message(" - MPD HTTP stream playback (phonon required)")
endif (NOT PHONON_FOUND)
if (NOT ENABLE_HTTP_STREAM_PLAYBACK)
message(" - MPD HTTP stream playback (Phonon required for Qt4, QtMultiMedia for Qt5)")
endif (NOT ENABLE_HTTP_STREAM_PLAYBACK)
if (NOT MTP_FOUND AND NOT WIN32)
message(" - MTP device sync (taglib and libmtp required)")
endif (NOT MTP_FOUND AND NOT WIN32)
@@ -616,7 +623,7 @@ if (TAGLIB_FOUND)
if(NOT ENABLE_REPLAYGAIN_SUPPORT)
message(" - ReplayGain calculation (taglib, and ffmpeg and/or mpg123 required)")
endif(NOT ENABLE_REPLAYGAIN_SUPPORT)
endif (NOT TAGLIB_FOUND OR NOT MTP_FOUND OR NOT AUDIOCD_SUPPORT OR NOT ENABLE_REPLAYGAIN_SUPPORT OR NOT PHONON_FOUND OR NOT ENABLE_REMOTE_DEVICES OR NOT ENABLE_ONLINE_SERVICES OR (AUDIOCD_SUPPORT AND NOT LAME_FOUND))
endif (NOT TAGLIB_FOUND OR NOT MTP_FOUND OR NOT AUDIOCD_SUPPORT OR NOT ENABLE_REPLAYGAIN_SUPPORT OR NOT ENABLE_HTTP_STREAM_PLAYBACK OR NOT ENABLE_REMOTE_DEVICES OR NOT ENABLE_ONLINE_SERVICES OR (AUDIOCD_SUPPORT AND NOT LAME_FOUND))
else (TAGLIB_FOUND)

View File

@@ -59,6 +59,9 @@
38. Remove amazon cover fetching - required API key that Cantata never really
had.
39. Add debug logging. Please see README for details.
40. Enable MPD HTTP stream playback using QtMultiMedia for Qt5 builds. Thanks
to Marcel Bosling for the patch. Disabled by default, to enable pass
-DENABLE_HTTP_STREAM_PLAYBACK=ON to cmake.
1.0.3
-----

View File

@@ -55,8 +55,9 @@ The following options may be passed to CMake:
Build against Qt5, not Qt4
Default: OFF
-DENABLE_PHONON=ON
Enable support for playing back MPD HTTP streams via Phonon.
-DENABLE_HTTP_STREAM_PLAYBACK=ON
Enable support for playing back MPD HTTP streams via Phonon (Qt4) or
QtMultiMedia (Qt5).
Default: OFF
-DENABLE_UDISKS2=ON

View File

@@ -22,7 +22,7 @@
#cmakedefine TAGLIB_ASF_FOUND
#cmakedefine TAGLIB_MP4_FOUND 1
#cmakedefine MTP_FOUND 1
#cmakedefine PHONON_FOUND 1
#cmakedefine ENABLE_HTTP_STREAM_PLAYBACK 1
#cmakedefine FFMPEG_FOUND 1
#cmakedefine MPG123_FOUND 1
#cmakedefine LAME_FOUND 1

View File

@@ -45,7 +45,7 @@
#endif
#include "localize.h"
#include "mainwindow.h"
#ifdef PHONON_FOUND
#if defined ENABLE_HTTP_STREAM_PLAYBACK && QT_VERSION < 0x050000
#include <phonon/audiooutput.h>
#endif
#include "trayitem.h"
@@ -205,9 +205,9 @@ MainWindow::MainWindow(QWidget *parent)
, origVolume(0)
, lastVolume(0)
, stopState(StopState_None)
#ifdef PHONON_FOUND
, phononStreamEnabled(false)
, phononStream(0)
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
, httpStreamEnabled(false)
, httpStream(0)
#endif
{
QPoint p=pos();
@@ -292,7 +292,7 @@ MainWindow::MainWindow(QWidget *parent)
singlePlayQueueAction = ActionCollection::get()->createAction("singleplaylist", i18n("Single"), Icons::singleIcon, i18n("When 'Single' is activated, playback is stopped after current song, or song is repeated if 'Repeat' is enabled."));
consumePlayQueueAction = ActionCollection::get()->createAction("consumeplaylist", i18n("Consume"), Icons::consumeIcon, i18n("When consume is activated, a song is removed from the play queue after it has been played."));
setPriorityAction = ActionCollection::get()->createAction("setprio", i18n("Set Priority"), Icon("favorites"));
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
streamPlayAction = ActionCollection::get()->createAction("streamplay", i18n("Play Stream"), Icons::toolbarStreamIcon, i18n("When 'Play Stream' is activated, the enabled stream is played locally."));
#endif
locateTrackAction = ActionCollection::get()->createAction("locatetrack", i18n("Locate In Library"), "edit-find");
@@ -408,7 +408,7 @@ MainWindow::MainWindow(QWidget *parent)
repeatButton->setDefaultAction(repeatPlayQueueAction);
singleButton->setDefaultAction(singlePlayQueueAction);
consumeButton->setDefaultAction(consumePlayQueueAction);
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
streamButton->setDefaultAction(streamPlayAction);
#else
streamButton->setVisible(false);
@@ -486,7 +486,7 @@ MainWindow::MainWindow(QWidget *parent)
repeatPlayQueueAction->setCheckable(true);
singlePlayQueueAction->setCheckable(true);
consumePlayQueueAction->setCheckable(true);
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
streamPlayAction->setCheckable(true);
#endif
@@ -543,7 +543,7 @@ MainWindow::MainWindow(QWidget *parent)
repeatPlayQueueAction->setChecked(false);
singlePlayQueueAction->setChecked(false);
consumePlayQueueAction->setChecked(false);
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
streamPlayAction->setChecked(false);
#endif
@@ -750,7 +750,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(repeatPlayQueueAction, SIGNAL(triggered(bool)), MPDConnection::self(), SLOT(setRepeat(bool)));
connect(singlePlayQueueAction, SIGNAL(triggered(bool)), MPDConnection::self(), SLOT(setSingle(bool)));
connect(consumePlayQueueAction, SIGNAL(triggered(bool)), MPDConnection::self(), SLOT(setConsume(bool)));
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
connect(streamPlayAction, SIGNAL(triggered(bool)), this, SLOT(toggleStream(bool)));
#endif
connect(StdActions::self()->backAction, SIGNAL(triggered(bool)), this, SLOT(goBack()));
@@ -885,7 +885,7 @@ MainWindow::~MainWindow()
#if defined ENABLE_REMOTE_DEVICES && defined ENABLE_DEVICES_SUPPORT
DevicesModel::self()->unmountRemote();
#endif
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
Settings::self()->savePlayStream(streamPlayAction->isChecked());
#endif
if (!fullScreenAction->isChecked()) {
@@ -1353,7 +1353,7 @@ void MainWindow::readSettings()
albumsPage->setView(Settings::self()->albumsView());
AlbumsModel::self()->setAlbumSort(Settings::self()->albumSort());
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
streamButton->setVisible(!Settings::self()->streamUrl().isEmpty());
streamPlayAction->setChecked(streamButton->isVisible() && Settings::self()->playStream());
toggleStream(streamPlayAction->isChecked());
@@ -1522,32 +1522,37 @@ void MainWindow::showServerInfo()
void MainWindow::toggleStream(bool s)
{
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
MPDStatus * const status = MPDStatus::self();
phononStreamEnabled = s;
httpStreamEnabled = s;
if (!s){
if (phononStream) {
phononStream->stop();
if (httpStream) {
httpStream->stop();
}
} else {
if (phononStream) {
if (httpStream) {
switch (status->state()) {
case MPDState_Playing:
phononStream->play();
httpStream->play();
break;
case MPDState_Inactive:
case MPDState_Stopped:
phononStream->stop();
httpStream->stop();
break;
case MPDState_Paused:
phononStream->pause();
httpStream->pause();
default:
break;
}
} else {
phononStream=new Phonon::MediaObject(this);
Phonon::createPath(phononStream, new Phonon::AudioOutput(Phonon::MusicCategory, this));
phononStream->setCurrentSource(Settings::self()->streamUrl());
#if QT_VERSION < 0x050000
httpStream=new Phonon::MediaObject(this);
Phonon::createPath(httpStream, new Phonon::AudioOutput(Phonon::MusicCategory, this));
httpStream->setCurrentSource(Settings::self()->streamUrl());
#else
httpStream=new QMediaPlayer(this);
httpStream->setMedia(QUrl(Settings::self()->streamUrl()));
#endif
}
}
#else
@@ -1947,9 +1952,9 @@ void MainWindow::updateStatus(MPDStatus * const status)
playQueueModel.setState(status->state());
switch (status->state()) {
case MPDState_Playing:
#ifdef PHONON_FOUND
if (phononStreamEnabled && phononStream) {
phononStream->play();
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
if (httpStreamEnabled && httpStream) {
httpStream->play();
}
#endif
playPauseTrackAction->setIcon(Icons::toolbarPauseIcon);
@@ -1970,9 +1975,9 @@ void MainWindow::updateStatus(MPDStatus * const status)
break;
case MPDState_Inactive:
case MPDState_Stopped:
#ifdef PHONON_FOUND
if (phononStreamEnabled && phononStream) {
phononStream->stop();
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
if (httpStreamEnabled && httpStream) {
httpStream->stop();
}
#endif
playPauseTrackAction->setIcon(Icons::toolbarPlayIcon);
@@ -1998,9 +2003,9 @@ void MainWindow::updateStatus(MPDStatus * const status)
positionSlider->stopTimer();
break;
case MPDState_Paused:
#ifdef PHONON_FOUND
if (phononStreamEnabled && phononStream) {
phononStream->pause();
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
if (httpStreamEnabled && httpStream) {
httpStream->pause();
}
#endif
playPauseTrackAction->setIcon(Icons::toolbarPlayIcon);

View File

@@ -46,8 +46,12 @@
#include "mpdconnection.h"
#include "song.h"
#include "config.h"
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
#if QT_VERSION < 0x050000
#include <phonon/mediaobject.h>
#else
#include <QtMultimedia/QMediaPlayer>
#endif
#endif
class Action;
@@ -356,7 +360,7 @@ private:
Action *singlePlayQueueAction;
Action *consumePlayQueueAction;
Action *setPriorityAction;
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
Action *streamPlayAction;
#endif
Action *expandInterfaceAction;
@@ -436,9 +440,13 @@ private:
int origVolume;
int lastVolume;
StopState stopState;
#ifdef PHONON_FOUND
bool phononStreamEnabled;
Phonon::MediaObject *phononStream;
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
bool httpStreamEnabled;
#if QT_VERSION < 0x050000
Phonon::MediaObject *httpStream;
#else
QMediaPlayer *httpStream;
#endif
#endif
friend class VolumeSliderEventHandler;

View File

@@ -52,7 +52,7 @@ ServerPlaybackSettings::ServerPlaybackSettings(QWidget *p)
messageIcon->setMinimumSize(iconSize, iconSize);
messageIcon->setMaximumSize(iconSize, iconSize);
mpdConnectionStateChanged(MPDConnection::self()->isConnected());
#ifndef PHONON_FOUND
#if not defined PHONON_FOUND && not defined ENABLE_QT5PLAYER
streamUrl->setVisible(false);
streamUrlLabel->setVisible(false);
streamUrlInfoLabel->setVisible(false);
@@ -66,7 +66,7 @@ void ServerPlaybackSettings::load()
emit getReplayGain();
emit outputs();
}
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
streamUrl->setText(Settings::self()->streamUrl());
#endif
}
@@ -81,7 +81,7 @@ void ServerPlaybackSettings::save()
emit enableOutput(item->data(Qt::UserRole).toInt(), Qt::Checked==item->checkState());
}
}
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
Settings::self()->saveStreamUrl(streamUrl->text().trimmed());
#endif
}
@@ -115,7 +115,7 @@ void ServerPlaybackSettings::mpdConnectionStateChanged(bool c)
replayGain->setEnabled(c);
crossfadingLabel->setEnabled(c);
replayGainLabel->setEnabled(c);
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
streamUrl->setEnabled(c);
streamUrlLabel->setEnabled(c);
#endif

View File

@@ -584,7 +584,7 @@ bool Settings::playListsStartClosed()
return GET_BOOL("playListsStartClosed", true);
}
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
bool Settings::playStream()
{
return GET_BOOL("playStream", false);
@@ -985,7 +985,7 @@ void Settings::savePlayListsStartClosed(bool v)
SET_VALUE_MOD(playListsStartClosed)
}
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
void Settings::savePlayStream(bool v)
{
SET_VALUE_MOD(playStream)

View File

@@ -150,7 +150,7 @@ public:
bool playQueueStartClosed();
bool playQueueScroll();
bool playListsStartClosed();
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
bool playStream();
QString streamUrl();
#endif
@@ -231,7 +231,7 @@ public:
void savePlayQueueStartClosed(bool v);
void savePlayQueueScroll(bool v);
void savePlayListsStartClosed(bool v);
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
void savePlayStream(bool v);
void saveStreamUrl(const QString &v);
#endif

View File

@@ -348,7 +348,7 @@ Icon Icons::toolbarVolumeMutedIcon;
Icon Icons::toolbarVolumeLowIcon;
Icon Icons::toolbarVolumeMediumIcon;
Icon Icons::toolbarVolumeHighIcon;
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
Icon Icons::toolbarStreamIcon;
#endif
@@ -681,7 +681,7 @@ void Icons::initToolbarIcons(const QColor &color, bool forceLight)
toolbarVolumeHighIcon=Icon("audio-volume-high");
}
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
toolbarStreamIcon=streamIcon;
#endif
}

View File

@@ -94,7 +94,7 @@ namespace Icons
extern Icon toolbarVolumeLowIcon;
extern Icon toolbarVolumeMediumIcon;
extern Icon toolbarVolumeHighIcon;
#ifdef PHONON_FOUND
#ifdef ENABLE_HTTP_STREAM_PLAYBACK
extern Icon toolbarStreamIcon;
#endif
}