2004-11-26 18:00:02 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-07 19:31:03 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2004-11-26 18:00:02 +00:00
|
|
|
*
|
2005-09-07 19:31:03 +00:00
|
|
|
* $RCSfile: soundplayer.cxx,v $
|
2004-11-26 18:00:02 +00:00
|
|
|
*
|
2008-03-07 16:02:53 +00:00
|
|
|
* $Revision: 1.11 $
|
2004-11-26 18:00:02 +00:00
|
|
|
*
|
2008-03-07 16:02:53 +00:00
|
|
|
* last change: $Author: kz $ $Date: 2008-03-07 17:02:53 $
|
2004-11-26 18:00:02 +00:00
|
|
|
*
|
2005-09-07 19:31:03 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2004-11-26 18:00:02 +00:00
|
|
|
*
|
|
|
|
*
|
2005-09-07 19:31:03 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2004-11-26 18:00:02 +00:00
|
|
|
*
|
2005-09-07 19:31:03 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2004-11-26 18:00:02 +00:00
|
|
|
*
|
2005-09-07 19:31:03 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2004-11-26 18:00:02 +00:00
|
|
|
*
|
2005-09-07 19:31:03 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2004-11-26 18:00:02 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 07:29:19 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_slideshow.hxx"
|
|
|
|
|
2004-11-26 18:00:02 +00:00
|
|
|
#include <canvas/debug.hxx>
|
|
|
|
#include <canvas/verbosetrace.hxx>
|
|
|
|
|
2006-12-13 14:20:54 +00:00
|
|
|
#include <comphelper/anytostring.hxx>
|
|
|
|
#include <cppuhelper/exc_hlp.hxx>
|
|
|
|
|
2004-11-26 18:00:02 +00:00
|
|
|
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
|
|
|
|
#include <com/sun/star/lang/NoSupportException.hpp>
|
|
|
|
#include <com/sun/star/lang/XComponent.hdl>
|
|
|
|
|
|
|
|
#include <tools/urlobj.hxx>
|
|
|
|
|
2008-03-07 16:02:53 +00:00
|
|
|
#include <avmedia/mediawindow.hxx>
|
|
|
|
|
2006-12-13 14:20:54 +00:00
|
|
|
#include "soundplayer.hxx"
|
|
|
|
|
2004-11-26 18:00:02 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
|
|
|
|
2006-12-13 14:20:54 +00:00
|
|
|
namespace slideshow
|
2004-11-26 18:00:02 +00:00
|
|
|
{
|
|
|
|
namespace internal
|
|
|
|
{
|
|
|
|
// TODO(Q3): Move the whole SoundPlayer class to avmedia.
|
|
|
|
|
2005-03-10 12:45:15 +00:00
|
|
|
boost::shared_ptr<SoundPlayer> SoundPlayer::create(
|
|
|
|
EventMultiplexer & rEventMultiplexer,
|
|
|
|
const ::rtl::OUString& rSoundURL,
|
|
|
|
const uno::Reference< uno::XComponentContext>& rComponentContext )
|
|
|
|
{
|
|
|
|
boost::shared_ptr<SoundPlayer> pPlayer(
|
|
|
|
new SoundPlayer( rEventMultiplexer,
|
|
|
|
rSoundURL,
|
|
|
|
rComponentContext ) );
|
|
|
|
rEventMultiplexer.addPauseHandler( pPlayer );
|
|
|
|
pPlayer->mThis = pPlayer;
|
|
|
|
return pPlayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SoundPlayer::handlePause( bool bPauseShow )
|
|
|
|
{
|
|
|
|
return bPauseShow ? stopPlayback() : startPlayback();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SoundPlayer::dispose()
|
|
|
|
{
|
2006-12-13 14:20:54 +00:00
|
|
|
if( mThis )
|
|
|
|
{
|
2005-03-10 12:45:15 +00:00
|
|
|
mrEventMultiplexer.removePauseHandler( mThis );
|
|
|
|
mThis.reset();
|
|
|
|
}
|
|
|
|
|
2006-12-13 14:20:54 +00:00
|
|
|
if( mxPlayer.is() )
|
|
|
|
{
|
2005-03-10 12:45:15 +00:00
|
|
|
mxPlayer->stop();
|
|
|
|
uno::Reference<lang::XComponent> xComponent(
|
|
|
|
mxPlayer, uno::UNO_QUERY );
|
2006-12-13 14:20:54 +00:00
|
|
|
if( xComponent.is() )
|
2005-03-10 12:45:15 +00:00
|
|
|
xComponent->dispose();
|
|
|
|
mxPlayer.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SoundPlayer::SoundPlayer(
|
|
|
|
EventMultiplexer & rEventMultiplexer,
|
|
|
|
const ::rtl::OUString& rSoundURL,
|
|
|
|
const uno::Reference< uno::XComponentContext>& rComponentContext )
|
|
|
|
: mrEventMultiplexer(rEventMultiplexer),
|
|
|
|
mThis(),
|
|
|
|
mxPlayer()
|
2004-11-26 18:00:02 +00:00
|
|
|
{
|
|
|
|
ENSURE_AND_THROW( rComponentContext.is(),
|
|
|
|
"SoundPlayer::SoundPlayer(): Invalid component context" );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2008-03-07 16:02:53 +00:00
|
|
|
const INetURLObject aURL( rSoundURL );
|
|
|
|
mxPlayer.set( avmedia::MediaWindow::createPlayer(
|
|
|
|
aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) ),
|
|
|
|
uno::UNO_QUERY);
|
2004-11-26 18:00:02 +00:00
|
|
|
}
|
2007-07-17 13:41:34 +00:00
|
|
|
catch( uno::RuntimeException& )
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
2004-11-26 18:00:02 +00:00
|
|
|
catch( uno::Exception& )
|
|
|
|
{
|
2007-08-17 11:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !mxPlayer.is() )
|
2005-03-10 12:45:15 +00:00
|
|
|
throw lang::NoSupportException(
|
|
|
|
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"No sound support for ") ) + rSoundURL,
|
|
|
|
uno::Reference<uno::XInterface>() );
|
2004-11-26 18:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SoundPlayer::~SoundPlayer()
|
|
|
|
{
|
2006-12-13 14:20:54 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
dispose();
|
|
|
|
}
|
|
|
|
catch (uno::Exception &) {
|
|
|
|
OSL_ENSURE( false, rtl::OUStringToOString(
|
|
|
|
comphelper::anyToString(
|
|
|
|
cppu::getCaughtException() ),
|
|
|
|
RTL_TEXTENCODING_UTF8 ).getStr() );
|
|
|
|
}
|
2004-11-26 18:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double SoundPlayer::getDuration() const
|
|
|
|
{
|
|
|
|
if( !mxPlayer.is() )
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
const double nDuration( mxPlayer->getDuration() );
|
|
|
|
if( mxPlayer->isPlaying() )
|
|
|
|
return ::std::max( 0.0,
|
|
|
|
nDuration - mxPlayer->getMediaTime() );
|
|
|
|
else
|
|
|
|
return nDuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SoundPlayer::startPlayback()
|
|
|
|
{
|
|
|
|
if( !mxPlayer.is() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( mxPlayer->isPlaying() )
|
|
|
|
mxPlayer->stop();
|
|
|
|
|
|
|
|
mxPlayer->start();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SoundPlayer::stopPlayback()
|
|
|
|
{
|
|
|
|
if( mxPlayer.is() )
|
|
|
|
mxPlayer->stop();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-06-27 14:50:15 +00:00
|
|
|
void SoundPlayer::setPlaybackLoop( bool bLoop )
|
|
|
|
{
|
|
|
|
if( mxPlayer.is() )
|
|
|
|
mxPlayer->setPlaybackLoop( bLoop );
|
|
|
|
}
|
2004-11-26 18:00:02 +00:00
|
|
|
}
|
|
|
|
}
|