1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef INCLUDED_SLIDESHOW_SOUNDPLAYER_HXX
29 #define INCLUDED_SLIDESHOW_SOUNDPLAYER_HXX
30 
31 #include <rtl/ustring.hxx>
32 
33 #include <com/sun/star/uno/XComponentContext.hpp>
34 #include <com/sun/star/media/XManager.hpp>
35 #include <com/sun/star/media/XPlayer.hpp>
36 
37 #include <boost/shared_ptr.hpp>
38 
39 #include "pauseeventhandler.hxx"
40 #include "disposable.hxx"
41 #include "eventmultiplexer.hxx"
42 
43 
44 /* Definition of SoundPlayer class */
45 
46 namespace slideshow
47 {
48     namespace internal
49     {
50         /** Little class that plays a sound from a URL.
51             TODO:
52             Must be explicitly disposed (as long as enable_shared_ptr_from_this
53             isn't available)!
54          */
55         class SoundPlayer : public PauseEventHandler,
56                             public Disposable
57         {
58         public:
59             /** Create a sound player object.
60 
61             	@param rSoundURL
62                 URL to a sound file.
63 
64                 @param rComponentContext
65                 Reference to a component context, used to create the
66                 needed services
67 
68                 @throws ::com::sun::star::lang::NoSupportException, if
69                 the sound file is invalid, or not supported by the
70                 player service.
71              */
72             static ::boost::shared_ptr<SoundPlayer> create(
73                 EventMultiplexer & rEventMultiplexer,
74                 const ::rtl::OUString& rSoundURL,
75                 const ::com::sun::star::uno::Reference<
76                 ::com::sun::star::uno::XComponentContext>& rComponentContext );
77 
78             virtual ~SoundPlayer();
79 
80             /** Query duration of sound playback.
81 
82             	If the sound is already playing, this method
83             	returns the remaining playback time.
84 
85                 @return the playback duration in seconds.
86              */
87             double getDuration() const;
88 
89             bool startPlayback();
90             bool stopPlayback();
91 
92 			void setPlaybackLoop( bool bLoop );
93 
94             // PauseEventHandler:
95             virtual bool handlePause( bool bPauseShow );
96 
97             // Disposable
98             virtual void dispose();
99 
100         private:
101             SoundPlayer(
102                 EventMultiplexer & rEventMultiplexer,
103                 const ::rtl::OUString& rSoundURL,
104                 const ::com::sun::star::uno::Reference<
105                 ::com::sun::star::uno::XComponentContext>& rComponentContext );
106 
107             EventMultiplexer & mrEventMultiplexer;
108             // TODO(Q3): obsolete when boost::enable_shared_ptr_from_this
109             //           is available
110             ::boost::shared_ptr<SoundPlayer> mThis;
111             ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > mxPlayer;
112         };
113 
114         typedef ::boost::shared_ptr< SoundPlayer > SoundPlayerSharedPtr;
115     }
116 }
117 
118 #endif /* INCLUDED_SLIDESHOW_SOUNDPLAYER_HXX */
119