2010-10-12 15:51:52 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2004-11-26 18:00:02 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 23:28:51 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2004-11-26 18:00:02 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2004-11-26 18:00:02 +00:00
|
|
|
*
|
2008-04-10 23:28:51 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2004-11-26 18:00:02 +00:00
|
|
|
*
|
2008-04-10 23:28:51 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2004-11-26 18:00:02 +00:00
|
|
|
*
|
2008-04-10 23:28:51 +00: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 18:00:02 +00:00
|
|
|
*
|
2008-04-10 23:28:51 +00: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 18:00:02 +00:00
|
|
|
*
|
2008-04-10 23:28:51 +00: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 18:00:02 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 07:29:19 +00:00
|
|
|
|
2004-11-26 18:00:02 +00:00
|
|
|
#include <canvas/debug.hxx>
|
2008-06-24 11:03:48 +00:00
|
|
|
#include <tools/diagnose_ex.h>
|
2004-11-26 18:00:02 +00:00
|
|
|
#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
|
|
|
{
|
2008-06-24 11:03:48 +00:00
|
|
|
ENSURE_OR_THROW( rComponentContext.is(),
|
2004-11-26 18:00:02 +00:00
|
|
|
"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 &) {
|
2011-03-12 11:41:23 +01:00
|
|
|
OSL_FAIL( rtl::OUStringToOString(
|
2006-12-13 14:20:54 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2010-10-12 15:51:52 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|