1 /* This file is part of the KDE project
2 Copyright (C) 2004-2006 Matthias Kretz <kretz@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
20 #include "audioplayer.h"
21 #include "mediaobject.h"
22 #include "audiopath.h"
23 #include "audiooutput.h"
29 class AudioPlayer::Private
42 void _k_stateChanged( Phonon::State
, Phonon::State
);
45 AudioPlayer::AudioPlayer( Phonon::Category category
, QObject
* parent
)
49 d
->output
= new AudioOutput( category
, this );
50 d
->path
= new AudioPath( this );
51 d
->path
->addOutput( d
->output
);
52 d
->player
= new MediaObject( this );
53 d
->player
->addAudioPath( d
->path
);
55 connect(d
->player
, SIGNAL(stateChanged(Phonon::State
, Phonon::State
)),
56 SLOT(_k_stateChanged(Phonon::State
, Phonon::State
)));
57 connect( d
->player
, SIGNAL( finished() ), SIGNAL( finished() ) );
60 AudioPlayer::~AudioPlayer()
67 void AudioPlayer::load( const KUrl
& url
)
70 d
->player
->setUrl( url
);
74 void AudioPlayer::play( const KUrl
& url
)
83 d
->player
->setUrl( url
);
85 if( ErrorState
== d
->player
->state() )
90 if( StoppedState
== d
->player
->state() )
94 void AudioPlayer::play()
99 void AudioPlayer::pause()
104 void AudioPlayer::stop()
109 qint64
AudioPlayer::totalTime() const
111 return d
->player
->totalTime();
114 qint64
AudioPlayer::currentTime() const
116 return d
->player
->currentTime();
119 void AudioPlayer::seek( qint64 ms
)
121 d
->player
->seek( ms
);
124 float AudioPlayer::volume() const
126 return d
->output
->volume();
129 void AudioPlayer::setVolume( float v
)
131 d
->output
->setVolume( v
);
134 bool AudioPlayer::isPlaying() const
136 return ( d
->player
->state() == PlayingState
);
139 bool AudioPlayer::isPaused() const
141 return ( d
->player
->state() == PausedState
);
144 void AudioPlayer::Private::_k_stateChanged( State ns
, State os
)
146 if( os
== LoadingState
&& ns
== StoppedState
)
152 #include "audioplayer.moc"