1f39251c4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3f39251c4SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4f39251c4SAndrew Rist * or more contributor license agreements. See the NOTICE file
5f39251c4SAndrew Rist * distributed with this work for additional information
6f39251c4SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7f39251c4SAndrew Rist * to you under the Apache License, Version 2.0 (the
8f39251c4SAndrew Rist * "License"); you may not use this file except in compliance
9f39251c4SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11f39251c4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13f39251c4SAndrew Rist * Unless required by applicable law or agreed to in writing,
14f39251c4SAndrew Rist * software distributed under the License is distributed on an
15f39251c4SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f39251c4SAndrew Rist * KIND, either express or implied. See the License for the
17f39251c4SAndrew Rist * specific language governing permissions and limitations
18f39251c4SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20f39251c4SAndrew Rist *************************************************************/
21f39251c4SAndrew Rist
22f39251c4SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir //_________________________________________________________________________________________________________________
25cdf0e10cSrcweir // my own includes
26cdf0e10cSrcweir //_________________________________________________________________________________________________________________
27cdf0e10cSrcweir
28cdf0e10cSrcweir #ifndef __FRAMEWORK_DISPATCH_SOUNDHANDLER_HXX_
29cdf0e10cSrcweir #include "soundhandler.hxx"
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir
32cdf0e10cSrcweir #ifndef __COMPHELPER_MEDIADESCRIPTOR_HXX_
33cdf0e10cSrcweir #include <comphelper/mediadescriptor.hxx>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir
36cdf0e10cSrcweir //_________________________________________________________________________________________________________________
37cdf0e10cSrcweir // interface includes
38cdf0e10cSrcweir //_________________________________________________________________________________________________________________
39cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
40cdf0e10cSrcweir #include <com/sun/star/frame/DispatchResultState.hpp>
41cdf0e10cSrcweir
42cdf0e10cSrcweir //_________________________________________________________________________________________________________________
43cdf0e10cSrcweir // includes of other projects
44cdf0e10cSrcweir //_________________________________________________________________________________________________________________
45cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx>
46cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
47cdf0e10cSrcweir
48cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
49cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
50*46880872SDamjan Jovanovic #include <cppuhelper/implementationentry.hxx>
51cdf0e10cSrcweir
52cdf0e10cSrcweir //_________________________________________________________________________________________________________________
53cdf0e10cSrcweir // namespace
54cdf0e10cSrcweir //_________________________________________________________________________________________________________________
55cdf0e10cSrcweir
56cdf0e10cSrcweir namespace avmedia{
57cdf0e10cSrcweir
58cdf0e10cSrcweir //_________________________________________________________________________________________________________________
59cdf0e10cSrcweir // non exported const
60cdf0e10cSrcweir //_________________________________________________________________________________________________________________
61cdf0e10cSrcweir
62cdf0e10cSrcweir //_________________________________________________________________________________________________________________
63cdf0e10cSrcweir // non exported definitions
64cdf0e10cSrcweir //_________________________________________________________________________________________________________________
65cdf0e10cSrcweir
66cdf0e10cSrcweir //_________________________________________________________________________________________________________________
67cdf0e10cSrcweir // declarations
68cdf0e10cSrcweir //_________________________________________________________________________________________________________________
69cdf0e10cSrcweir
70cdf0e10cSrcweir //*****************************************************************************************************************
71cdf0e10cSrcweir // XInterface, XTypeProvider, XServiceInfo
72cdf0e10cSrcweir //*****************************************************************************************************************
73cdf0e10cSrcweir
acquire()74cdf0e10cSrcweir void SAL_CALL SoundHandler::acquire() throw()
75cdf0e10cSrcweir {
76cdf0e10cSrcweir /* Don't use mutex in methods of XInterface! */
77cdf0e10cSrcweir OWeakObject::acquire();
78cdf0e10cSrcweir }
79cdf0e10cSrcweir
release()80cdf0e10cSrcweir void SAL_CALL SoundHandler::release() throw()
81cdf0e10cSrcweir {
82cdf0e10cSrcweir /* Don't use mutex in methods of XInterface! */
83cdf0e10cSrcweir OWeakObject::release();
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
queryInterface(const css::uno::Type & aType)86cdf0e10cSrcweir css::uno::Any SAL_CALL SoundHandler::queryInterface( const css::uno::Type& aType ) throw( css::uno::RuntimeException )
87cdf0e10cSrcweir {
888f79cfd8Smseidel /* Attention: Don't use mutex or guard in this method!!! It's a method of XInterface. */
89cdf0e10cSrcweir /* Ask for my own supported interfaces ...*/
90cdf0e10cSrcweir css::uno::Any aReturn( ::cppu::queryInterface( aType,
91cdf0e10cSrcweir static_cast< css::lang::XTypeProvider* >(this),
92cdf0e10cSrcweir static_cast< css::lang::XServiceInfo* >(this),
93cdf0e10cSrcweir static_cast< css::frame::XNotifyingDispatch* >(this),
94cdf0e10cSrcweir static_cast< css::frame::XDispatch* >(this),
95cdf0e10cSrcweir static_cast< css::document::XExtendedFilterDetection* >(this)));
96cdf0e10cSrcweir /* If searched interface not supported by this class ... */
97cdf0e10cSrcweir if ( aReturn.hasValue() == sal_False )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir /* ... ask baseclass for interfaces! */
100cdf0e10cSrcweir aReturn = OWeakObject::queryInterface( aType );
101cdf0e10cSrcweir }
102cdf0e10cSrcweir /* Return result of this search. */
103cdf0e10cSrcweir return aReturn;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir
getImplementationId()106cdf0e10cSrcweir css::uno::Sequence< sal_Int8 > SAL_CALL SoundHandler::getImplementationId() throw( css::uno::RuntimeException )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir /* Create one Id for all instances of this class. */
109cdf0e10cSrcweir /* Use ethernet address to do this! (sal_True) */
110cdf0e10cSrcweir /* Optimize this method */
111cdf0e10cSrcweir /* We initialize a static variable only one time. And we don't must use a mutex at every call! */
112cdf0e10cSrcweir /* For the first call; pID is NULL - for the second call pID is different from NULL! */
113cdf0e10cSrcweir static ::cppu::OImplementationId* pID = NULL ;
114cdf0e10cSrcweir if ( pID == NULL )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir /* Ready for multithreading; get global mutex for first call of this method only! see before */
117cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
118b12a77c9Smseidel /* Control these pointer again ... it can be, that another instance will be faster than these! */
119cdf0e10cSrcweir if ( pID == NULL )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir /* Create a new static ID ... */
122cdf0e10cSrcweir static ::cppu::OImplementationId aID( sal_False );
123cdf0e10cSrcweir /* ... and set his address to static pointer! */
124cdf0e10cSrcweir pID = &aID ;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir }
127cdf0e10cSrcweir return pID->getImplementationId();
128cdf0e10cSrcweir }
129cdf0e10cSrcweir
getTypes()130cdf0e10cSrcweir css::uno::Sequence< css::uno::Type > SAL_CALL SoundHandler::getTypes() throw( css::uno::RuntimeException )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir /* Optimize this method ! */
133cdf0e10cSrcweir /* We initialize a static variable only one time. */
134cdf0e10cSrcweir /* And we don't must use a mutex at every call! */
135cdf0e10cSrcweir /* For the first call; pTypeCollection is NULL - */
136cdf0e10cSrcweir /* for the second call pTypeCollection is different from NULL! */
137cdf0e10cSrcweir static ::cppu::OTypeCollection* pTypeCollection = NULL ;
138cdf0e10cSrcweir if ( pTypeCollection == NULL )
139cdf0e10cSrcweir {
140cdf0e10cSrcweir /* Ready for multithreading; get global mutex for first call of this method only! see before */
141cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
142b12a77c9Smseidel /* Control these pointer again ... it can be, that another instance will be faster than these! */
143cdf0e10cSrcweir if ( pTypeCollection == NULL )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir /* Create a static typecollection ... */
146cdf0e10cSrcweir static ::cppu::OTypeCollection aTypeCollection
147cdf0e10cSrcweir (
148cdf0e10cSrcweir ::getCppuType(( const ::com::sun::star::uno::Reference< css::lang::XTypeProvider >*)NULL ),
149cdf0e10cSrcweir ::getCppuType(( const ::com::sun::star::uno::Reference< css::lang::XServiceInfo >*)NULL ),
150cdf0e10cSrcweir ::getCppuType(( const ::com::sun::star::uno::Reference< css::frame::XNotifyingDispatch >*)NULL ),
151cdf0e10cSrcweir ::getCppuType(( const ::com::sun::star::uno::Reference< css::frame::XDispatch >*)NULL ),
152cdf0e10cSrcweir ::getCppuType(( const ::com::sun::star::uno::Reference< css::document::XExtendedFilterDetection >*)NULL )
153cdf0e10cSrcweir );
154cdf0e10cSrcweir /* ... and set his address to static pointer! */
155cdf0e10cSrcweir pTypeCollection = &aTypeCollection ;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir }
158cdf0e10cSrcweir return pTypeCollection->getTypes();
159cdf0e10cSrcweir }
160cdf0e10cSrcweir
161cdf0e10cSrcweir #define DECLARE_ASCII( SASCIIVALUE ) \
162cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
163cdf0e10cSrcweir
164cdf0e10cSrcweir #define IMPLEMENTATIONNAME_SOUNDHANDLER DECLARE_ASCII("com.sun.star.comp.framework.SoundHandler")
165cdf0e10cSrcweir #define SERVICENAME_CONTENTHANDLER DECLARE_ASCII("com.sun.star.frame.ContentHandler")
166cdf0e10cSrcweir
167cdf0e10cSrcweir /*===========================================================================================================*/
168cdf0e10cSrcweir /* XServiceInfo */
169cdf0e10cSrcweir /*===========================================================================================================*/
getImplementationName()170cdf0e10cSrcweir ::rtl::OUString SAL_CALL SoundHandler::getImplementationName() throw( css::uno::RuntimeException )
171cdf0e10cSrcweir {
172cdf0e10cSrcweir return impl_getStaticImplementationName();
173cdf0e10cSrcweir }
174cdf0e10cSrcweir
175cdf0e10cSrcweir /*===========================================================================================================*/
176cdf0e10cSrcweir /* XServiceInfo */
177cdf0e10cSrcweir /*===========================================================================================================*/
supportsService(const::rtl::OUString & sServiceName)178cdf0e10cSrcweir sal_Bool SAL_CALL SoundHandler::supportsService( const ::rtl::OUString& sServiceName ) throw( css::uno::RuntimeException )
179cdf0e10cSrcweir {
180cdf0e10cSrcweir /* Set default return value. */
181cdf0e10cSrcweir sal_Bool bReturn = sal_False ;
182cdf0e10cSrcweir /* Get names of all supported servicenames. */
183cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > seqServiceNames = getSupportedServiceNames();
184cdf0e10cSrcweir const ::rtl::OUString* pArray = seqServiceNames.getConstArray();
185cdf0e10cSrcweir sal_Int32 nCounter = 0;
186cdf0e10cSrcweir sal_Int32 nLength = seqServiceNames.getLength();
187cdf0e10cSrcweir /* Search for right name in list. */
188cdf0e10cSrcweir while (
189cdf0e10cSrcweir ( nCounter < nLength ) &&
190cdf0e10cSrcweir ( bReturn == sal_False )
191cdf0e10cSrcweir )
192cdf0e10cSrcweir {
1938f79cfd8Smseidel /* If name was found, say "YES, SERVICE IS SUPPORTED." and break loop. */
194cdf0e10cSrcweir if ( pArray[nCounter] == sServiceName )
195cdf0e10cSrcweir {
196cdf0e10cSrcweir bReturn = sal_True ;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir /* Else step to next element in list. */
199cdf0e10cSrcweir ++nCounter;
200cdf0e10cSrcweir }
201cdf0e10cSrcweir /* Return state of search. */
202cdf0e10cSrcweir return bReturn;
203cdf0e10cSrcweir }
204cdf0e10cSrcweir
205cdf0e10cSrcweir /*===========================================================================================================*/
206cdf0e10cSrcweir /* XServiceInfo */
207cdf0e10cSrcweir /*===========================================================================================================*/
getSupportedServiceNames()208cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL SoundHandler::getSupportedServiceNames() throw( css::uno::RuntimeException )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir return impl_getStaticSupportedServiceNames();
211cdf0e10cSrcweir }
212cdf0e10cSrcweir
213cdf0e10cSrcweir /*===========================================================================================================*/
214cdf0e10cSrcweir /* Helper for XServiceInfo */
215cdf0e10cSrcweir /*===========================================================================================================*/
impl_getStaticSupportedServiceNames()216cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SoundHandler::impl_getStaticSupportedServiceNames()
217cdf0e10cSrcweir {
218cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > seqServiceNames( 1 );
219cdf0e10cSrcweir seqServiceNames.getArray() [0] = SERVICENAME_CONTENTHANDLER;
220cdf0e10cSrcweir return seqServiceNames;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir
223cdf0e10cSrcweir /*===========================================================================================================*/
224cdf0e10cSrcweir /* Helper for XServiceInfo */
225cdf0e10cSrcweir /*===========================================================================================================*/
impl_getStaticImplementationName()226cdf0e10cSrcweir ::rtl::OUString SoundHandler::impl_getStaticImplementationName()
227cdf0e10cSrcweir {
228cdf0e10cSrcweir return IMPLEMENTATIONNAME_SOUNDHANDLER;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir
impl_createInstance(const css::uno::Reference<css::uno::XComponentContext> & xContext)231*46880872SDamjan Jovanovic css::uno::Reference< css::uno::XInterface > SAL_CALL SoundHandler::impl_createInstance( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw( css::uno::Exception )
232cdf0e10cSrcweir {
233cdf0e10cSrcweir /* create new instance of service */
234*46880872SDamjan Jovanovic SoundHandler* pClass = new SoundHandler( xContext );
235cdf0e10cSrcweir /* hold it alive by increasing his ref count!!! */
236cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > xService( static_cast< ::cppu::OWeakObject* >(pClass), css::uno::UNO_QUERY );
237cdf0e10cSrcweir /* initialize new service instance ... he can use his own refcount ... we hold it! */
238cdf0e10cSrcweir pClass->impl_initService();
239cdf0e10cSrcweir /* return new created service as reference */
240cdf0e10cSrcweir return xService;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir
243*46880872SDamjan Jovanovic static struct ::cppu::ImplementationEntry g_component_entries[] =
244cdf0e10cSrcweir {
245*46880872SDamjan Jovanovic {
246cdf0e10cSrcweir SoundHandler::impl_createInstance,
247*46880872SDamjan Jovanovic SoundHandler::impl_getStaticImplementationName,
248*46880872SDamjan Jovanovic SoundHandler::impl_getStaticSupportedServiceNames,
249*46880872SDamjan Jovanovic ::cppu::createSingleComponentFactory,
250*46880872SDamjan Jovanovic 0,
251*46880872SDamjan Jovanovic 0
252*46880872SDamjan Jovanovic },
253*46880872SDamjan Jovanovic { 0, 0, 0, 0, 0, 0 }
254*46880872SDamjan Jovanovic };
255cdf0e10cSrcweir
impl_initService()256cdf0e10cSrcweir void SAL_CALL SoundHandler::impl_initService()
257cdf0e10cSrcweir {
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
260cdf0e10cSrcweir
261cdf0e10cSrcweir /*-************************************************************************************************************//**
262cdf0e10cSrcweir @short standard ctor
263cdf0e10cSrcweir @descr These initialize a new instance of this class with needed informations for work.
264cdf0e10cSrcweir
265cdf0e10cSrcweir @seealso using at owner
266cdf0e10cSrcweir
267*46880872SDamjan Jovanovic @param "xContext", reference to component context for creation of new services
268cdf0e10cSrcweir @return -
269cdf0e10cSrcweir
270cdf0e10cSrcweir @onerror Show an assertion and do nothing else.
271cdf0e10cSrcweir @threadsafe yes
272cdf0e10cSrcweir *//*-*************************************************************************************************************/
SoundHandler(const css::uno::Reference<css::uno::XComponentContext> & xContext)273*46880872SDamjan Jovanovic SoundHandler::SoundHandler( const css::uno::Reference< css::uno::XComponentContext >& xContext )
274cdf0e10cSrcweir // Init baseclasses first
275cdf0e10cSrcweir : ThreadHelpBase ( )
276cdf0e10cSrcweir , ::cppu::OWeakObject ( )
277cdf0e10cSrcweir // Init member
278cdf0e10cSrcweir , m_bError ( false )
279*46880872SDamjan Jovanovic , m_xContext ( xContext )
280cdf0e10cSrcweir {
281cdf0e10cSrcweir m_aUpdateTimer.SetTimeoutHdl(LINK(this, SoundHandler, implts_PlayerNotify));
282cdf0e10cSrcweir }
283cdf0e10cSrcweir
284cdf0e10cSrcweir /*-************************************************************************************************************//**
285cdf0e10cSrcweir @short standard dtor
286cdf0e10cSrcweir @descr -
287cdf0e10cSrcweir
288cdf0e10cSrcweir @seealso -
289cdf0e10cSrcweir
290cdf0e10cSrcweir @param -
291cdf0e10cSrcweir @return -
292cdf0e10cSrcweir
293cdf0e10cSrcweir @onerror -
294cdf0e10cSrcweir @threadsafe -
295cdf0e10cSrcweir *//*-*************************************************************************************************************/
~SoundHandler()296cdf0e10cSrcweir SoundHandler::~SoundHandler()
297cdf0e10cSrcweir {
298cdf0e10cSrcweir if (m_xListener.is())
299cdf0e10cSrcweir {
300cdf0e10cSrcweir css::frame::DispatchResultEvent aEvent;
301cdf0e10cSrcweir aEvent.State = css::frame::DispatchResultState::FAILURE;
302cdf0e10cSrcweir m_xListener->dispatchFinished(aEvent);
303cdf0e10cSrcweir m_xListener = css::uno::Reference< css::frame::XDispatchResultListener >();
304cdf0e10cSrcweir }
305cdf0e10cSrcweir }
306cdf0e10cSrcweir
307cdf0e10cSrcweir /*-************************************************************************************************************//**
308cdf0e10cSrcweir @interface ::com::sun::star::frame::XDispatch
309cdf0e10cSrcweir
310cdf0e10cSrcweir @short try to load audio file
311cdf0e10cSrcweir @descr This method try to load given audio file by URL and play it. We use vcl/Sound class to do that.
312cdf0e10cSrcweir Playing of sound is asynchron every time.
313cdf0e10cSrcweir
314cdf0e10cSrcweir @attention We must hold us alive by ourself ... because we use async. vcl sound player ... but playing is started
3158f79cfd8Smseidel in async interface call "dispatch()" too. And caller forget us immediately. But then our uno ref count
316cdf0e10cSrcweir will decreased to 0 and will die. The only solution is to use own reference to our implementation.
31707a3d7f1SPedro Giffuni But we do it for really started jobs only and release it during call back of vcl.
318cdf0e10cSrcweir
319cdf0e10cSrcweir @seealso class vcl/Sound
320cdf0e10cSrcweir @seealso method implts_PlayerNotify()
321cdf0e10cSrcweir
322cdf0e10cSrcweir @param "aURL" , URL to dispatch.
323cdf0e10cSrcweir @param "lArguments", list of optional arguments.
324cdf0e10cSrcweir @return -
325cdf0e10cSrcweir
326cdf0e10cSrcweir @onerror We do nothing.
327cdf0e10cSrcweir @threadsafe yes
328cdf0e10cSrcweir *//*-*************************************************************************************************************/
dispatchWithNotification(const css::util::URL & aURL,const css::uno::Sequence<css::beans::PropertyValue> & lDescriptor,const css::uno::Reference<css::frame::XDispatchResultListener> & xListener)329cdf0e10cSrcweir void SAL_CALL SoundHandler::dispatchWithNotification(const css::util::URL& aURL ,
330cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >& lDescriptor,
331cdf0e10cSrcweir const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw(css::uno::RuntimeException)
332cdf0e10cSrcweir {
333cdf0e10cSrcweir // SAFE {
334cdf0e10cSrcweir const ::vos::OGuard aLock( m_aLock );
335cdf0e10cSrcweir
336cdf0e10cSrcweir {
337cdf0e10cSrcweir //close streams otherwise on windows we can't reopen the file in the
338cdf0e10cSrcweir //media player when we pass the url to directx as it'll already be open
339cdf0e10cSrcweir ::comphelper::MediaDescriptor aDescriptor(lDescriptor);
340cdf0e10cSrcweir
341cdf0e10cSrcweir css::uno::Reference< css::io::XInputStream > xInputStream =
342cdf0e10cSrcweir aDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_INPUTSTREAM(),
343cdf0e10cSrcweir css::uno::Reference< css::io::XInputStream >());
344cdf0e10cSrcweir if (xInputStream.is()) xInputStream->closeInput();
345cdf0e10cSrcweir }
346cdf0e10cSrcweir
347cdf0e10cSrcweir // If player currently used for other dispatch() requests ...
348cdf0e10cSrcweir // cancel it by calling stop()!
349cdf0e10cSrcweir m_aUpdateTimer.Stop();
350cdf0e10cSrcweir if (m_xPlayer.is())
351cdf0e10cSrcweir {
352cdf0e10cSrcweir if (m_xPlayer->isPlaying())
353cdf0e10cSrcweir m_xPlayer->stop();
354cdf0e10cSrcweir m_xPlayer.clear();
355cdf0e10cSrcweir }
356cdf0e10cSrcweir
357cdf0e10cSrcweir // Try to initialize player.
358cdf0e10cSrcweir m_xListener = xListener;
359cdf0e10cSrcweir try
360cdf0e10cSrcweir {
361cdf0e10cSrcweir m_bError = false;
362cdf0e10cSrcweir m_xPlayer.set( avmedia::MediaWindow::createPlayer( aURL.Complete ), css::uno::UNO_QUERY_THROW );
363cdf0e10cSrcweir // OK- we can start async playing ...
36430acf5e8Spfg // Count this request and initialize self-holder against dying by uno ref count ...
365cdf0e10cSrcweir m_xSelfHold = css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY);
366cdf0e10cSrcweir m_xPlayer->start();
367cdf0e10cSrcweir m_aUpdateTimer.SetTimeout( 200 );
368cdf0e10cSrcweir m_aUpdateTimer.Start();
369cdf0e10cSrcweir }
370cdf0e10cSrcweir catch( css::uno::Exception& e )
371cdf0e10cSrcweir {
372cdf0e10cSrcweir m_bError = true;
373cdf0e10cSrcweir (void)e;
374cdf0e10cSrcweir m_xPlayer.clear();
375cdf0e10cSrcweir }
376cdf0e10cSrcweir
377cdf0e10cSrcweir // } SAFE
378cdf0e10cSrcweir }
379cdf0e10cSrcweir
dispatch(const css::util::URL & aURL,const css::uno::Sequence<css::beans::PropertyValue> & lArguments)380cdf0e10cSrcweir void SAL_CALL SoundHandler::dispatch( const css::util::URL& aURL ,
381cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) throw( css::uno::RuntimeException )
382cdf0e10cSrcweir {
383cdf0e10cSrcweir dispatchWithNotification(aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >());
384cdf0e10cSrcweir }
385cdf0e10cSrcweir
386cdf0e10cSrcweir /*-************************************************************************************************************//**
387cdf0e10cSrcweir @interface ::com::sun::star::document::XExtendedFilterDetection
388cdf0e10cSrcweir
389cdf0e10cSrcweir @short try to detect file (given as argument included in "lDescriptor")
390cdf0e10cSrcweir @descr We try to detect, if given file could be handled by this class and is a well known one.
391cdf0e10cSrcweir If it is - we return right internal type name - otherwise we return nothing!
392cdf0e10cSrcweir So call can search for another detect service and ask him too.
393cdf0e10cSrcweir
394cdf0e10cSrcweir @attention a) We don't need any mutex here ... because we don't use any member!
3959f813b30Smseidel b) Don't use internal player instance "m_pPlayer" to detect given sound file!
39607a3d7f1SPedro Giffuni It's not necessary to do that ... and we can use temp. variable to do the same.
397cdf0e10cSrcweir This way is easy - we don't must synchronize it with currently played sounds!
398cdf0e10cSrcweir Another reason to do so ... We are a listener on our internal ma_Player object.
399cdf0e10cSrcweir If you would call "IsSoundFile()" on this instance, he would call us back and
4008f79cfd8Smseidel we make some unnecessary things ...
401cdf0e10cSrcweir
402cdf0e10cSrcweir @seealso -
403cdf0e10cSrcweir
404cdf0e10cSrcweir @param "lDescriptor", description of file to detect
405cdf0e10cSrcweir @return Internal type name which match this file ... or nothing if it is unknown.
406cdf0e10cSrcweir
407cdf0e10cSrcweir @onerror We return nothing.
408cdf0e10cSrcweir @threadsafe yes
409cdf0e10cSrcweir *//*-*************************************************************************************************************/
detect(css::uno::Sequence<css::beans::PropertyValue> & lDescriptor)410cdf0e10cSrcweir ::rtl::OUString SAL_CALL SoundHandler::detect( css::uno::Sequence< css::beans::PropertyValue >& lDescriptor ) throw( css::uno::RuntimeException )
411cdf0e10cSrcweir {
4128f79cfd8Smseidel // Our default is "nothing". So we can return it, if detection failed or file type is really unknown.
413cdf0e10cSrcweir ::rtl::OUString sTypeName;
414cdf0e10cSrcweir
415cdf0e10cSrcweir // Analyze given descriptor to find filename or input stream or ...
416cdf0e10cSrcweir ::comphelper::MediaDescriptor aDescriptor(lDescriptor);
417cdf0e10cSrcweir ::rtl::OUString sURL = aDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_URL(), ::rtl::OUString());
418cdf0e10cSrcweir
419cdf0e10cSrcweir if (
420144e4e62SHerbert Dürr !sURL.isEmpty() &&
421cdf0e10cSrcweir (avmedia::MediaWindow::isMediaURL(sURL))
422cdf0e10cSrcweir )
423cdf0e10cSrcweir {
424cdf0e10cSrcweir // If the file type is supported depends on the OS, so...
425cdf0e10cSrcweir // I think we can the following ones:
426cdf0e10cSrcweir // a) look for given extension of url to map our type decision HARD CODED!!!
427cdf0e10cSrcweir // b) return preferred type every time... it's easy :-)
428cdf0e10cSrcweir sTypeName = ::rtl::OUString::createFromAscii("wav_Wave_Audio_File");
429cdf0e10cSrcweir aDescriptor[::comphelper::MediaDescriptor::PROP_TYPENAME()] <<= sTypeName;
430cdf0e10cSrcweir aDescriptor >> lDescriptor;
431cdf0e10cSrcweir }
432cdf0e10cSrcweir
433cdf0e10cSrcweir // Return our decision.
434cdf0e10cSrcweir return sTypeName;
435cdf0e10cSrcweir }
436cdf0e10cSrcweir
437cdf0e10cSrcweir /*-************************************************************************************************************//**
438cdf0e10cSrcweir @short call back of sound player
439cdf0e10cSrcweir @descr Our player call us back to give us some informations.
4409f813b30Smseidel We use these informations to callback our might existing listener.
441cdf0e10cSrcweir
442cdf0e10cSrcweir @seealso method dispatchWithNotification()
443cdf0e10cSrcweir
444cdf0e10cSrcweir @param -
44507a3d7f1SPedro Giffuni @return 0 every time ... it doesn't matter for us.
446cdf0e10cSrcweir
447cdf0e10cSrcweir @onerror -
448cdf0e10cSrcweir @threadsafe yes
449cdf0e10cSrcweir *//*-*************************************************************************************************************/
IMPL_LINK(SoundHandler,implts_PlayerNotify,void *,EMPTYARG)450cdf0e10cSrcweir IMPL_LINK( SoundHandler, implts_PlayerNotify, void*, EMPTYARG )
451cdf0e10cSrcweir {
452cdf0e10cSrcweir // SAFE {
453cdf0e10cSrcweir ::vos::OClearableGuard aLock( m_aLock );
454cdf0e10cSrcweir
455cdf0e10cSrcweir if (m_xPlayer.is() && m_xPlayer->isPlaying() && m_xPlayer->getMediaTime() < m_xPlayer->getDuration())
456cdf0e10cSrcweir {
457cdf0e10cSrcweir m_aUpdateTimer.Start();
458cdf0e10cSrcweir return 0L;
459cdf0e10cSrcweir }
460cdf0e10cSrcweir m_xPlayer.clear();
461cdf0e10cSrcweir
462cdf0e10cSrcweir // We use m_xSelfHold to let us die ... but we must live till real finishing of this method too!!!
463cdf0e10cSrcweir // So we SHOULD use another "self-holder" temp. to provide that ...
464cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > xOperationHold = m_xSelfHold;
465cdf0e10cSrcweir m_xSelfHold = css::uno::Reference< css::uno::XInterface >();
466cdf0e10cSrcweir
467cdf0e10cSrcweir // notify might existing listener
468cdf0e10cSrcweir // And forget this listener!
469cdf0e10cSrcweir // Because the corresponding dispatch was finished.
470cdf0e10cSrcweir if (m_xListener.is())
471cdf0e10cSrcweir {
472cdf0e10cSrcweir css::frame::DispatchResultEvent aEvent;
473cdf0e10cSrcweir if (!m_bError)
474cdf0e10cSrcweir aEvent.State = css::frame::DispatchResultState::SUCCESS;
475cdf0e10cSrcweir else
476cdf0e10cSrcweir aEvent.State = css::frame::DispatchResultState::FAILURE;
477cdf0e10cSrcweir m_xListener->dispatchFinished(aEvent);
478cdf0e10cSrcweir m_xListener = css::uno::Reference< css::frame::XDispatchResultListener >();
479cdf0e10cSrcweir }
480cdf0e10cSrcweir
481cdf0e10cSrcweir // } SAFE
482cdf0e10cSrcweir //release aLock before end of method at which point xOperationHold goes out of scope and pThis dies
483cdf0e10cSrcweir aLock.clear();
484cdf0e10cSrcweir return 0;
485cdf0e10cSrcweir }
486cdf0e10cSrcweir
487cdf0e10cSrcweir } // namespace framework
488cdf0e10cSrcweir
489cdf0e10cSrcweir // ------------------------------------------
490cdf0e10cSrcweir // - component_getImplementationEnvironment -
491cdf0e10cSrcweir // ------------------------------------------
492cdf0e10cSrcweir
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)493deb7b1c2Sdamjan extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ )
494cdf0e10cSrcweir {
495cdf0e10cSrcweir *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
496cdf0e10cSrcweir }
497cdf0e10cSrcweir
498cdf0e10cSrcweir // ------------------------
499cdf0e10cSrcweir // - component_getFactory -
500cdf0e10cSrcweir // ------------------------
501cdf0e10cSrcweir
component_getFactory(const sal_Char * pImplementationName,void * pServiceManager,void * pRegistryKey)502*46880872SDamjan Jovanovic extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(const sal_Char* pImplementationName, void* pServiceManager, void* pRegistryKey )
503cdf0e10cSrcweir {
504*46880872SDamjan Jovanovic return ::cppu::component_getFactoryHelper( pImplementationName, pServiceManager, pRegistryKey, avmedia::g_component_entries );
505cdf0e10cSrcweir }
506