Commit 262b4c70 authored by Allan Sandfeld Jensen's avatar Allan Sandfeld Jensen

Add direct aKode backend.

FEATURE:

Note: This is mostly intended to be used together with soundservers like polypaudio,
jackd or ALSA's dmix, but can also be used for direct playback.

svn path=/trunk/kdemultimedia/juk/; revision=376452
parent 319350af
......@@ -4,6 +4,7 @@ check_PROGRAMS = tagguessertest
juk_SOURCES = \
advancedsearchdialog.cpp \
actioncollection.cpp \
akodeplayer.cpp \
artsplayer.cpp \
cache.cpp \
categoryreaderinterface.cpp \
......@@ -80,7 +81,7 @@ mblibs = -lmusicbrainz -ltunepimp
endif
##################################################
juk_LDADD = -lm $(LDADD_GST) $(mblibs) $(LIB_KIO) $(taglib_libs) $(LIB_KHTML) $(LIB_ARTS)
juk_LDADD = -lm $(LDADD_GST) $(mblibs) $(LIB_KIO) $(taglib_libs) $(LIB_KHTML) $(LIB_ARTS) ../akode/lib/libakode.la
juk_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LDFLAGS_GST)
tagguessertest_LDADD = $(LIB_KDECORE)
......
/***************************************************************************
copyright : (C) 2004 by Allan Sandfeld Jensen
email : kde@carewolf.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. *
* *
***************************************************************************/
#include <config.h>
#include <kdebug.h>
#include <qfile.h>
#include "../akode/lib/player.h"
#include "../akode/lib/decoder.h"
#include "akodeplayer.h"
using namespace aKode;
////////////////////////////////////////////////////////////////////////////////
// public methods
////////////////////////////////////////////////////////////////////////////////
aKodePlayer::aKodePlayer() : Player(),
m_player(0),
m_currentFile(0)
{}
aKodePlayer::~aKodePlayer()
{
delete m_player;
}
void aKodePlayer::play(const FileHandle &file)
{
kdDebug( 65432 ) << k_funcinfo << endl;
QString filename = file.absFilePath();
delete m_currentFile;
m_currentFile = qstrdup(filename.local8Bit());
kdDebug( 65432 ) << "Opening: " << file.absFilePath() << endl;
if (m_player)
m_player->stop();
else {
m_player = new aKode::Player();
m_player->open("auto");
}
if (m_player->load(m_currentFile))
m_player->play();
}
void aKodePlayer::pause()
{
if (m_player)
m_player->pause();
}
void aKodePlayer::stop()
{
if (m_player) {
m_player->stop();
m_player->unload();
}
}
void aKodePlayer::setVolume(float volume)
{
if (m_player)
m_player->setVolume(volume);
}
float aKodePlayer::volume() const
{
if (m_player)
return m_player->volume();
// 1.0 is full volume
return 1.0;
}
/////////////////////////////////////////////////////////////////////////////////
// m_player status functions
/////////////////////////////////////////////////////////////////////////////////
bool aKodePlayer::playing() const
{
if (m_player && m_player->decoder())
return !m_player->decoder()->eof();
else
return false;
}
bool aKodePlayer::paused() const
{
return false;
}
int aKodePlayer::totalTime() const
{
if (m_player) {
Decoder *d = m_player->decoder();
if (d)
return d->length() / 1000;
}
return -1;
}
int aKodePlayer::currentTime() const
{
if (m_player) {
Decoder *d = m_player->decoder();
if (d)
return d->position() / 1000;
}
return -1;
}
int aKodePlayer::position() const
{
if (m_player) {
Decoder *d = m_player->decoder();
if (d && d->length())
return (d->position()*1000)/(d->length());
else
return -1;
}
else
return -1;
}
/////////////////////////////////////////////////////////////////////////////////
// m_player seek functions
/////////////////////////////////////////////////////////////////////////////////
void aKodePlayer::seek(int seekTime)
{
// seek time in seconds?
if (m_player)
m_player->decoder()->seek(seekTime*1000);
}
void aKodePlayer::seekPosition(int position)
{
// position unit is 1/1000th
if (m_player)
m_player->decoder()->seek((position * m_player->decoder()->length())/1000);
}
#include "akodeplayer.moc"
/***************************************************************************
copyright : (C) 2004 by Allan Sandfeld Jensen
email : kde@carewolf.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. *
* *
***************************************************************************/
#ifndef AKODEPLAYER_H
#define AKODEPLAYER_H
#include <config.h>
#include <qstring.h>
#include "player.h"
namespace aKode {
class File;
class Player;
}
class aKodePlayer : public Player
{
Q_OBJECT
public:
aKodePlayer();
virtual ~aKodePlayer();
virtual void play(const FileHandle &file = FileHandle::null());
virtual void setVolume(float volume = 1.0);
virtual float volume() const;
virtual bool playing() const;
virtual bool paused() const;
virtual int totalTime() const;
virtual int currentTime() const;
virtual int position() const;
virtual void seek(int seekTime);
virtual void seekPosition(int position);
public slots:
void pause();
void stop();
private:
aKode::Player *m_player;
const char* m_currentFile;
};
#endif
......@@ -22,6 +22,7 @@
#include <math.h>
#include "artsplayer.h"
#include "akodeplayer.h"
#include "gstreamerplayer.h"
#include "playermanager.h"
#include "playlistinterface.h"
......@@ -43,38 +44,36 @@ enum PlayerManagerStatus { StatusStopped = -1, StatusPaused = 1, StatusPlaying =
// helper functions
////////////////////////////////////////////////////////////////////////////////
enum SoundSystem { ArtsBackend = 0, GStreamerBackend = 1 };
enum SoundSystem { AkodeBackend = 0, ArtsBackend = 1, GStreamerBackend = 2};
static Player *createPlayer(int system = ArtsBackend)
{
Player *p = 0;
#if HAVE_ARTS && HAVE_GSTREAMER
switch(system) {
case AkodeBackend:
p = new aKodePlayer;
break;
#if HAVE_ARTS
case ArtsBackend:
p = new ArtsPlayer;
break;
#endif
#if HAVE_GSTREAMER
case GStreamerBackend:
p = new GStreamerPlayer;
break;
#endif
default:
p = new ArtsPlayer;
break;
}
#else
Q_UNUSED(system)
#if HAVE_ARTS
p = new ArtsPlayer;
#endif
#if HAVE_GSTREAMER
p = new GStreamerPlayer;
p = new ArtsPlayer;
#elif defined(HAVE_GSTREAMER)
p = new GStreamerPlayer;
#else
#warning No Player Backend Available
#endif
p = new AkodePlayer;
#endif
break;
}
return p;
}
......@@ -149,7 +148,7 @@ int PlayerManager::status() const
if(player()->playing())
return StatusPlaying;
return 0;
}
......@@ -218,13 +217,15 @@ KSelectAction *PlayerManager::playerSelectAction(QObject *parent) // static
KSelectAction *action = 0;
action = new KSelectAction(i18n("&Output To"), 0, parent, "outputSelect");
QStringList l;
#if defined(HAVE_ARTS) && defined(HAVE_GSTREAMER)
l << i18n("aRts") << i18n("GStreamer");
action->setItems(l);
#else
Q_UNUSED(parent)
l << "aKode"
#if HAVE_ARTS
<< "aRts"
#endif
#if HAVE_GSTREAMER
<< "GStreamer"
#endif
;
action->setItems(l);
return action;
}
......@@ -588,11 +589,15 @@ void PlayerManager::setup()
this, SLOT(slotSetVolume(int)));
// Call this method manually to avoid warnings.
KAction *outputAction = actions()->action("outputSelect");
if(outputAction) {
int mediaSystem = static_cast<KSelectAction *>(outputAction)->currentItem();
#if (!HAVE_ARTS)
// Fix problem with position->enum
if (mediaSystem == ArtsBackend) mediaSystem = GStreamerBackend;
#endif
m_player = createPlayer(mediaSystem);
connect(outputAction, SIGNAL(activated(int)), this, SLOT(slotSetOutput(int)));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment