1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mediawindowbase_impl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "mediawindowbase_impl.hxx"
32 #include <avmedia/mediaitem.hxx>
33 #include "mediamisc.hxx"
34 #include "mediawindow.hrc"
35 #include <tools/urlobj.hxx>
36 #include <comphelper/processfactory.hxx>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/media/XManager.hpp>
39 #ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HDL_
40 #include <com/sun/star/lang/XComponent.hdl>
43 #define MEDIA_TIMER_TIMEOUT 100
45 using namespace ::com::sun::star
;
47 namespace avmedia
{ namespace priv
{
49 // -----------------------
50 // - MediaWindowBaseImpl -
51 // -----------------------
53 MediaWindowBaseImpl::MediaWindowBaseImpl( MediaWindow
* pMediaWindow
) :
54 mpMediaWindow( pMediaWindow
)
58 // ---------------------------------------------------------------------
60 MediaWindowBaseImpl::~MediaWindowBaseImpl()
62 uno::Reference
< lang::XMultiServiceFactory
> xFactory( ::comphelper::getProcessServiceFactory() );
65 // -------------------------------------------------------------------------
67 uno::Reference
< media::XPlayer
> MediaWindowBaseImpl::createPlayer( const ::rtl::OUString
& rURL
)
69 uno::Reference
< lang::XMultiServiceFactory
> xFactory( ::comphelper::getProcessServiceFactory() );
70 uno::Reference
< media::XPlayer
> xPlayer
;
77 uno::Reference
< ::com::sun::star::media::XManager
> xManager(
78 xFactory
->createInstance( ::rtl::OUString::createFromAscii( AVMEDIA_MANAGER_SERVICE_NAME
) ),
83 xPlayer
= uno::Reference
< ::com::sun::star::media::XPlayer
>(
84 xManager
->createPlayer( rURL
), uno::UNO_QUERY
);
96 // ---------------------------------------------------------------------
98 void MediaWindowBaseImpl::setURL( const ::rtl::OUString
& rURL
)
100 if( rURL
!= getURL() )
102 INetURLObject
aURL( maFileURL
= rURL
);
107 if( mxPlayerWindow
.is() )
109 mxPlayerWindow
->setVisible( false );
110 mxPlayerWindow
.clear();
115 if( aURL
.GetProtocol() != INET_PROT_NOT_VALID
)
116 maFileURL
= aURL
.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS
);
118 mxPlayer
= createPlayer( maFileURL
);
123 // ---------------------------------------------------------------------
125 void MediaWindowBaseImpl::onURLChanged()
129 // ---------------------------------------------------------------------
131 const ::rtl::OUString
& MediaWindowBaseImpl::getURL() const
136 // ---------------------------------------------------------------------
138 bool MediaWindowBaseImpl::isValid() const
140 return( getPlayer().is() );
143 // ---------------------------------------------------------------------
145 void MediaWindowBaseImpl::stopPlayingInternal( bool bStop
)
156 // ---------------------------------------------------------------------
158 MediaWindow
* MediaWindowBaseImpl::getMediaWindow() const
160 return mpMediaWindow
;
163 // ---------------------------------------------------------------------
165 uno::Reference
< media::XPlayer
> MediaWindowBaseImpl::getPlayer() const
170 // ---------------------------------------------------------------------
172 uno::Reference
< media::XPlayerWindow
> MediaWindowBaseImpl::getPlayerWindow() const
174 return mxPlayerWindow
;
177 // ---------------------------------------------------------------------
179 void MediaWindowBaseImpl::setPlayerWindow( const uno::Reference
< media::XPlayerWindow
>& rxPlayerWindow
)
181 mxPlayerWindow
= rxPlayerWindow
;
184 // ---------------------------------------------------------------------
186 void MediaWindowBaseImpl::cleanUp()
192 uno::Reference
< lang::XComponent
> xComponent( mxPlayer
, uno::UNO_QUERY
);
194 if( xComponent
.is() )
195 xComponent
->dispose();
200 mpMediaWindow
= NULL
;
203 // ---------------------------------------------------------------------
205 bool MediaWindowBaseImpl::hasPreferredSize() const
207 return( mxPlayerWindow
.is() );
210 // ---------------------------------------------------------------------
212 Size
MediaWindowBaseImpl::getPreferredSize() const
218 awt::Size
aPrefSize( mxPlayer
->getPreferredPlayerWindowSize() );
220 aRet
.Width() = aPrefSize
.Width
;
221 aRet
.Height() = aPrefSize
.Height
;
227 // ---------------------------------------------------------------------
229 bool MediaWindowBaseImpl::setZoom( ::com::sun::star::media::ZoomLevel eLevel
)
231 return( mxPlayerWindow
.is() ? mxPlayerWindow
->setZoomLevel( eLevel
) : false );
234 // -------------------------------------------------------------------------
236 ::com::sun::star::media::ZoomLevel
MediaWindowBaseImpl::getZoom() const
238 return( mxPlayerWindow
.is() ? mxPlayerWindow
->getZoomLevel() : ::com::sun::star::media::ZoomLevel_NOT_AVAILABLE
);
241 // ---------------------------------------------------------------------
243 bool MediaWindowBaseImpl::start()
245 return( mxPlayer
.is() ? ( mxPlayer
->start(), true ) : false );
248 // ---------------------------------------------------------------------
250 void MediaWindowBaseImpl::stop()
256 // ---------------------------------------------------------------------
258 bool MediaWindowBaseImpl::isPlaying() const
260 return( mxPlayer
.is() && mxPlayer
->isPlaying() );
263 // ---------------------------------------------------------------------
265 double MediaWindowBaseImpl::getDuration() const
267 return( mxPlayer
.is() ? mxPlayer
->getDuration() : 0.0 );
270 // ---------------------------------------------------------------------
272 void MediaWindowBaseImpl::setMediaTime( double fTime
)
275 mxPlayer
->setMediaTime( fTime
);
278 // ---------------------------------------------------------------------
280 double MediaWindowBaseImpl::getMediaTime() const
282 return( mxPlayer
.is() ? mxPlayer
->getMediaTime() : 0.0 );
285 // ---------------------------------------------------------------------
287 void MediaWindowBaseImpl::setStopTime( double fTime
)
290 mxPlayer
->setStopTime( fTime
);
293 // ---------------------------------------------------------------------
295 double MediaWindowBaseImpl::getStopTime() const
297 return( mxPlayer
.is() ? mxPlayer
->getStopTime() : 0.0 );
300 // ---------------------------------------------------------------------
302 void MediaWindowBaseImpl::setRate( double fRate
)
305 mxPlayer
->setRate( fRate
);
308 // ---------------------------------------------------------------------
310 double MediaWindowBaseImpl::getRate() const
312 return( mxPlayer
.is() ? mxPlayer
->getRate() : 0.0 );
315 // ---------------------------------------------------------------------
317 void MediaWindowBaseImpl::setPlaybackLoop( bool bSet
)
320 mxPlayer
->setPlaybackLoop( bSet
);
323 // ---------------------------------------------------------------------
325 bool MediaWindowBaseImpl::isPlaybackLoop() const
327 return( mxPlayer
.is() ? mxPlayer
->isPlaybackLoop() : false );
330 // ---------------------------------------------------------------------
332 void MediaWindowBaseImpl::setMute( bool bSet
)
335 mxPlayer
->setMute( bSet
);
338 // ---------------------------------------------------------------------
340 bool MediaWindowBaseImpl::isMute() const
342 return( mxPlayer
.is() ? mxPlayer
->isMute() : false );
345 // ---------------------------------------------------------------------
347 void MediaWindowBaseImpl::setVolumeDB( sal_Int16 nVolumeDB
)
350 mxPlayer
->setVolumeDB( nVolumeDB
);
353 // ---------------------------------------------------------------------
355 sal_Int16
MediaWindowBaseImpl::getVolumeDB() const
357 return( mxPlayer
.is() ? mxPlayer
->getVolumeDB() : 0 );
360 // -------------------------------------------------------------------------
362 void MediaWindowBaseImpl::updateMediaItem( MediaItem
& rItem
) const
365 rItem
.setState( ( getRate() > 1.0 ) ? MEDIASTATE_PLAYFFW
: MEDIASTATE_PLAY
);
367 rItem
.setState( ( 0.0 == getMediaTime() ) ? MEDIASTATE_STOP
: MEDIASTATE_PAUSE
);
369 rItem
.setDuration( getDuration() );
370 rItem
.setTime( getMediaTime() );
371 rItem
.setLoop( isPlaybackLoop() );
372 rItem
.setMute( isMute() );
373 rItem
.setVolumeDB( getVolumeDB() );
374 rItem
.setZoom( getZoom() );
375 rItem
.setURL( getURL() );
378 // -------------------------------------------------------------------------
380 void MediaWindowBaseImpl::executeMediaItem( const MediaItem
& rItem
)
382 const sal_uInt32 nMaskSet
= rItem
.getMaskSet();
385 if( nMaskSet
& AVMEDIA_SETMASK_URL
)
386 setURL( rItem
.getURL() );
388 // set different states next
389 if( nMaskSet
& AVMEDIA_SETMASK_TIME
)
390 setMediaTime( ::std::min( rItem
.getTime(), getDuration() ) );
392 if( nMaskSet
& AVMEDIA_SETMASK_LOOP
)
393 setPlaybackLoop( rItem
.isLoop() );
395 if( nMaskSet
& AVMEDIA_SETMASK_MUTE
)
396 setMute( rItem
.isMute() );
398 if( nMaskSet
& AVMEDIA_SETMASK_VOLUMEDB
)
399 setVolumeDB( rItem
.getVolumeDB() );
401 if( nMaskSet
& AVMEDIA_SETMASK_ZOOM
)
402 setZoom( rItem
.getZoom() );
404 // set play state at last
405 if( nMaskSet
& AVMEDIA_SETMASK_STATE
)
407 switch( rItem
.getState() )
409 case( MEDIASTATE_PLAY
):
410 case( MEDIASTATE_PLAYFFW
):
413 const double fNewRate = ( ( MEDIASTATE_PLAYFFW == rItem.getState() ) ? AVMEDIA_FFW_PLAYRATE : 1.0 );
415 if( getRate() != fNewRate )
423 case( MEDIASTATE_PAUSE
):
430 case( MEDIASTATE_STOP
):
445 } // namespace avemdia