2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
Clementine 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.
|
|
|
|
|
|
|
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "config.h"
|
2009-12-24 20:16:07 +01:00
|
|
|
#include "player.h"
|
2010-04-15 14:39:34 +02:00
|
|
|
#include "engines/enginebase.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "playlist/playlist.h"
|
2010-05-20 23:21:55 +02:00
|
|
|
#include "playlist/playlistitem.h"
|
|
|
|
#include "playlist/playlistmanager.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "radio/lastfmservice.h"
|
2010-04-15 14:39:34 +02:00
|
|
|
|
2010-05-31 23:24:54 +02:00
|
|
|
#ifdef HAVE_GSTREAMER
|
2010-04-15 14:39:34 +02:00
|
|
|
# include "engines/gstengine.h"
|
2010-05-31 23:24:54 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBVLC
|
2010-04-15 14:39:34 +02:00
|
|
|
# include "engines/vlcengine.h"
|
2010-05-31 23:24:54 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBXINE
|
2010-04-15 14:39:34 +02:00
|
|
|
# include "engines/xine-engine.h"
|
2010-05-31 23:24:54 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_QT_PHONON
|
2010-04-15 14:39:34 +02:00
|
|
|
# include "engines/phononengine.h"
|
|
|
|
#endif
|
2010-03-24 22:07:16 +01:00
|
|
|
|
|
|
|
#ifdef Q_WS_X11
|
2010-11-21 16:13:26 +01:00
|
|
|
# include "mpris.h"
|
|
|
|
# include "mpris2.h"
|
2010-03-24 22:07:16 +01:00
|
|
|
# include <QDBusConnection>
|
2010-11-21 16:13:26 +01:00
|
|
|
# include <QImage>
|
2010-03-24 22:07:16 +01:00
|
|
|
#endif
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
#include <QtDebug>
|
2010-02-03 22:48:00 +01:00
|
|
|
#include <QtConcurrentRun>
|
|
|
|
|
|
|
|
#include <boost/bind.hpp>
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-04-15 00:36:28 +02:00
|
|
|
using boost::shared_ptr;
|
|
|
|
|
2010-06-18 15:35:17 +02:00
|
|
|
const char* Player::kRainUrl = "http://data.clementine-player.org/rainymood";
|
2010-06-14 22:00:17 +02:00
|
|
|
|
2010-03-24 22:34:32 +01:00
|
|
|
#ifdef Q_WS_X11
|
2010-03-24 21:58:17 +01:00
|
|
|
QDBusArgument& operator<< (QDBusArgument& arg, const DBusStatus& status) {
|
|
|
|
arg.beginStructure();
|
2010-03-24 22:46:00 +01:00
|
|
|
arg << status.play;
|
|
|
|
arg << status.random;
|
|
|
|
arg << status.repeat;
|
|
|
|
arg << status.repeat_playlist;
|
2010-03-24 21:58:17 +01:00
|
|
|
arg.endStructure();
|
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDBusArgument& operator>> (const QDBusArgument& arg, DBusStatus& status) {
|
|
|
|
arg.beginStructure();
|
2010-03-24 22:46:00 +01:00
|
|
|
arg >> status.play;
|
|
|
|
arg >> status.random;
|
|
|
|
arg >> status.repeat;
|
|
|
|
arg >> status.repeat_playlist;
|
2010-03-24 21:58:17 +01:00
|
|
|
arg.endStructure();
|
|
|
|
return arg;
|
|
|
|
}
|
2010-03-24 22:34:32 +01:00
|
|
|
#endif
|
2010-03-24 21:58:17 +01:00
|
|
|
|
2010-11-21 16:13:26 +01:00
|
|
|
Player::Player(MainWindow* main_window, PlaylistManager* playlists,
|
|
|
|
LastFMService* lastfm, Engine::Type engine, QObject* parent)
|
2009-12-24 20:16:07 +01:00
|
|
|
: QObject(parent),
|
2010-11-21 16:13:26 +01:00
|
|
|
mpris_(NULL),
|
|
|
|
mpris2_(NULL),
|
2010-05-20 23:21:55 +02:00
|
|
|
playlists_(playlists),
|
2009-12-29 20:22:02 +01:00
|
|
|
lastfm_(lastfm),
|
2010-05-31 22:51:29 +02:00
|
|
|
engine_(CreateEngine(engine)),
|
2010-06-14 22:00:17 +02:00
|
|
|
stream_change_type_(Engine::First),
|
Fixes issu...
,'``.._ ,'``.
:,--._:)\,:,._,.: All Glory to
:`--,'' :`...';\ the HYPNO TOAD!
`,' `---' `.
/ :
/ \
,' :\.___,-.
`...,---'``````-..._ |: \
( ) ;: ) \ _,-.
`. ( // `' \
: `.// ) ) , ;
,-|`. _,'/ ) ) ,' ,'
( :`.`-..____..=:.-': . _,' ,'
`,'\ ``--....-)=' `._, \ ,') _ '``._
_.-/ _ `. (_) / )' ; / \ \`-.'
`--( `-:`. `' ___..' _,-' |/ `.)
`-. `.`.``-----``--, .'
|/`.\`' ,','); SSt
` (/ (/
2010-07-12 21:51:23 +02:00
|
|
|
rain_stream_(-1),
|
2010-07-14 00:22:04 +02:00
|
|
|
toad_stream_(-1),
|
|
|
|
volume_before_mute_(0)
|
2009-12-24 20:16:07 +01:00
|
|
|
{
|
2010-11-21 16:13:26 +01:00
|
|
|
#ifdef Q_WS_X11
|
|
|
|
// MPRIS DBus interface.
|
|
|
|
qDBusRegisterMetaType<DBusStatus>();
|
|
|
|
qDBusRegisterMetaType<Version>();
|
|
|
|
qDBusRegisterMetaType<QImage>();
|
|
|
|
qDBusRegisterMetaType<TrackMetadata>();
|
|
|
|
qDBusRegisterMetaType<TrackIds>();
|
|
|
|
//MPRIS 1.0 implementation
|
|
|
|
mpris_ = new MPRIS(this, this);
|
|
|
|
//MPRIS 2.0 implementation
|
|
|
|
mpris2_ = new MPRIS2(main_window, this, this);
|
|
|
|
#endif
|
|
|
|
|
2010-02-03 22:48:00 +01:00
|
|
|
settings_.beginGroup("Player");
|
|
|
|
|
2010-02-03 23:05:39 +01:00
|
|
|
SetVolume(settings_.value("volume", 50).toInt());
|
|
|
|
|
2010-05-31 22:24:05 +02:00
|
|
|
connect(engine_.get(), SIGNAL(Error(QString)), SIGNAL(Error(QString)));
|
2010-03-24 21:58:17 +01:00
|
|
|
|
2010-02-03 22:48:00 +01:00
|
|
|
}
|
|
|
|
|
2010-05-28 21:51:51 +02:00
|
|
|
Player::~Player() {
|
|
|
|
}
|
|
|
|
|
2010-05-31 22:51:29 +02:00
|
|
|
EngineBase* Player::CreateEngine(Engine::Type engine) {
|
2010-04-15 14:39:34 +02:00
|
|
|
switch(engine) {
|
2010-05-31 23:24:54 +02:00
|
|
|
#ifdef HAVE_GSTREAMER
|
2010-05-31 22:59:13 +02:00
|
|
|
case Engine::Type_GStreamer:
|
2010-04-15 14:39:34 +02:00
|
|
|
return new GstEngine();
|
|
|
|
break;
|
2010-05-31 23:24:54 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBVLC
|
2010-05-31 22:59:13 +02:00
|
|
|
case Engine::Type_VLC:
|
2010-04-15 14:39:34 +02:00
|
|
|
return new VlcEngine();
|
|
|
|
break;
|
2010-05-31 23:24:54 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBXINE
|
2010-05-31 22:59:13 +02:00
|
|
|
case Engine::Type_Xine:
|
2010-04-15 14:39:34 +02:00
|
|
|
return new XineEngine();
|
|
|
|
break;
|
2010-05-31 23:24:54 +02:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_QT_PHONON
|
2010-05-31 22:59:13 +02:00
|
|
|
case Engine::Type_QtPhonon:
|
2010-04-15 14:39:34 +02:00
|
|
|
return new PhononEngine();
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
qFatal("Selected engine not compiled in");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* NOT REACHED */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-02-03 22:48:00 +01:00
|
|
|
void Player::Init() {
|
2010-04-12 01:24:03 +02:00
|
|
|
if (!engine_->Init())
|
2010-02-03 22:48:00 +01:00
|
|
|
qFatal("Error initialising audio engine");
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-05-31 22:24:05 +02:00
|
|
|
connect(engine_.get(), SIGNAL(StateChanged(Engine::State)), SLOT(EngineStateChanged(Engine::State)));
|
|
|
|
connect(engine_.get(), SIGNAL(TrackAboutToEnd()), SLOT(TrackAboutToEnd()));
|
|
|
|
connect(engine_.get(), SIGNAL(TrackEnded()), SLOT(TrackEnded()));
|
|
|
|
connect(engine_.get(), SIGNAL(MetaData(Engine::SimpleMetaBundle)),
|
2010-02-03 23:20:31 +01:00
|
|
|
SLOT(EngineMetadataReceived(Engine::SimpleMetaBundle)));
|
2010-02-03 22:48:00 +01:00
|
|
|
|
2010-04-12 01:24:03 +02:00
|
|
|
engine_->SetVolume(settings_.value("volume", 50).toInt());
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2010-02-03 17:51:56 +01:00
|
|
|
void Player::ReloadSettings() {
|
2010-04-12 01:03:39 +02:00
|
|
|
engine_->ReloadSettings();
|
2010-02-03 17:51:56 +01:00
|
|
|
}
|
|
|
|
|
2010-05-18 22:43:10 +02:00
|
|
|
void Player::HandleSpecialLoad(const PlaylistItem::SpecialLoadResult &result) {
|
|
|
|
switch (result.type_) {
|
|
|
|
case PlaylistItem::SpecialLoadResult::NoMoreTracks:
|
|
|
|
loading_async_ = QUrl();
|
|
|
|
NextItem(Engine::Auto);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PlaylistItem::SpecialLoadResult::TrackAvailable: {
|
|
|
|
// Might've been an async load, so check we're still on the same item
|
2010-05-20 23:21:55 +02:00
|
|
|
int current_index = playlists_->active()->current_index();
|
2010-05-18 22:43:10 +02:00
|
|
|
if (current_index == -1)
|
|
|
|
return;
|
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
shared_ptr<PlaylistItem> item = playlists_->active()->item_at(current_index);
|
2010-05-18 22:43:10 +02:00
|
|
|
if (!item || item->Url() != result.original_url_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
engine_->Play(result.media_url_, stream_change_type_);
|
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
current_item_ = item;
|
2010-05-18 22:43:10 +02:00
|
|
|
loading_async_ = QUrl();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PlaylistItem::SpecialLoadResult::WillLoadAsynchronously:
|
|
|
|
// We'll get called again later with either NoMoreTracks or TrackAvailable
|
|
|
|
loading_async_ = result.original_url_;
|
|
|
|
break;
|
|
|
|
}
|
2010-04-12 03:59:21 +02:00
|
|
|
}
|
|
|
|
|
2010-04-30 01:30:24 +02:00
|
|
|
void Player::Next() {
|
|
|
|
NextInternal(Engine::Manual);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::NextInternal(Engine::TrackChangeType change) {
|
2010-10-17 21:27:31 +02:00
|
|
|
if (change == Engine::Manual) {
|
|
|
|
emit TrackSkipped(current_item_);
|
|
|
|
}
|
|
|
|
|
2010-08-26 21:29:55 +02:00
|
|
|
if (playlists_->active()->stop_after_current()) {
|
|
|
|
playlists_->active()->StopAfter(-1);
|
|
|
|
Stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-21 00:30:55 +02:00
|
|
|
if (playlists_->active()->current_item() &&
|
|
|
|
playlists_->active()->current_item()->options() & PlaylistItem::ContainsMultipleTracks) {
|
2010-05-18 22:43:10 +02:00
|
|
|
// The next track is already being loaded
|
2010-05-20 23:21:55 +02:00
|
|
|
if (playlists_->active()->current_item()->Url() == loading_async_)
|
2010-05-18 22:43:10 +02:00
|
|
|
return;
|
|
|
|
|
2010-04-12 03:59:21 +02:00
|
|
|
stream_change_type_ = change;
|
2010-05-20 23:21:55 +02:00
|
|
|
HandleSpecialLoad(playlists_->active()->current_item()->LoadNext());
|
2009-12-29 21:48:50 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-08 19:39:12 +02:00
|
|
|
NextItem(change);
|
2010-02-04 00:12:21 +01:00
|
|
|
}
|
|
|
|
|
2010-04-12 03:59:21 +02:00
|
|
|
void Player::NextItem(Engine::TrackChangeType change) {
|
2010-05-20 23:21:55 +02:00
|
|
|
int i = playlists_->active()->next_index();
|
2009-12-24 20:16:07 +01:00
|
|
|
if (i == -1) {
|
2010-11-20 19:49:54 +01:00
|
|
|
playlists_->active()->set_current_index(i);
|
2010-04-19 15:01:57 +02:00
|
|
|
emit PlaylistFinished();
|
2009-12-24 20:16:07 +01:00
|
|
|
Stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-30 01:30:24 +02:00
|
|
|
PlayAt(i, change, false);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2009-12-26 23:59:11 +01:00
|
|
|
void Player::TrackEnded() {
|
2010-05-20 23:21:55 +02:00
|
|
|
if (playlists_->active()->stop_after_current()) {
|
2010-08-26 21:29:55 +02:00
|
|
|
playlists_->active()->StopAfter(-1);
|
2009-12-26 23:59:11 +01:00
|
|
|
Stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-30 01:30:24 +02:00
|
|
|
NextInternal(Engine::Auto);
|
2009-12-26 23:59:11 +01:00
|
|
|
}
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
void Player::PlayPause() {
|
|
|
|
switch (engine_->state()) {
|
|
|
|
case Engine::Paused:
|
2010-04-12 01:24:03 +02:00
|
|
|
engine_->Unpause();
|
2009-12-24 20:16:07 +01:00
|
|
|
break;
|
|
|
|
|
2010-05-27 15:17:28 +02:00
|
|
|
case Engine::Playing: {
|
2010-01-17 16:48:31 +01:00
|
|
|
// We really shouldn't pause last.fm streams
|
2010-05-27 15:17:28 +02:00
|
|
|
// Stopping seems like a reasonable thing to do (especially on mac where there
|
|
|
|
// is no media key for stop).
|
|
|
|
if (current_item_->options() & PlaylistItem::PauseDisabled) {
|
|
|
|
engine_->Stop();
|
|
|
|
} else {
|
|
|
|
engine_->Pause();
|
|
|
|
}
|
2009-12-24 20:16:07 +01:00
|
|
|
break;
|
2010-05-27 15:17:28 +02:00
|
|
|
}
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
case Engine::Empty:
|
|
|
|
case Engine::Idle: {
|
2010-05-21 12:29:17 +02:00
|
|
|
playlists_->SetActivePlaylist(playlists_->current_id());
|
2010-05-20 23:21:55 +02:00
|
|
|
if (playlists_->active()->rowCount() == 0)
|
2010-04-12 02:40:03 +02:00
|
|
|
break;
|
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
int i = playlists_->active()->current_index();
|
|
|
|
if (i == -1) i = playlists_->active()->last_played_index();
|
2010-04-12 02:40:03 +02:00
|
|
|
if (i == -1) i = 0;
|
|
|
|
|
2010-04-30 01:30:24 +02:00
|
|
|
PlayAt(i, Engine::First, true);
|
2009-12-24 20:16:07 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
|
|
|
|
if (mpris2_)
|
|
|
|
mpris2_->emitNotification("PlaybackStatus");
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Player::Stop() {
|
2010-04-12 01:24:03 +02:00
|
|
|
engine_->Stop();
|
2010-05-20 23:21:55 +02:00
|
|
|
playlists_->active()->set_current_index(-1);
|
|
|
|
current_item_.reset();
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Player::Previous() {
|
2010-05-20 23:21:55 +02:00
|
|
|
int i = playlists_->active()->previous_index();
|
|
|
|
playlists_->active()->set_current_index(i);
|
2009-12-24 20:16:07 +01:00
|
|
|
if (i == -1) {
|
|
|
|
Stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-30 01:30:24 +02:00
|
|
|
PlayAt(i, Engine::Manual, false);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Player::EngineStateChanged(Engine::State state) {
|
|
|
|
switch (state) {
|
|
|
|
case Engine::Paused: emit Paused(); break;
|
|
|
|
case Engine::Playing: emit Playing(); break;
|
|
|
|
case Engine::Empty:
|
|
|
|
case Engine::Idle: emit Stopped(); break;
|
|
|
|
}
|
2010-11-21 16:13:26 +01:00
|
|
|
if (mpris_) {
|
|
|
|
mpris_->EmitStatusChange(mpris_->GetStatus());
|
|
|
|
mpris_->EmitCapsChange(mpris_->GetCaps());
|
|
|
|
}
|
|
|
|
if (mpris2_) {
|
|
|
|
mpris2_->emitNotification("PlaybackStatus");
|
|
|
|
mpris2_->emitNotification("Metadata");
|
|
|
|
}
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Player::SetVolume(int value) {
|
2010-04-13 01:35:47 +02:00
|
|
|
int old_volume = engine_->volume();
|
|
|
|
|
2010-03-24 23:31:34 +01:00
|
|
|
int volume = qBound(0, value, 100);
|
2010-03-24 23:29:17 +01:00
|
|
|
settings_.setValue("volume", volume);
|
2010-04-12 01:24:03 +02:00
|
|
|
engine_->SetVolume(volume);
|
2010-04-13 01:35:47 +02:00
|
|
|
|
2010-11-21 16:13:26 +01:00
|
|
|
if (volume != old_volume){
|
2010-04-13 01:35:47 +02:00
|
|
|
emit VolumeChanged(volume);
|
2010-11-21 16:13:26 +01:00
|
|
|
if (mpris2_)
|
|
|
|
mpris2_->emitNotification("Volume");
|
|
|
|
}
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int Player::GetVolume() const {
|
|
|
|
return engine_->volume();
|
|
|
|
}
|
|
|
|
|
|
|
|
Engine::State Player::GetState() const {
|
|
|
|
return engine_->state();
|
|
|
|
}
|
|
|
|
|
2010-04-30 01:30:24 +02:00
|
|
|
void Player::PlayAt(int index, Engine::TrackChangeType change, bool reshuffle) {
|
|
|
|
if (reshuffle)
|
2010-05-20 23:21:55 +02:00
|
|
|
playlists_->active()->set_current_index(-1);
|
|
|
|
playlists_->active()->set_current_index(index);
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2010-11-20 19:49:54 +01:00
|
|
|
current_item_ = playlists_->active()->current_item();
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
if (current_item_->options() & PlaylistItem::SpecialPlayBehaviour) {
|
2010-05-18 22:43:10 +02:00
|
|
|
// It's already loading
|
2010-05-20 23:21:55 +02:00
|
|
|
if (current_item_->Url() == loading_async_)
|
2010-05-18 22:43:10 +02:00
|
|
|
return;
|
|
|
|
|
2010-06-12 22:22:58 +02:00
|
|
|
stream_change_type_ = change;
|
2010-05-20 23:21:55 +02:00
|
|
|
HandleSpecialLoad(current_item_->StartLoading());
|
2010-05-18 22:43:10 +02:00
|
|
|
}
|
2009-12-29 20:22:02 +01:00
|
|
|
else {
|
2010-05-18 22:43:10 +02:00
|
|
|
loading_async_ = QUrl();
|
2010-05-20 23:21:55 +02:00
|
|
|
engine_->Play(current_item_->Url(), change);
|
2009-12-29 21:48:50 +01:00
|
|
|
|
|
|
|
if (lastfm_->IsScrobblingEnabled())
|
2010-05-20 23:21:55 +02:00
|
|
|
lastfm_->NowPlaying(current_item_->Metadata());
|
2009-12-29 20:22:02 +01:00
|
|
|
}
|
2010-03-24 21:58:17 +01:00
|
|
|
|
2010-11-21 16:13:26 +01:00
|
|
|
if (mpris_) {
|
|
|
|
mpris_->EmitCapsChange(mpris_->GetCaps());
|
|
|
|
}
|
|
|
|
if (mpris2_) {
|
|
|
|
mpris2_->emitNotification("PlaybackStatus");
|
|
|
|
mpris2_->emitNotification("Metadata");
|
|
|
|
}
|
2009-12-26 22:35:45 +01:00
|
|
|
}
|
|
|
|
|
2010-11-21 16:13:26 +01:00
|
|
|
void Player::CurrentMetadataChanged(const Song& metadata) {
|
2010-03-08 00:28:40 +01:00
|
|
|
lastfm_->NowPlaying(metadata);
|
2010-11-21 16:13:26 +01:00
|
|
|
|
|
|
|
PlaylistItemPtr item = playlists_->active()->current_item();
|
|
|
|
if (mpris_)
|
|
|
|
mpris_->EmitTrackChange(mpris_->GetMetadata(item));
|
|
|
|
if (mpris2_)
|
|
|
|
mpris2_->UpdateMetadata(item);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
2010-01-15 18:12:47 +01:00
|
|
|
|
|
|
|
void Player::Seek(int seconds) {
|
2010-04-14 15:22:50 +02:00
|
|
|
int msec = qBound(0, seconds * 1000, int(engine_->length()));
|
|
|
|
engine_->Seek(msec);
|
2010-03-24 15:21:26 +01:00
|
|
|
|
|
|
|
// If we seek the track we don't want to submit it to last.fm
|
2010-05-20 23:21:55 +02:00
|
|
|
playlists_->active()->set_scrobbled(true);
|
2010-01-15 18:12:47 +01:00
|
|
|
}
|
2010-02-03 23:20:31 +01:00
|
|
|
|
|
|
|
void Player::EngineMetadataReceived(const Engine::SimpleMetaBundle& bundle) {
|
2010-11-21 16:13:26 +01:00
|
|
|
PlaylistItemPtr item = playlists_->active()->current_item();
|
2010-08-09 15:12:54 +02:00
|
|
|
if (!item)
|
2010-02-03 23:20:31 +01:00
|
|
|
return;
|
|
|
|
|
2010-07-10 21:51:34 +02:00
|
|
|
Engine::SimpleMetaBundle bundle_copy = bundle;
|
|
|
|
|
|
|
|
// Maybe the metadata is from icycast and has "Artist - Title" shoved
|
|
|
|
// together in the title field.
|
|
|
|
int dash_pos = bundle_copy.title.indexOf('-');
|
|
|
|
if (dash_pos != -1 && bundle_copy.artist.isEmpty()) {
|
|
|
|
bundle_copy.artist = bundle_copy.title.mid(dash_pos + 1).trimmed();
|
|
|
|
bundle_copy.title = bundle_copy.title.left(dash_pos).trimmed();
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:59:14 +02:00
|
|
|
// Hack as SomaFM's artist/title descriptions are backwards.
|
|
|
|
if (item->Url().host().contains("somafm.com")) {
|
|
|
|
qSwap(bundle_copy.artist, bundle_copy.title);
|
|
|
|
}
|
|
|
|
|
2010-04-21 16:04:40 +02:00
|
|
|
Song song = item->Metadata();
|
2010-07-10 21:51:34 +02:00
|
|
|
song.MergeFromSimpleMetaBundle(bundle_copy);
|
2010-02-03 23:20:31 +01:00
|
|
|
|
2010-02-04 00:56:41 +01:00
|
|
|
// Ignore useless metadata
|
|
|
|
if (song.title().isEmpty() && song.artist().isEmpty())
|
|
|
|
return;
|
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
playlists_->active()->SetStreamMetadata(item->Url(), song);
|
2010-02-03 23:20:31 +01:00
|
|
|
}
|
2010-03-24 21:58:17 +01:00
|
|
|
|
2010-11-21 16:13:26 +01:00
|
|
|
PlaylistItemPtr Player::GetItemAt(int pos) const {
|
|
|
|
if (pos < 0 || pos >= playlists_->active()->rowCount())
|
|
|
|
return PlaylistItemPtr();
|
|
|
|
return playlists_->active()->item_at(pos);
|
2010-03-24 21:58:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Player::Mute() {
|
2010-07-14 00:22:04 +02:00
|
|
|
const int current_volume = engine_->volume();
|
|
|
|
|
|
|
|
if (current_volume == 0) {
|
|
|
|
SetVolume(volume_before_mute_);
|
|
|
|
} else {
|
|
|
|
volume_before_mute_ = current_volume;
|
|
|
|
SetVolume(0);
|
|
|
|
}
|
2010-03-24 21:58:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Player::Pause() {
|
|
|
|
switch (GetState()) {
|
|
|
|
case Engine::Playing:
|
2010-04-12 01:24:03 +02:00
|
|
|
engine_->Pause();
|
2010-03-24 21:58:17 +01:00
|
|
|
break;
|
|
|
|
case Engine::Paused:
|
2010-06-08 18:00:09 +02:00
|
|
|
engine_->Unpause();
|
2010-03-24 21:58:17 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::Play() {
|
|
|
|
switch (GetState()) {
|
|
|
|
case Engine::Playing:
|
|
|
|
Seek(0);
|
|
|
|
break;
|
|
|
|
case Engine::Paused:
|
2010-04-12 01:24:03 +02:00
|
|
|
engine_->Unpause();
|
2010-03-24 21:58:17 +01:00
|
|
|
break;
|
|
|
|
default:
|
2010-04-13 22:22:29 +02:00
|
|
|
PlayPause();
|
2010-03-24 21:58:17 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::Prev() {
|
|
|
|
Previous();
|
|
|
|
}
|
|
|
|
|
|
|
|
int Player::PositionGet() const {
|
|
|
|
return engine_->position();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::Repeat(bool enable) {
|
2010-05-20 23:21:55 +02:00
|
|
|
playlists_->sequence()->SetRepeatMode(
|
2010-03-24 21:58:17 +01:00
|
|
|
enable ? PlaylistSequence::Repeat_Track : PlaylistSequence::Repeat_Off);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::ShowOSD() {
|
2010-05-20 23:21:55 +02:00
|
|
|
if (current_item_)
|
|
|
|
emit ForceShowOSD(current_item_->Metadata());
|
2010-03-24 21:58:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Player::VolumeDown(int change) {
|
|
|
|
SetVolume(GetVolume() - change);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::VolumeUp(int change) {
|
|
|
|
SetVolume(GetVolume() + change);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Player::VolumeGet() const {
|
|
|
|
return GetVolume();
|
|
|
|
}
|
|
|
|
|
|
|
|
int Player::AddTrack(const QString& track, bool play_now) {
|
2010-06-15 20:24:08 +02:00
|
|
|
playlists_->active()->InsertUrls(QList<QUrl>() << QUrl(track), play_now);
|
|
|
|
return 0;
|
2010-03-24 21:58:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Player::DelTrack(int index) {
|
2010-05-20 23:21:55 +02:00
|
|
|
playlists_->active()->removeRows(index, 1);
|
2010-03-24 21:58:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int Player::GetCurrentTrack() const {
|
2010-05-20 23:21:55 +02:00
|
|
|
return playlists_->active()->current_index();
|
2010-03-24 21:58:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int Player::GetLength() const {
|
2010-05-20 23:21:55 +02:00
|
|
|
return playlists_->active()->rowCount();
|
2010-03-24 21:58:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Player::SetLoop(bool enable) {
|
2010-05-20 23:21:55 +02:00
|
|
|
playlists_->active()->sequence()->SetRepeatMode(
|
2010-03-24 21:58:17 +01:00
|
|
|
enable ? PlaylistSequence::Repeat_Playlist : PlaylistSequence::Repeat_Off);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::SetRandom(bool enable) {
|
2010-05-20 23:21:55 +02:00
|
|
|
playlists_->active()->sequence()->SetShuffleMode(
|
2010-03-24 21:58:17 +01:00
|
|
|
enable ? PlaylistSequence::Shuffle_All : PlaylistSequence::Shuffle_Off);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Player::PlaylistChanged() {
|
2010-11-21 16:13:26 +01:00
|
|
|
if (mpris_)
|
|
|
|
mpris_->EmitTrackListChange(GetLength());
|
2010-03-24 21:58:17 +01:00
|
|
|
}
|
2010-04-21 15:55:30 +02:00
|
|
|
|
|
|
|
void Player::TrackAboutToEnd() {
|
|
|
|
if (engine_->is_autocrossfade_enabled()) {
|
|
|
|
// Crossfade is on, so just start playing the next track. The current one
|
|
|
|
// will fade out, and the new one will fade in
|
2010-04-30 01:30:24 +02:00
|
|
|
NextInternal(Engine::Auto);
|
2010-04-21 15:55:30 +02:00
|
|
|
} else {
|
|
|
|
// Crossfade is off, so start preloading the next track so we don't get a
|
|
|
|
// gap between songs.
|
2010-05-20 23:21:55 +02:00
|
|
|
if (current_item_->options() & PlaylistItem::ContainsMultipleTracks)
|
2010-04-21 15:55:30 +02:00
|
|
|
return;
|
2010-05-20 23:21:55 +02:00
|
|
|
if (playlists_->active()->next_index() == -1)
|
2010-04-21 19:11:02 +02:00
|
|
|
return;
|
2010-04-21 15:55:30 +02:00
|
|
|
|
2010-05-20 23:21:55 +02:00
|
|
|
shared_ptr<PlaylistItem> item = playlists_->active()->item_at(
|
|
|
|
playlists_->active()->next_index());
|
2010-04-21 15:55:30 +02:00
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
|
2010-05-18 22:43:10 +02:00
|
|
|
QUrl url = item->Url();
|
|
|
|
|
2010-05-18 16:30:55 +02:00
|
|
|
// Get the actual track URL rather than the stream URL.
|
|
|
|
if (item->options() & PlaylistItem::ContainsMultipleTracks) {
|
2010-05-18 22:43:10 +02:00
|
|
|
PlaylistItem::SpecialLoadResult result = item->LoadNext();
|
2010-05-19 15:08:52 +02:00
|
|
|
switch (result.type_) {
|
|
|
|
case PlaylistItem::SpecialLoadResult::NoMoreTracks:
|
2010-05-18 22:43:10 +02:00
|
|
|
return;
|
|
|
|
|
2010-05-19 15:08:52 +02:00
|
|
|
case PlaylistItem::SpecialLoadResult::WillLoadAsynchronously:
|
|
|
|
loading_async_ = item->Url();
|
|
|
|
return;
|
|
|
|
|
|
|
|
case PlaylistItem::SpecialLoadResult::TrackAvailable:
|
|
|
|
url = result.media_url_;
|
|
|
|
break;
|
|
|
|
}
|
2010-05-18 16:30:55 +02:00
|
|
|
}
|
2010-05-18 22:43:10 +02:00
|
|
|
engine_->StartPreloading(url);
|
2010-04-21 15:55:30 +02:00
|
|
|
}
|
|
|
|
}
|
2010-06-14 22:00:17 +02:00
|
|
|
|
|
|
|
void Player::MakeItRain(bool rain) {
|
|
|
|
const bool is_raining = rain_stream_ != -1;
|
|
|
|
if (rain && !is_raining) {
|
|
|
|
rain_stream_ = engine_->AddBackgroundStream(QUrl(kRainUrl));
|
|
|
|
}
|
|
|
|
if (!rain && is_raining) {
|
|
|
|
engine_->StopBackgroundStream(rain_stream_);
|
|
|
|
rain_stream_ = -1;
|
|
|
|
}
|
|
|
|
}
|
Fixes issu...
,'``.._ ,'``.
:,--._:)\,:,._,.: All Glory to
:`--,'' :`...';\ the HYPNO TOAD!
`,' `---' `.
/ :
/ \
,' :\.___,-.
`...,---'``````-..._ |: \
( ) ;: ) \ _,-.
`. ( // `' \
: `.// ) ) , ;
,-|`. _,'/ ) ) ,' ,'
( :`.`-..____..=:.-': . _,' ,'
`,'\ ``--....-)=' `._, \ ,') _ '``._
_.-/ _ `. (_) / )' ; / \ \`-.'
`--( `-:`. `' ___..' _,-' |/ `.)
`-. `.`.``-----``--, .'
|/`.\`' ,','); SSt
` (/ (/
2010-07-12 21:51:23 +02:00
|
|
|
|
|
|
|
void Player::AllHail(bool hypnotoad) {
|
|
|
|
const bool is_hailing = toad_stream_ != -1;
|
|
|
|
if (hypnotoad && !is_hailing) {
|
2010-07-14 13:16:56 +02:00
|
|
|
toad_stream_ = engine_->AllGloryToTheHypnotoad();
|
Fixes issu...
,'``.._ ,'``.
:,--._:)\,:,._,.: All Glory to
:`--,'' :`...';\ the HYPNO TOAD!
`,' `---' `.
/ :
/ \
,' :\.___,-.
`...,---'``````-..._ |: \
( ) ;: ) \ _,-.
`. ( // `' \
: `.// ) ) , ;
,-|`. _,'/ ) ) ,' ,'
( :`.`-..____..=:.-': . _,' ,'
`,'\ ``--....-)=' `._, \ ,') _ '``._
_.-/ _ `. (_) / )' ; / \ \`-.'
`--( `-:`. `' ___..' _,-' |/ `.)
`-. `.`.``-----``--, .'
|/`.\`' ,','); SSt
` (/ (/
2010-07-12 21:51:23 +02:00
|
|
|
}
|
|
|
|
if (!hypnotoad && is_hailing) {
|
|
|
|
engine_->StopBackgroundStream(toad_stream_);
|
|
|
|
toad_stream_ = -1;
|
|
|
|
}
|
|
|
|
}
|