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 <com/sun/star/lang/NoSupportException.hpp>
24 #include <com/sun/star/lang/XComponent.hpp>
26 #include <tools/urlobj.hxx>
28 #include <avmedia/mediawindow.hxx>
29 #include <mediafilemanager.hxx>
30 #include <soundplayer.hxx>
34 using namespace ::com::sun::star
;
37 namespace slideshow::internal
39 // TODO(Q3): Move the whole SoundPlayer class to avmedia.
41 std::shared_ptr
<SoundPlayer
> SoundPlayer::create(
42 EventMultiplexer
& rEventMultiplexer
,
43 const OUString
& rSoundURL
,
44 const uno::Reference
< uno::XComponentContext
>& rComponentContext
,
45 MediaFileManager
& rMediaFileManager
)
47 std::shared_ptr
<SoundPlayer
> pPlayer(
48 new SoundPlayer( rEventMultiplexer
,
52 rEventMultiplexer
.addPauseHandler( pPlayer
);
53 pPlayer
->mThis
= pPlayer
;
57 bool SoundPlayer::handlePause( bool bPauseShow
)
59 return bPauseShow
? stopPlayback() : startPlayback();
62 void SoundPlayer::dispose()
66 mrEventMultiplexer
.removePauseHandler( mThis
);
73 uno::Reference
<lang::XComponent
> xComponent(
74 mxPlayer
, uno::UNO_QUERY
);
76 xComponent
->dispose();
81 SoundPlayer::SoundPlayer(
82 EventMultiplexer
& rEventMultiplexer
,
83 const OUString
& rSoundURL
,
84 const uno::Reference
< uno::XComponentContext
>& rComponentContext
,
85 MediaFileManager
& rMediaFileManager
)
86 : mrEventMultiplexer(rEventMultiplexer
),
90 ENSURE_OR_THROW( rComponentContext
.is(),
91 "SoundPlayer::SoundPlayer(): Invalid component context" );
95 if (rSoundURL
.startsWithIgnoreAsciiCase("vnd.sun.star.Package:"))
97 mpMediaTempFile
= rMediaFileManager
.getMediaTempFile(rSoundURL
);
99 const INetURLObject
aURL( mpMediaTempFile
? mpMediaTempFile
->m_TempFileURL
: rSoundURL
);
100 mxPlayer
= avmedia::MediaWindow::createPlayer(
101 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 TOOLS_WARN_EXCEPTION( "slideshow", "" );
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
);
166 bool SoundPlayer::isPlaying() const
168 return mxPlayer
->isPlaying();
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */