1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: soundplayer.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_slideshow.hxx"
34 #include <canvas/debug.hxx>
35 #include <tools/diagnose_ex.h>
36 #include <canvas/verbosetrace.hxx>
38 #include <comphelper/anytostring.hxx>
39 #include <cppuhelper/exc_hlp.hxx>
41 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
42 #include <com/sun/star/lang/NoSupportException.hpp>
43 #include <com/sun/star/lang/XComponent.hdl>
45 #include <tools/urlobj.hxx>
47 #include <avmedia/mediawindow.hxx>
49 #include "soundplayer.hxx"
53 using namespace ::com::sun::star
;
60 // TODO(Q3): Move the whole SoundPlayer class to avmedia.
62 boost::shared_ptr
<SoundPlayer
> SoundPlayer::create(
63 EventMultiplexer
& rEventMultiplexer
,
64 const ::rtl::OUString
& rSoundURL
,
65 const uno::Reference
< uno::XComponentContext
>& rComponentContext
)
67 boost::shared_ptr
<SoundPlayer
> pPlayer(
68 new SoundPlayer( rEventMultiplexer
,
70 rComponentContext
) );
71 rEventMultiplexer
.addPauseHandler( pPlayer
);
72 pPlayer
->mThis
= pPlayer
;
76 bool SoundPlayer::handlePause( bool bPauseShow
)
78 return bPauseShow
? stopPlayback() : startPlayback();
81 void SoundPlayer::dispose()
85 mrEventMultiplexer
.removePauseHandler( mThis
);
92 uno::Reference
<lang::XComponent
> xComponent(
93 mxPlayer
, uno::UNO_QUERY
);
95 xComponent
->dispose();
100 SoundPlayer::SoundPlayer(
101 EventMultiplexer
& rEventMultiplexer
,
102 const ::rtl::OUString
& rSoundURL
,
103 const uno::Reference
< uno::XComponentContext
>& rComponentContext
)
104 : mrEventMultiplexer(rEventMultiplexer
),
108 ENSURE_OR_THROW( rComponentContext
.is(),
109 "SoundPlayer::SoundPlayer(): Invalid component context" );
113 const INetURLObject
aURL( rSoundURL
);
114 mxPlayer
.set( avmedia::MediaWindow::createPlayer(
115 aURL
.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS
) ),
118 catch( uno::RuntimeException
& )
122 catch( uno::Exception
& )
127 throw lang::NoSupportException(
128 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
129 "No sound support for ") ) + rSoundURL
,
130 uno::Reference
<uno::XInterface
>() );
133 SoundPlayer::~SoundPlayer()
139 catch (uno::Exception
&) {
140 OSL_ENSURE( false, rtl::OUStringToOString(
141 comphelper::anyToString(
142 cppu::getCaughtException() ),
143 RTL_TEXTENCODING_UTF8
).getStr() );
147 double SoundPlayer::getDuration() const
152 const double nDuration( mxPlayer
->getDuration() );
153 if( mxPlayer
->isPlaying() )
154 return ::std::max( 0.0,
155 nDuration
- mxPlayer
->getMediaTime() );
160 bool SoundPlayer::startPlayback()
165 if( mxPlayer
->isPlaying() )
172 bool SoundPlayer::stopPlayback()
180 void SoundPlayer::setPlaybackLoop( bool bLoop
)
183 mxPlayer
->setPlaybackLoop( bLoop
);