00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "xinecontrol.h"
00035 #include "xinevideowidget.h"
00036
00037
00038 #include <opie2/odebug.h>
00039 #include <qpe/qcopenvelope_qws.h>
00040 #include <qpe/qpeapplication.h>
00041 using namespace Opie::Core;
00042
00043
00044 #include <qtimer.h>
00045 #include <qmessagebox.h>
00046
00047 XineControl::XineControl( XINE::Lib *xine, XineVideoWidget *xineWidget,
00048 MediaPlayerState &_mediaPlayerState,
00049 QObject *parent, const char *name )
00050 : QObject( parent, name ), libXine( xine ), mediaPlayerState( _mediaPlayerState ), xineVideoWidget( xineWidget )
00051 {
00052 m_wasError = false;
00053
00054 xine->ensureInitialized();
00055
00056 xine->setWidget( xineWidget );
00057
00058 init();
00059 }
00060
00061 void XineControl::init()
00062 {
00063 connect( &mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( pause(bool) ) );
00064 connect( this, SIGNAL( positionChanged(long) ), &mediaPlayerState, SLOT( updatePosition(long) ) );
00065 connect( &mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( stop(bool) ) );
00066 connect( &mediaPlayerState, SIGNAL( fullscreenToggled(bool) ), this, SLOT( setFullscreen(bool) ) );
00067 connect( &mediaPlayerState, SIGNAL( positionChanged(long) ), this, SLOT( seekTo(long) ) );
00068 connect( &mediaPlayerState, SIGNAL( videoGammaChanged(int) ), this, SLOT( setGamma(int) ) );
00069 connect( libXine, SIGNAL( stopped() ), this, SLOT( nextMedia() ) );
00070 connect( xineVideoWidget, SIGNAL( videoResized(const QSize&) ), this, SLOT( videoResized(const QSize&) ) );
00071
00072 disabledSuspendScreenSaver = FALSE;
00073 }
00074
00075 XineControl::~XineControl() {
00076 #if !defined(QT_NO_COP)
00077 if ( disabledSuspendScreenSaver ) {
00078 disabledSuspendScreenSaver = FALSE;
00079
00080 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
00081 }
00082 #endif
00083 delete libXine;
00084 }
00085
00086 void XineControl::play( const QString& fileName ) {
00087
00088 hasVideoChannel = FALSE;
00089 hasAudioChannel = FALSE;
00090 m_fileName = fileName;
00091 m_wasError = false;
00092
00093
00094
00095
00096
00097
00098
00099 if ( !libXine->play( fileName, 0, 0 ) ) {
00100 QMessageBox::warning( 0l , tr( "Failure" ), getErrorCode() );
00101 m_wasError = true;
00102 }
00103 mediaPlayerState.setPlaying( true );
00104
00105 MediaPlayerState::DisplayType displayType;
00106 if ( !libXine->hasVideo() ) {
00107 displayType = MediaPlayerState::Audio;
00108 libXine->setShowVideo( false );
00109 hasAudioChannel = TRUE;
00110 } else {
00111 displayType = MediaPlayerState::Video;
00112 libXine->setShowVideo( true );
00113 hasVideoChannel = TRUE;
00114 }
00115
00116 mediaPlayerState.setIsSeekable( libXine->isSeekable() );
00117
00118
00119 mediaPlayerState.setDisplayType( displayType );
00120
00121 #if defined(Q_WS_QWS) && !defined(QT_NO_COP)
00122 if ( !disabledSuspendScreenSaver ) {
00123 disabledSuspendScreenSaver = TRUE;
00124
00125 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" )
00126 << ( displayType == MediaPlayerState::Video ? QPEApplication::Disable : QPEApplication::DisableSuspend );
00127 }
00128 #endif
00129
00130 length();
00131 position();
00132 }
00133
00134 void XineControl::nextMedia() {
00135 mediaPlayerState.setNext();
00136 }
00137
00138 void XineControl::setGamma( int value ) {
00139 libXine->setGamma( value );
00140 }
00141
00142 void XineControl::stop( bool isSet ) {
00143 if ( !isSet ) {
00144 libXine->stop();
00145
00146 #if !defined(QT_NO_COP)
00147 if ( disabledSuspendScreenSaver ) {
00148 disabledSuspendScreenSaver = FALSE;
00149
00150 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
00151 }
00152 #endif
00153 }
00154 }
00155
00160 void XineControl::pause( bool isSet) {
00161 libXine->pause( isSet );
00162 }
00163
00164
00168 long XineControl::currentTime() {
00169
00170 m_currentTime = libXine->currentTime();
00171 return m_currentTime;
00172 }
00173
00177 void XineControl::length() {
00178 m_length = libXine->length();
00179 mediaPlayerState.setLength( m_length );
00180 }
00181
00182
00187 long XineControl::position() {
00188 m_position = ( currentTime() );
00189 mediaPlayerState.updatePosition( m_position );
00190 long emitPos = (long)m_position;
00191 emit positionChanged( emitPos );
00192 if( mediaPlayerState.isPlaying() ) {
00193
00194 QTimer::singleShot( 1000, this, SLOT( position() ) );
00195 }
00196 return m_position;
00197 }
00198
00203 void XineControl::setFullscreen( bool isSet ) {
00204 libXine->showVideoFullScreen( isSet );
00205 }
00206
00207
00208 QString XineControl::getMetaInfo() {
00209
00210 QString returnString;
00211
00212
00213
00214
00215
00216 if ( m_wasError ) {
00217 returnString = tr("Error on file '%1' with reason: ",
00218 "Error when playing a file" ).arg( m_fileName );
00219 returnString += getErrorCode();
00220 returnString.replace( QRegExp("<qt>", false), "" );
00221 returnString.replace( QRegExp("</qt>", false), "" );
00222 return returnString;
00223 }
00224
00225 if ( !libXine->metaInfo( 0 ).isEmpty() ) {
00226 returnString += tr( " Title: " + libXine->metaInfo( 0 ) );
00227 }
00228
00229 if ( !libXine->metaInfo( 1 ).isEmpty() ) {
00230 returnString += tr( " Comment: " + libXine->metaInfo( 1 ) );
00231 }
00232
00233 if ( !libXine->metaInfo( 2 ).isEmpty() ) {
00234 returnString += tr( " Artist: " + libXine->metaInfo( 2 ) );
00235 }
00236
00237 if ( !libXine->metaInfo( 3 ).isEmpty() ) {
00238 returnString += tr( " Genre: " + libXine->metaInfo( 3 ) );
00239 }
00240
00241 if ( !libXine->metaInfo( 4 ).isEmpty() ) {
00242 returnString += tr( " Album: " + libXine->metaInfo( 4 ) );
00243 }
00244
00245 if ( !libXine->metaInfo( 5 ).isEmpty() ) {
00246 returnString += tr( " Year: " + libXine->metaInfo( 5 ) );
00247 }
00248 return returnString;
00249 }
00250
00251 QString XineControl::getErrorCode() {
00252
00253 int errorCode = libXine->error();
00254
00255 odebug << QString("ERRORCODE: %1 ").arg(errorCode) << oendl;
00256
00257 if ( errorCode == 1 ) {
00258 return tr( "<qt>No input plugin found for this media type</qt>" );
00259 } else if ( errorCode == 2 ) {
00260 return tr( "<qt>No demux plugin found for this media type</qt>" );
00261 } else if ( errorCode == 3 ) {
00262 return tr( "<qt>Demuxing failed for this media type</qt>" );
00263 } else if ( errorCode == 4 ) {
00264 return tr( "<qt>Malformed MRL</qt>" );
00265 } else if ( errorCode == 5 ) {
00266 return tr( "<qt>Input failed</qt>" );
00267 } else {
00268 return tr( "<qt>Some other error</qt>" );
00269 }
00270 }
00271
00276 void XineControl::seekTo( long second ) {
00277 libXine->seekTo( (int)second );
00278 }
00279
00280 void XineControl::videoResized ( const QSize &s ) {
00281 libXine->resize( s );
00282 }