2004-11-26 12:00:02 -06:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 18:28:51 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2004-11-26 12:00:02 -06:00
|
|
|
*
|
2010-02-12 08:01:35 -06:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2004-11-26 12:00:02 -06:00
|
|
|
*
|
2008-04-10 18:28:51 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2004-11-26 12:00:02 -06:00
|
|
|
*
|
2008-04-10 18:28:51 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2004-11-26 12:00:02 -06:00
|
|
|
*
|
2008-04-10 18:28:51 -05:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2004-11-26 12:00:02 -06:00
|
|
|
*
|
2008-04-10 18:28:51 -05:00
|
|
|
* OpenOffice.org 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 version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2004-11-26 12:00:02 -06:00
|
|
|
*
|
2008-04-10 18:28:51 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2004-11-26 12:00:02 -06:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 02:29:19 -05:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_slideshow.hxx"
|
|
|
|
|
2004-11-26 12:00:02 -06:00
|
|
|
#include <canvas/debug.hxx>
|
2008-06-24 06:03:48 -05:00
|
|
|
#include <tools/diagnose_ex.h>
|
2004-11-26 12:00:02 -06:00
|
|
|
#include <canvas/verbosetrace.hxx>
|
|
|
|
|
2006-12-13 08:20:54 -06:00
|
|
|
#include <comphelper/anytostring.hxx>
|
|
|
|
#include <cppuhelper/exc_hlp.hxx>
|
|
|
|
|
2004-11-26 12:00:02 -06: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 10:02:53 -06:00
|
|
|
#include <avmedia/mediawindow.hxx>
|
|
|
|
|
2006-12-13 08:20:54 -06:00
|
|
|
#include "soundplayer.hxx"
|
|
|
|
|
2004-11-26 12:00:02 -06:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
|
|
|
|
2006-12-13 08:20:54 -06:00
|
|
|
namespace slideshow
|
2004-11-26 12:00:02 -06:00
|
|
|
{
|
|
|
|
namespace internal
|
|
|
|
{
|
|
|
|
// TODO(Q3): Move the whole SoundPlayer class to avmedia.
|
|
|
|
|
2005-03-10 06:45:15 -06: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 08:20:54 -06:00
|
|
|
if( mThis )
|
|
|
|
{
|
2005-03-10 06:45:15 -06:00
|
|
|
mrEventMultiplexer.removePauseHandler( mThis );
|
|
|
|
mThis.reset();
|
|
|
|
}
|
|
|
|
|
2006-12-13 08:20:54 -06:00
|
|
|
if( mxPlayer.is() )
|
|
|
|
{
|
2005-03-10 06:45:15 -06:00
|
|
|
mxPlayer->stop();
|
|
|
|
uno::Reference<lang::XComponent> xComponent(
|
|
|
|
mxPlayer, uno::UNO_QUERY );
|
2006-12-13 08:20:54 -06:00
|
|
|
if( xComponent.is() )
|
2005-03-10 06:45:15 -06: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 12:00:02 -06:00
|
|
|
{
|
2008-06-24 06:03:48 -05:00
|
|
|
ENSURE_OR_THROW( rComponentContext.is(),
|
2004-11-26 12:00:02 -06:00
|
|
|
"SoundPlayer::SoundPlayer(): Invalid component context" );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2008-03-07 10:02:53 -06:00
|
|
|
const INetURLObject aURL( rSoundURL );
|
|
|
|
mxPlayer.set( avmedia::MediaWindow::createPlayer(
|
|
|
|
aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) ),
|
|
|
|
uno::UNO_QUERY);
|
2004-11-26 12:00:02 -06:00
|
|
|
}
|
2007-07-17 08:41:34 -05:00
|
|
|
catch( uno::RuntimeException& )
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
2004-11-26 12:00:02 -06:00
|
|
|
catch( uno::Exception& )
|
|
|
|
{
|
2007-08-17 06:43:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !mxPlayer.is() )
|
2005-03-10 06:45:15 -06:00
|
|
|
throw lang::NoSupportException(
|
|
|
|
rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"No sound support for ") ) + rSoundURL,
|
|
|
|
uno::Reference<uno::XInterface>() );
|
2004-11-26 12:00:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
SoundPlayer::~SoundPlayer()
|
|
|
|
{
|
2006-12-13 08:20:54 -06:00
|
|
|
try
|
|
|
|
{
|
|
|
|
dispose();
|
|
|
|
}
|
|
|
|
catch (uno::Exception &) {
|
|
|
|
OSL_ENSURE( false, rtl::OUStringToOString(
|
|
|
|
comphelper::anyToString(
|
|
|
|
cppu::getCaughtException() ),
|
|
|
|
RTL_TEXTENCODING_UTF8 ).getStr() );
|
|
|
|
}
|
2004-11-26 12:00:02 -06: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 09:50:15 -05:00
|
|
|
void SoundPlayer::setPlaybackLoop( bool bLoop )
|
|
|
|
{
|
|
|
|
if( mxPlayer.is() )
|
|
|
|
mxPlayer->setPlaybackLoop( bLoop );
|
|
|
|
}
|
2004-11-26 12:00:02 -06:00
|
|
|
}
|
|
|
|
}
|