1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <tools/diagnose_ex.h>
23 #include <comphelper/anytostring.hxx>
24 #include <cppuhelper/exc_hlp.hxx>
26 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
27 #include <com/sun/star/lang/NoSupportException.hpp>
28 #include <com/sun/star/lang/XComponent.hpp>
30 #include <tools/urlobj.hxx>
32 #include <avmedia/mediawindow.hxx>
34 #include <soundplayer.hxx>
38 using namespace ::com::sun::star
;
45 // TODO(Q3): Move the whole SoundPlayer class to avmedia.
47 std::shared_ptr
<SoundPlayer
> SoundPlayer::create(
48 EventMultiplexer
& rEventMultiplexer
,
49 const OUString
& rSoundURL
,
50 const uno::Reference
< uno::XComponentContext
>& rComponentContext
)
52 std::shared_ptr
<SoundPlayer
> pPlayer(
53 new SoundPlayer( rEventMultiplexer
,
55 rComponentContext
) );
56 rEventMultiplexer
.addPauseHandler( pPlayer
);
57 pPlayer
->mThis
= pPlayer
;
61 bool SoundPlayer::handlePause( bool bPauseShow
)
63 return bPauseShow
? stopPlayback() : startPlayback();
66 void SoundPlayer::dispose()
70 mrEventMultiplexer
.removePauseHandler( mThis
);
77 uno::Reference
<lang::XComponent
> xComponent(
78 mxPlayer
, uno::UNO_QUERY
);
80 xComponent
->dispose();
85 SoundPlayer::SoundPlayer(
86 EventMultiplexer
& rEventMultiplexer
,
87 const OUString
& rSoundURL
,
88 const uno::Reference
< uno::XComponentContext
>& rComponentContext
)
89 : mrEventMultiplexer(rEventMultiplexer
),
93 ENSURE_OR_THROW( rComponentContext
.is(),
94 "SoundPlayer::SoundPlayer(): Invalid component context" );
98 const INetURLObject
aURL( rSoundURL
);
99 mxPlayer
.set( avmedia::MediaWindow::createPlayer(
100 aURL
.GetMainURL( INetURLObject::DecodeMechanism::Unambiguous
), ""/*TODO!*/ ),
103 catch( uno::RuntimeException
& )
107 catch( uno::Exception
& )
112 throw lang::NoSupportException(
113 "No sound support for " + rSoundURL
);
116 SoundPlayer::~SoundPlayer()
122 catch (uno::Exception
&) {
123 SAL_WARN( "slideshow", comphelper::anyToString( cppu::getCaughtException() ) );
127 double SoundPlayer::getDuration() const
132 const double nDuration( mxPlayer
->getDuration() );
133 if( mxPlayer
->isPlaying() )
134 return ::std::max( 0.0,
135 nDuration
- mxPlayer
->getMediaTime() );
140 bool SoundPlayer::startPlayback()
145 if( mxPlayer
->isPlaying() )
152 bool SoundPlayer::stopPlayback()
160 void SoundPlayer::setPlaybackLoop( bool bLoop
)
163 mxPlayer
->setPlaybackLoop( bLoop
);
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */