kpresenter

KPrSoundPlayer.cpp
1/* This file is part of the KDE project
2
3base code from kaudioplayer.h, kaudioplayer.cpp
4Copyright (C) 2000 Stefan Westerfeld
5stefan@space.twc.de
6
7and konq_sound.h konq_sound.cpp
8Copyright (c) 2001 Malte Starostik <malte@kde.org>
9
10This file's authors :
11Copyright (C) 2001 Toshitaka Fujioka <fujioka@kde.org>
12
13This library is free software; you can redistribute it and/or
14modify it under the terms of the GNU Library General Public
15License as published by the Free Software Foundation; either
16version 2 of the License, or (at your option) any later version.
17
18This library is distributed in the hope that it will be useful,
19but WITHOUT ANY WARRANTY; without even the implied warranty of
20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21Library General Public License for more details.
22
23You should have received a copy of the GNU Library General Public License
24along with this library; see the file COPYING.LIB. If not, write to
25the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 * Boston, MA 02110-1301, USA.
27*/
28
29#include <config.h>
30
31#ifndef WITHOUT_ARTS
32#include <kartsdispatcher.h>
33#include <kplayobjectfactory.h>
34#include <soundserver.h>
35#endif
36
37#include <kdebug.h>
38
39#include "KPrSoundPlayer.h"
40
41using namespace std;
42
43class KPresenterSoundPlayerPrivate {
44public:
45 TQString fileName;
46
47 KPresenterSoundPlayerPrivate( TQString fileName ) : fileName( fileName ) {};
48
49#ifndef WITHOUT_ARTS
50 KArtsDispatcher m_dispatche;
51 Arts::SoundServerV2 m_soundServer;
52 KPlayObjectFactory *m_factory;
53 KPlayObject *m_player;
54#endif
55};
56
57KPrSoundPlayer::KPrSoundPlayer( const TQString &fileName, TQObject *parent, const char *name )
58 : TQObject( parent, name )
59{
60 d = new KPresenterSoundPlayerPrivate( fileName );
61
62#ifndef WITHOUT_ARTS
63 d->m_soundServer = Arts::Reference( "global:Arts_SoundServerV2" );
64 d->m_factory = new KPlayObjectFactory( d->m_soundServer );
65 d->m_player = 0;
66#endif
67}
68
69KPrSoundPlayer::~KPrSoundPlayer()
70{
71#ifndef WITHOUT_ARTS
72 delete d->m_player;
73 delete d->m_factory;
74#endif
75 delete d;
76}
77
78void KPrSoundPlayer::play( const TQString &fileName )
79{
80 KPrSoundPlayer sp( fileName );
81 sp.play();
82}
83
84void KPrSoundPlayer::stop()
85{
86#ifndef WITHOUT_ARTS
87 delete d->m_player;
88 d->m_player = 0;
89#endif
90}
91
92void KPrSoundPlayer::play()
93{
94#ifndef WITHOUT_ARTS
95 if ( d->m_soundServer.isNull() )
96 return;
97
98 delete d->m_player;
99
100 d->m_player = d->m_factory->createPlayObject( d->fileName, true );
101 if ( d->m_player ) {
102 if ( d->m_player->object().isNull() )
103 stop();
104 else
105 d->m_player->play();
106 }
107#endif
108}
109
110#include "KPrSoundPlayer.moc"