diff options
Diffstat (limited to 'avmedia/source/viewer/mediawindowbase_impl.cxx')
-rw-r--r-- | avmedia/source/viewer/mediawindowbase_impl.cxx | 478 |
1 files changed, 478 insertions, 0 deletions
diff --git a/avmedia/source/viewer/mediawindowbase_impl.cxx b/avmedia/source/viewer/mediawindowbase_impl.cxx new file mode 100644 index 000000000000..5196e3339439 --- /dev/null +++ b/avmedia/source/viewer/mediawindowbase_impl.cxx @@ -0,0 +1,478 @@ +/************************************************************************* + * + * $RCSfile: mediawindowbase_impl.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: ka $ $Date: 2004-08-23 09:04:42 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "mediawindowbase_impl.hxx" +#include "mediaitem.hxx" +#include "mediamisc.hxx" +#include "mediawindow.hrc" +#include <tools/urlobj.hxx> + +#ifndef _COMPHELPER_PROCESSFACTORY_HXX_ +#include <comphelper/processfactory.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_MEDIA_XMANAGER_HPP_ +#include <com/sun/star/media/XManager.hpp> +#endif + +#define MEDIA_TIMER_TIMEOUT 100 + +using namespace ::com::sun::star; + +namespace avmedia { namespace priv { + +// ----------------------- +// - MediaWindowBaseImpl - +// ----------------------- + +MediaWindowBaseImpl::MediaWindowBaseImpl( MediaWindow* pMediaWindow ) : + mpMediaWindow( pMediaWindow ) +{ +} + +// --------------------------------------------------------------------- + +MediaWindowBaseImpl::~MediaWindowBaseImpl() +{ + uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() ); +} + +// ------------------------------------------------------------------------- + +uno::Reference< media::XPlayer > MediaWindowBaseImpl::createPlayer( const ::rtl::OUString& rURL ) +{ + uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() ); + uno::Reference< media::XPlayer > xPlayer; + + if( xFactory.is() ) + { + try + { + + uno::Reference< ::com::sun::star::media::XManager > xManager( + xFactory->createInstance( ::rtl::OUString::createFromAscii( AVMEDIA_MANAGER_SERVICE_NAME ) ), + uno::UNO_QUERY ); + + if( xManager.is() ) + { + xPlayer = uno::Reference< ::com::sun::star::media::XPlayer >( + xManager->createPlayer( rURL ), uno::UNO_QUERY ); + } + } + catch( ... ) + { + } + } + + return xPlayer; +} + + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::setURL( const ::rtl::OUString& rURL ) +{ + if( rURL != getURL() ) + { + INetURLObject aURL( maFileURL = rURL ); + + if( mxPlayer.is() ) + mxPlayer->stop(); + + if( mxPlayerWindow.is() ) + { + mxPlayerWindow->setVisible( false ); + mxPlayerWindow.clear(); + } + + mxPlayer.clear(); + + if( aURL.GetProtocol() != INET_PROT_NOT_VALID ) + maFileURL = aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ); + + mxPlayer = createPlayer( rURL ); + onURLChanged(); + } +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::onURLChanged() +{ +} + +// --------------------------------------------------------------------- + +const ::rtl::OUString& MediaWindowBaseImpl::getURL() const +{ + return maFileURL; +} + +// --------------------------------------------------------------------- + +bool MediaWindowBaseImpl::isValid() const +{ + return( getPlayer().is() ); +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::stopPlayingInternal( bool bStop ) +{ + if( isPlaying() ) + { + if( bStop ) + mxPlayer->start(); + else + mxPlayer->stop(); + } +} + +// --------------------------------------------------------------------- + +MediaWindow* MediaWindowBaseImpl::getMediaWindow() const +{ + return mpMediaWindow; +} + +// --------------------------------------------------------------------- + +uno::Reference< media::XPlayer > MediaWindowBaseImpl::getPlayer() const +{ + return mxPlayer; +} + +// --------------------------------------------------------------------- + +uno::Reference< media::XPlayerWindow > MediaWindowBaseImpl::getPlayerWindow() const +{ + return mxPlayerWindow; +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::setPlayerWindow( const uno::Reference< media::XPlayerWindow >& rxPlayerWindow ) +{ + mxPlayerWindow = rxPlayerWindow; +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::cleanUp() +{ + if( mxPlayer.is() ) + mxPlayer->stop(); + + if( mxPlayerWindow.is() ) + { + mxPlayerWindow->setVisible( false ); + mxPlayerWindow.clear(); + } + + mxPlayer.clear(); + mpMediaWindow = NULL; +} + +// --------------------------------------------------------------------- + +bool MediaWindowBaseImpl::hasPreferredSize() const +{ + return( mxPlayerWindow.is() ); +} + +// --------------------------------------------------------------------- + +Size MediaWindowBaseImpl::getPreferredSize() const +{ + Size aRet; + + if( mxPlayer.is() ) + { + awt::Size aPrefSize( mxPlayer->getPreferredPlayerWindowSize() ); + + aRet.Width() = aPrefSize.Width; + aRet.Height() = aPrefSize.Height; + } + + return aRet; +} + +// --------------------------------------------------------------------- + +bool MediaWindowBaseImpl::setZoom( ::com::sun::star::media::ZoomLevel eLevel ) +{ + return( mxPlayerWindow.is() ? mxPlayerWindow->setZoomLevel( eLevel ) : false ); +} + +// ------------------------------------------------------------------------- + +::com::sun::star::media::ZoomLevel MediaWindowBaseImpl::getZoom() const +{ + return( mxPlayerWindow.is() ? mxPlayerWindow->getZoomLevel() : ::com::sun::star::media::ZoomLevel_NOT_AVAILABLE ); +} + +// --------------------------------------------------------------------- + +bool MediaWindowBaseImpl::start() +{ + return( mxPlayer.is() ? ( mxPlayer->start(), true ) : false ); +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::stop() +{ + if( mxPlayer.is() ) + mxPlayer->stop(); +} + +// --------------------------------------------------------------------- + +bool MediaWindowBaseImpl::isPlaying() const +{ + return( mxPlayer.is() && mxPlayer->isPlaying() ); +} + +// --------------------------------------------------------------------- + +double MediaWindowBaseImpl::getDuration() const +{ + return( mxPlayer.is() ? mxPlayer->getDuration() : 0.0 ); +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::setMediaTime( double fTime ) +{ + if( mxPlayer.is() ) + mxPlayer->setMediaTime( fTime ); +} + +// --------------------------------------------------------------------- + +double MediaWindowBaseImpl::getMediaTime() const +{ + return( mxPlayer.is() ? mxPlayer->getMediaTime() : 0.0 ); +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::setStopTime( double fTime ) +{ + if( mxPlayer.is() ) + mxPlayer->setStopTime( fTime ); +} + +// --------------------------------------------------------------------- + +double MediaWindowBaseImpl::getStopTime() const +{ + return( mxPlayer.is() ? mxPlayer->getStopTime() : 0.0 ); +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::setRate( double fRate ) +{ + if( mxPlayer.is() ) + mxPlayer->setRate( fRate ); +} + +// --------------------------------------------------------------------- + +double MediaWindowBaseImpl::getRate() const +{ + return( mxPlayer.is() ? mxPlayer->getRate() : 0.0 ); +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::setPlaybackLoop( bool bSet ) +{ + if( mxPlayer.is() ) + mxPlayer->setPlaybackLoop( bSet ); +} + +// --------------------------------------------------------------------- + +bool MediaWindowBaseImpl::isPlaybackLoop() const +{ + return( mxPlayer.is() ? mxPlayer->isPlaybackLoop() : false ); +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::setMute( bool bSet ) +{ + if( mxPlayer.is() ) + mxPlayer->setMute( bSet ); +} + +// --------------------------------------------------------------------- + +bool MediaWindowBaseImpl::isMute() const +{ + return( mxPlayer.is() ? mxPlayer->isMute() : false ); +} + +// --------------------------------------------------------------------- + +void MediaWindowBaseImpl::setVolumeDB( sal_Int16 nVolumeDB ) +{ + if( mxPlayer.is() ) + mxPlayer->setVolumeDB( nVolumeDB ); +} + +// --------------------------------------------------------------------- + +sal_Int16 MediaWindowBaseImpl::getVolumeDB() const +{ + return( mxPlayer.is() ? mxPlayer->getVolumeDB() : 0 ); +} + +// ------------------------------------------------------------------------- + +void MediaWindowBaseImpl::updateMediaItem( MediaItem& rItem ) const +{ + if( isPlaying() ) + rItem.setState( ( getRate() > 1.0 ) ? MEDIASTATE_PLAYFFW : MEDIASTATE_PLAY ); + else + rItem.setState( ( 0.0 == getMediaTime() ) ? MEDIASTATE_STOP : MEDIASTATE_PAUSE ); + + rItem.setDuration( getDuration() ); + rItem.setTime( getMediaTime() ); + rItem.setLoop( isPlaybackLoop() ); + rItem.setMute( isMute() ); + rItem.setVolumeDB( getVolumeDB() ); + rItem.setZoom( getZoom() ); + rItem.setURL( getURL() ); +} + +// ------------------------------------------------------------------------- + +void MediaWindowBaseImpl::executeMediaItem( const MediaItem& rItem ) +{ + const sal_uInt32 nMaskSet = rItem.getMaskSet(); + + // set URL first + if( nMaskSet & AVMEDIA_SETMASK_URL ) + setURL( rItem.getURL() ); + + // set different states next + if( nMaskSet & AVMEDIA_SETMASK_TIME ) + setMediaTime( ::std::min( rItem.getTime(), getDuration() ) ); + + if( nMaskSet & AVMEDIA_SETMASK_LOOP ) + setPlaybackLoop( rItem.isLoop() ); + + if( nMaskSet & AVMEDIA_SETMASK_MUTE ) + setMute( rItem.isMute() ); + + if( nMaskSet & AVMEDIA_SETMASK_VOLUMEDB ) + setVolumeDB( rItem.getVolumeDB() ); + + if( nMaskSet & AVMEDIA_SETMASK_ZOOM ) + setZoom( rItem.getZoom() ); + + // set play state at last + if( nMaskSet & AVMEDIA_SETMASK_STATE ) + { + switch( rItem.getState() ) + { + case( MEDIASTATE_PLAY ): + case( MEDIASTATE_PLAYFFW ): + { +/* + const double fNewRate = ( ( MEDIASTATE_PLAYFFW == rItem.getState() ) ? AVMEDIA_FFW_PLAYRATE : 1.0 ); + + if( getRate() != fNewRate ) + setRate( fNewRate ); +*/ + if( !isPlaying() ) + start(); + } + break; + + case( MEDIASTATE_PAUSE ): + { + if( isPlaying() ) + stop(); + } + break; + + case( MEDIASTATE_STOP ): + { + if( isPlaying() ) + { + setMediaTime( 0.0 ); + stop(); + setMediaTime( 0.0 ); + } + } + break; + } + } +} + +} // namespace priv +} // namespace avemdia |