1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef INCLUDED_SLIDESHOW_SOUNDPLAYER_HXX 25 #define INCLUDED_SLIDESHOW_SOUNDPLAYER_HXX 26 27 #include <rtl/ustring.hxx> 28 29 #include <com/sun/star/uno/XComponentContext.hpp> 30 #include <com/sun/star/media/XManager.hpp> 31 #include <com/sun/star/media/XPlayer.hpp> 32 33 #include <boost/shared_ptr.hpp> 34 35 #include "pauseeventhandler.hxx" 36 #include "disposable.hxx" 37 #include "eventmultiplexer.hxx" 38 39 40 /* Definition of SoundPlayer class */ 41 42 namespace slideshow 43 { 44 namespace internal 45 { 46 /** Little class that plays a sound from a URL. 47 TODO: 48 Must be explicitly disposed (as long as enable_shared_ptr_from_this 49 isn't available)! 50 */ 51 class SoundPlayer : public PauseEventHandler, 52 public Disposable 53 { 54 public: 55 /** Create a sound player object. 56 57 @param rSoundURL 58 URL to a sound file. 59 60 @param rComponentContext 61 Reference to a component context, used to create the 62 needed services 63 64 @throws ::com::sun::star::lang::NoSupportException, if 65 the sound file is invalid, or not supported by the 66 player service. 67 */ 68 static ::boost::shared_ptr<SoundPlayer> create( 69 EventMultiplexer & rEventMultiplexer, 70 const ::rtl::OUString& rSoundURL, 71 const ::com::sun::star::uno::Reference< 72 ::com::sun::star::uno::XComponentContext>& rComponentContext ); 73 74 virtual ~SoundPlayer(); 75 76 /** Query duration of sound playback. 77 78 If the sound is already playing, this method 79 returns the remaining playback time. 80 81 @return the playback duration in seconds. 82 */ 83 double getDuration() const; 84 85 bool startPlayback(); 86 bool stopPlayback(); 87 88 void setPlaybackLoop( bool bLoop ); 89 90 // PauseEventHandler: 91 virtual bool handlePause( bool bPauseShow ); 92 93 // Disposable 94 virtual void dispose(); 95 96 private: 97 SoundPlayer( 98 EventMultiplexer & rEventMultiplexer, 99 const ::rtl::OUString& rSoundURL, 100 const ::com::sun::star::uno::Reference< 101 ::com::sun::star::uno::XComponentContext>& rComponentContext ); 102 103 EventMultiplexer & mrEventMultiplexer; 104 // TODO(Q3): obsolete when boost::enable_shared_ptr_from_this 105 // is available 106 ::boost::shared_ptr<SoundPlayer> mThis; 107 ::com::sun::star::uno::Reference< ::com::sun::star::media::XPlayer > mxPlayer; 108 }; 109 110 typedef ::boost::shared_ptr< SoundPlayer > SoundPlayerSharedPtr; 111 } 112 } 113 114 #endif /* INCLUDED_SLIDESHOW_SOUNDPLAYER_HXX */ 115