1
/*****************************************************************
3
Copyright (c) 2000-2001 the noatun authors. See file AUTHORS.
5
Permission is hereby granted, free of charge, to any person obtaining a copy
6
of this software and associated documentation files (the "Software"), to deal
7
in the Software without restriction, including without limitation the rights
8
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
copies of the Software, and to permit persons to whom the Software is
10
furnished to do so, subject to the following conditions:
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIAB\ILITY, WHETHER IN
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
******************************************************************/
32
#include <kmessagebox.h>
33
#include <kmimetype.h>
34
#include <kstandarddirs.h>
41
#include <dynamicrequest.h>
42
#include <flowsystem.h>
43
#include <kartsdispatcher.h>
44
#include <kartsserver.h>
45
#include <kplayobjectfactory.h>
46
#include <soundserver.h>
53
class Kaboodle::Engine::EnginePrivate
68
KDE::PlayObject *playobj;
69
KArtsDispatcher dispatcher;
74
Kaboodle::Engine::Engine(QObject *parent)
76
, d(new EnginePrivate)
80
Kaboodle::Engine::~Engine()
86
bool Kaboodle::Engine::load(const KURL &file)
88
if(file.path().length())
96
bool Kaboodle::Engine::reload(void)
98
// Only You can prevent memory leaks
102
KDE::PlayObjectFactory factory(d->server.server());
103
d->playobj = factory.createPlayObject(d->file, true);
107
return !d->playobj->isNull();
110
void Kaboodle::Engine::play()
114
switch(d->playobj->state())
121
case Arts::posPaused:
130
void Kaboodle::Engine::pause()
132
if(d->playobj && !d->playobj->isNull())
136
void Kaboodle::Engine::stop()
138
if(d->playobj && !d->playobj->isNull())
145
// pass time in msecs
146
void Kaboodle::Engine::seek(unsigned long msec)
150
t.ms = (long) msec % 1000;
151
t.seconds = (long) ((long)msec - t.ms) / 1000;
153
if(d->playobj && !d->playobj->isNull())
157
// return position in milliseconds
158
long Kaboodle::Engine::position()
160
if(!d->playobj || d->playobj->isNull()) return 0;
162
Arts::poTime time(d->playobj->currentTime());
163
return (time.ms + (time.seconds*1000));
166
// return track-length in milliseconds
167
unsigned long Kaboodle::Engine::length()
169
if(!d->playobj || d->playobj->isNull()) return 0;
171
Arts::poTime time(d->playobj->overallTime());
172
return (time.ms + (time.seconds*1000));
175
KMediaPlayer::Player::State Kaboodle::Engine::state()
177
if(!d->playobj || d->playobj->isNull()) return KMediaPlayer::Player::Empty;
179
switch(d->playobj->state())
182
return KMediaPlayer::Player::Stop;
184
case Arts::posPlaying:
185
return KMediaPlayer::Player::Play;
187
case Arts::posPaused:
188
return KMediaPlayer::Player::Pause;
191
return KMediaPlayer::Player::Stop;
196
bool Kaboodle::Engine::seekable(void)
198
if(!d->playobj || d->playobj->isNull()) return false;
199
return d->playobj->capabilities() & Arts::capSeek;
202
Arts::PlayObject Kaboodle::Engine::playObject() const
204
return d->playobj ? d->playobj->object() : Arts::PlayObject::null();
207
#include "engine.moc"