Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

mediaplayer.cpp

Go to the documentation of this file.
00001 #include "mediaplayer.h"
00002 #include "audiowidget.h"
00003 #include "videowidget.h"
00004 #include "volumecontrol.h"
00005 
00006 /* OPIE */
00007 #include <opie2/odebug.h>
00008 #include <opie2/odevice.h>
00009 #include <qpe/qpeapplication.h>
00010 #include <qpe/config.h>
00011 
00012 /* QT */
00013 #include <qfileinfo.h>
00014 
00015 /* STD */
00016 #include <linux/fb.h>
00017 #include <sys/file.h>
00018 #include <sys/ioctl.h>
00019 
00020 #define FBIOBLANK 0x4611
00021 
00022 MediaPlayer::MediaPlayer( PlayListWidget &_playList, MediaPlayerState &_mediaPlayerState, QObject *parent, const char *name )
00023     : QObject( parent, name ), volumeDirection( 0 ), mediaPlayerState( _mediaPlayerState ), playList( _playList ) {
00024 
00025     m_audioUI = 0;
00026     m_videoUI = 0;
00027     m_xineControl = 0;
00028     xine = new XINE::Lib( XINE::Lib::InitializeInThread );
00029 
00030     fd=-1;fl=-1;
00031     playList.setCaption( tr( "OpiePlayer: Initializating" ) );
00032 
00033     qApp->processEvents();
00034     //    QPEApplication::grabKeyboard(); // EVIL
00035     connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
00036 
00037     connect( &mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) );
00038     connect( &mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) );
00039     connect( &mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) );
00040     connect( &mediaPlayerState, SIGNAL( blankToggled(bool) ), this, SLOT ( blank(bool) ) );
00041 
00042     volControl = new VolumeControl;
00043     Config cfg( "OpiePlayer" );
00044     cfg.setGroup("PlayList");
00045     QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default");
00046     playList.setCaption( tr( "OpiePlayer: " ) + QFileInfo(currentPlaylist).baseName() );
00047 
00048     m_skinLoader = new SkinLoader;
00049     m_skinLoader->schedule( AudioWidget::guiInfo() );
00050     m_skinLoader->schedule( VideoWidget::guiInfo() );
00051     m_skinLoader->start();
00052 }
00053 
00054 MediaPlayer::~MediaPlayer() {
00055     // this shold never happen, but one never knows...
00056     if ( xine ) {
00057         xine->ensureInitialized();
00058         delete xine;
00059     }
00060     delete m_xineControl;
00061     delete m_audioUI;
00062     delete m_videoUI;
00063     delete volControl;
00064 }
00065 
00066 void MediaPlayer::pauseCheck( bool b ) {
00067      if ( b && !mediaPlayerState.isPlaying() ) {
00068          mediaPlayerState.setPaused( FALSE );
00069      }
00070 }
00071 
00072 void MediaPlayer::play() {
00073     mediaPlayerState.setPlaying( FALSE );
00074     mediaPlayerState.setPlaying( TRUE );
00075 }
00076 
00077 void MediaPlayer::setPlaying( bool play ) {
00078     if ( !play ) {
00079         return;
00080     }
00081 
00082     if ( mediaPlayerState.isPaused() ) {
00083         mediaPlayerState.setPaused( FALSE );
00084         return;
00085     }
00086 
00087     QString tickerText, time, fileName;
00088     if ( playList.currentTab() != PlayListWidget::CurrentPlayList ) {
00089         //if playing in file list.. play in a different way
00090         // random and looping settings enabled causes problems here,
00091         // since there is no selected file in the playlist, but a selected file in the file list,
00092         // so we remember and shutoff
00093         l = mediaPlayerState.isLooping();
00094         if(l) {
00095             mediaPlayerState.setLooping( false );
00096         }
00097         r = mediaPlayerState.isShuffled();
00098         mediaPlayerState.setShuffled( false );
00099     }
00100 
00101     PlayListWidget::Entry playListEntry = playList.currentEntry();
00102     fileName = playListEntry.name;
00103     xineControl()->play( playListEntry.file );
00104 
00105     long seconds = mediaPlayerState.length();
00106     time.sprintf("%li:%02i", seconds/60, (int)seconds%60 );
00107 
00108     if( fileName.left(4) == "http" ) {
00109         fileName = QFileInfo( fileName ).baseName();
00110        if ( xineControl()->getMetaInfo().isEmpty() ) {
00111            tickerText = tr( " File: " ) + fileName;
00112        } else {
00113            tickerText = xineControl()->getMetaInfo();
00114        }
00115     } else {
00116         if ( xineControl()->getMetaInfo().isEmpty() ) {
00117             tickerText = tr( " File: " ) + fileName + tr( ", Length: " ) + time + "  ";
00118         } else {
00119             tickerText = xineControl()->getMetaInfo() + " Length: " + time + "  ";
00120         }
00121     }
00122     audioUI()->setTickerText( tickerText );
00123 }
00124 
00125 
00126 void MediaPlayer::prev() {
00127     if( playList.currentTab() == PlayListWidget::CurrentPlayList ) { //if using the playlist
00128         if ( playList.prev() ) {
00129             play();
00130         } else if ( mediaPlayerState.isLooping() ) {
00131             if ( playList.last() ) {
00132                 play();
00133             }
00134         } else {
00135             mediaPlayerState.setList();
00136         }
00137     }
00138 }
00139 
00140 
00141 void MediaPlayer::next() {
00142 
00143     if(playList.currentTab() == PlayListWidget::CurrentPlayList) { //if using the playlist
00144         if ( playList.next() ) {
00145             play();
00146         } else if ( mediaPlayerState.isLooping() ) {
00147             if ( playList.first() ) {
00148                 play();
00149             }
00150         } else {
00151             mediaPlayerState.setList();
00152         }
00153     } else { //if playing from file list, let's just stop
00154         odebug << "<<<<<<<<<<<<<<<<<stop for filelists" << oendl;
00155         mediaPlayerState.setPlaying(false);
00156         mediaPlayerState.setDisplayType( MediaPlayerState::MediaSelection );
00157         if(l) mediaPlayerState.setLooping(l);
00158         if(r) mediaPlayerState.setShuffled(r);
00159     }
00160 }
00161 
00162 
00163 void MediaPlayer::startDecreasingVolume() {
00164     volumeDirection = -1;
00165     startTimer( 100 );
00166     volControl->decVol(2);
00167 }
00168 
00169 
00170 void MediaPlayer::startIncreasingVolume() {
00171     volumeDirection = +1;
00172     startTimer( 100 );
00173     volControl->incVol(2);
00174 }
00175 
00176 
00177 bool drawnOnScreenDisplay = FALSE;
00178 unsigned int onScreenDisplayVolume = 0;
00179 const int yoff = 110;
00180 
00181 void MediaPlayer::stopChangingVolume() {
00182     killTimers();
00183     // Get rid of the on-screen display stuff
00184     drawnOnScreenDisplay = FALSE;
00185     onScreenDisplayVolume = 0;
00186     int w=0;
00187     int h=0;
00188     if( !xineControl()->hasVideo() ) {
00189         w = audioUI()->width();
00190         h = audioUI()->height();
00191         audioUI()->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE );
00192     } else {
00193         w = videoUI()->width();
00194         h = videoUI()->height();
00195         videoUI()->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE );
00196     }
00197 }
00198 
00199 
00200 void MediaPlayer::timerEvent( QTimerEvent * ) {
00201     if ( volumeDirection == +1 ) {
00202         volControl->incVol( 2 );
00203     } else if ( volumeDirection == -1 ) {
00204         volControl->decVol( 2 );
00205     }
00206 
00207 
00208       // TODO FIXME
00209       // huh??
00210     unsigned int v= 0;
00211     v = volControl->volume();
00212     v = v / 10;
00213 
00214     if ( drawnOnScreenDisplay && onScreenDisplayVolume == v ) {
00215         return;
00216     }
00217 
00218     int w=0; int h=0;
00219     if( !xineControl()->hasVideo() ) {
00220         w = audioUI()->width();
00221         h = audioUI()->height();
00222 
00223         if ( drawnOnScreenDisplay ) {
00224             if ( onScreenDisplayVolume > v ) {
00225                 audioUI()->repaint( ( w - 200 ) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE );
00226             }
00227         }
00228         drawnOnScreenDisplay = TRUE;
00229         onScreenDisplayVolume = v;
00230         QPainter p( audioUI() );
00231         p.setPen( QColor( 0x10, 0xD0, 0x10 ) );
00232         p.setBrush( QColor( 0x10, 0xD0, 0x10 ) );
00233 
00234         QFont f;
00235         f.setPixelSize( 20 );
00236         f.setBold( TRUE );
00237         p.setFont( f );
00238         p.drawText( (w - 200) / 2, h - yoff + 20, tr("Volume") );
00239 
00240         for ( unsigned int i = 0; i < 10; i++ ) {
00241             if ( v > i ) {
00242                 p.drawRect( ( w - 200 ) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 );
00243             } else {
00244                 p.drawRect( ( w - 200 ) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 );
00245             }
00246         }
00247     } else {
00248         w = videoUI()->width();
00249         h = videoUI()->height();
00250 
00251         if ( drawnOnScreenDisplay ) {
00252             if ( onScreenDisplayVolume > v ) {
00253                 videoUI()->repaint( (w - 200) / 2 + v * 20 + 0, h - yoff + 40, ( onScreenDisplayVolume - v ) * 20 + 9, 30, FALSE );
00254             }
00255         }
00256         drawnOnScreenDisplay = TRUE;
00257         onScreenDisplayVolume = v;
00258         QPainter p( videoUI() );
00259         p.setPen( QColor( 0x10, 0xD0, 0x10 ) );
00260         p.setBrush( QColor( 0x10, 0xD0, 0x10 ) );
00261 
00262         QFont f;
00263         f.setPixelSize( 20 );
00264         f.setBold( TRUE );
00265         p.setFont( f );
00266         p.drawText( (w - 200) / 2, h - yoff + 20, tr( "Volume" ) );
00267 
00268         for ( unsigned int i = 0; i < 10; i++ ) {
00269             if ( v > i ) {
00270                 p.drawRect( (w - 200) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 );
00271             } else {
00272                 p.drawRect( (w - 200) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 );
00273             }
00274         }
00275     }
00276 }
00277 
00278 
00279 void MediaPlayer::blank( bool b ) {
00280     Opie::Core::ODevice::inst()->setDisplayStatus( b );
00281 }
00282 
00283 void MediaPlayer::keyReleaseEvent( QKeyEvent *e) {
00284     switch ( e->key() ) {
00286       case Key_Home:
00287           break;
00288       case Key_F9: //activity
00289           break;
00290       case Key_F10: //contacts
00291           break;
00292       case Key_F11: //menu
00293           break;
00294       case Key_F12: //home
00295           odebug << "Blank here" << oendl;
00296 //          mediaPlayerState->toggleBlank();
00297           break;
00298       case Key_F13: //mail
00299           odebug << "Blank here" << oendl;
00300           //  mediaPlayerState->toggleBlank();
00301           break;
00302     }
00303 }
00304 
00305 void MediaPlayer::cleanUp() {// this happens on closing
00306      Config cfg( "OpiePlayer" );
00307      mediaPlayerState.writeConfig( cfg );
00308      playList.writeDefaultPlaylist( );
00309 
00310 }
00311 
00312 void MediaPlayer::recreateAudioAndVideoWidgets() const
00313 {
00314     delete m_skinLoader;
00315 
00316     delete m_xineControl;
00317     delete m_audioUI;
00318     delete m_videoUI;
00319     m_audioUI = new AudioWidget( playList, mediaPlayerState, 0, "audioUI" );
00320     m_videoUI = new VideoWidget( playList, mediaPlayerState, 0, "videoUI" );
00321 
00322     connect( m_audioUI,  SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) );
00323     connect( m_audioUI,  SIGNAL( lessClicked() ),  this, SLOT( startDecreasingVolume() ) );
00324     connect( m_audioUI,  SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) );
00325     connect( m_audioUI,  SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) );
00326 
00327     connect( m_videoUI,  SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) );
00328     connect( m_videoUI,  SIGNAL( lessClicked() ),  this, SLOT( startDecreasingVolume() ) );
00329     connect( m_videoUI,  SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) );
00330     connect( m_videoUI,  SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) );
00331 
00332     if ( !xine )
00333         xine = new XINE::Lib( XINE::Lib::InitializeImmediately );
00334 
00335     m_xineControl = new XineControl( xine, m_videoUI->vidWidget(), mediaPlayerState );
00336 
00337     xine = 0;
00338 }
00339 
00340 AudioWidget *MediaPlayer::audioUI() const
00341 {
00342     if ( !m_audioUI )
00343         recreateAudioAndVideoWidgets();
00344     return m_audioUI;
00345 }
00346 
00347 VideoWidget *MediaPlayer::videoUI() const
00348 {
00349     if ( !m_videoUI )
00350         recreateAudioAndVideoWidgets();
00351     return m_videoUI;
00352 }
00353 
00354 XineControl *MediaPlayer::xineControl() const
00355 {
00356     if ( !m_xineControl )
00357         recreateAudioAndVideoWidgets();
00358     return m_xineControl;
00359 }
00360 
00361 void MediaPlayer::reloadSkins()
00362 {
00363     audioUI()->loadSkin();
00364     videoUI()->loadSkin();
00365 }
00366 

Generated on Sat Nov 5 16:15:37 2005 for OPIE by  doxygen 1.4.2