kpresenter

KPrSoundPlayer.cpp

00001 // -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
00002 /* This file is part of the KDE project
00003 
00004 base code from kaudioplayer.h, kaudioplayer.cpp
00005 Copyright (C) 2000 Stefan Westerfeld
00006 stefan@space.twc.de
00007 
00008 and konq_sound.h konq_sound.cc
00009 Copyright (c) 2001 Malte Starostik <malte@kde.org>
00010 
00011 This file's authors :
00012 Copyright (C) 2001 Toshitaka Fujioka <fujioka@kde.org>
00013 
00014 This library is free software; you can redistribute it and/or
00015 modify it under the terms of the GNU Library General Public
00016 License as published by the Free Software Foundation; either
00017 version 2 of the License, or (at your option) any later version.
00018 
00019 This library is distributed in the hope that it will be useful,
00020 but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022 Library General Public License for more details.
00023 
00024 You should have received a copy of the GNU Library General Public License
00025 along with this library; see the file COPYING.LIB.  If not, write to
00026 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00027  * Boston, MA 02110-1301, USA.
00028 */
00029 
00030 #include <config.h>
00031 
00032 #ifndef WITHOUT_ARTS
00033 #include <kartsdispatcher.h>
00034 #include <kplayobjectfactory.h>
00035 #include <soundserver.h>
00036 #endif
00037 
00038 #include <kdebug.h>
00039 
00040 #include "KPrSoundPlayer.h"
00041 
00042 using namespace std;
00043 
00044 class KPresenterSoundPlayerPrivate {
00045 public:
00046     QString fileName;
00047 
00048     KPresenterSoundPlayerPrivate( QString fileName ) : fileName( fileName ) {};
00049 
00050 #ifndef WITHOUT_ARTS
00051     KArtsDispatcher m_dispatche;
00052     Arts::SoundServerV2 m_soundServer;
00053     KPlayObjectFactory *m_factory;
00054     KPlayObject        *m_player;
00055 #endif
00056 };
00057 
00058 KPrSoundPlayer::KPrSoundPlayer( const QString &fileName, QObject *parent, const char *name )
00059     : QObject( parent, name )
00060 {
00061     d = new KPresenterSoundPlayerPrivate( fileName );
00062 
00063 #ifndef WITHOUT_ARTS
00064     d->m_soundServer = Arts::Reference( "global:Arts_SoundServerV2" );
00065     d->m_factory = new KPlayObjectFactory( d->m_soundServer );
00066     d->m_player = 0;
00067 #endif
00068 }
00069 
00070 KPrSoundPlayer::~KPrSoundPlayer()
00071 {
00072 #ifndef WITHOUT_ARTS
00073     delete d->m_player;
00074     delete d->m_factory;
00075 #endif
00076     delete d;
00077 }
00078 
00079 void KPrSoundPlayer::play( const QString &fileName )
00080 {
00081     KPrSoundPlayer sp( fileName );
00082     sp.play();
00083 }
00084 
00085 void KPrSoundPlayer::stop()
00086 {
00087 #ifndef WITHOUT_ARTS
00088     delete d->m_player;
00089     d->m_player = 0;
00090 #endif
00091 }
00092 
00093 void KPrSoundPlayer::play()
00094 {
00095 #ifndef WITHOUT_ARTS
00096     if ( d->m_soundServer.isNull() )
00097         return;
00098 
00099     delete d->m_player;
00100 
00101     d->m_player = d->m_factory->createPlayObject( d->fileName, true );
00102     if ( d->m_player ) {
00103         if ( d->m_player->object().isNull() )
00104             stop();
00105         else
00106             d->m_player->play();
00107     }
00108 #endif
00109 }
00110 
00111 #include "KPrSoundPlayer.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys