Diffstat (limited to 'core/multimedia/opieplayer/mediaplayer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/mediaplayer.cpp | 65 |
1 files changed, 30 insertions, 35 deletions
diff --git a/core/multimedia/opieplayer/mediaplayer.cpp b/core/multimedia/opieplayer/mediaplayer.cpp index ce42c2c..c971a3c 100644 --- a/core/multimedia/opieplayer/mediaplayer.cpp +++ b/core/multimedia/opieplayer/mediaplayer.cpp | |||
@@ -45,14 +45,14 @@ extern MediaPlayerState *mediaPlayerState; | |||
45 | 45 | ||
46 | MediaPlayer::MediaPlayer( QObject *parent, const char *name ) | 46 | MediaPlayer::MediaPlayer( QObject *parent, const char *name ) |
47 | : QObject( parent, name ), volumeDirection( 0 ), currentFile( NULL ) { | 47 | : QObject( parent, name ), volumeDirection( 0 ), currentFile( NULL ) { |
48 | 48 | ||
49 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); | 49 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) ); |
50 | connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); | 50 | connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) ); |
51 | connect( mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); | 51 | connect( mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) ); |
52 | connect( mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); | 52 | connect( mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) ); |
53 | 53 | ||
54 | connect( audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); | 54 | connect( audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) ); |
55 | connect( audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); | 55 | connect( audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) ); |
56 | connect( audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); | 56 | connect( audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) ); |
57 | connect( audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); | 57 | connect( audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) ); |
58 | } | 58 | } |
@@ -62,99 +62,94 @@ MediaPlayer::~MediaPlayer() { | |||
62 | } | 62 | } |
63 | 63 | ||
64 | 64 | ||
65 | void MediaPlayer::pauseCheck( bool b ) { | 65 | void MediaPlayer::pauseCheck( bool b ) { |
66 | // Only pause if playing | 66 | // Only pause if playing |
67 | if ( b && !mediaPlayerState->playing() ) | 67 | if ( b && !mediaPlayerState->playing() ) |
68 | mediaPlayerState->setPaused( FALSE ); | 68 | mediaPlayerState->setPaused( FALSE ); |
69 | } | 69 | } |
70 | 70 | ||
71 | 71 | ||
72 | void MediaPlayer::play() { | 72 | void MediaPlayer::play() { |
73 | mediaPlayerState->setPlaying( FALSE ); | 73 | mediaPlayerState->setPlaying( FALSE ); |
74 | mediaPlayerState->setPlaying( TRUE ); | 74 | mediaPlayerState->setPlaying( TRUE ); |
75 | } | 75 | } |
76 | 76 | ||
77 | 77 | ||
78 | void MediaPlayer::setPlaying( bool play ) { | 78 | void MediaPlayer::setPlaying( bool play ) { |
79 | |||
80 | if ( !play ) { | 79 | if ( !play ) { |
81 | mediaPlayerState->setPaused( FALSE ); | 80 | mediaPlayerState->setPaused( FALSE ); |
82 | loopControl->stop( FALSE ); | 81 | loopControl->stop( FALSE ); |
83 | return; | 82 | return; |
84 | } | 83 | } |
85 | 84 | ||
86 | if ( mediaPlayerState->paused() ) { | 85 | if ( mediaPlayerState->paused() ) { |
87 | mediaPlayerState->setPaused( FALSE ); | 86 | mediaPlayerState->setPaused( FALSE ); |
88 | return; | 87 | return; |
89 | } | 88 | } |
90 | 89 | ||
91 | const DocLnk *playListCurrent = playList->current(); | 90 | const DocLnk *playListCurrent = playList->current(); |
92 | |||
93 | if ( playListCurrent != NULL ) { | 91 | if ( playListCurrent != NULL ) { |
94 | loopControl->stop( TRUE ); | 92 | loopControl->stop( TRUE ); |
95 | currentFile = playListCurrent; | 93 | currentFile = playListCurrent; |
96 | } | 94 | } |
97 | |||
98 | if ( currentFile == NULL ) { | 95 | if ( currentFile == NULL ) { |
99 | QMessageBox::critical( 0, tr( "No file"), tr( "Error: There is no file selected" ) ); | 96 | QMessageBox::critical( 0, tr( "No file"), tr( "Error: There is no file selected" ) ); |
100 | mediaPlayerState->setPlaying( FALSE ); | 97 | mediaPlayerState->setPlaying( FALSE ); |
101 | return; | 98 | return; |
102 | } | 99 | } |
103 | |||
104 | if ( !QFile::exists( currentFile->file() ) ) { | 100 | if ( !QFile::exists( currentFile->file() ) ) { |
105 | QMessageBox::critical( 0, tr( "File not found"), tr( "The following file was not found: <i>" ) + currentFile->file() + "</i>" ); | 101 | QMessageBox::critical( 0, tr( "File not found"), tr( "The following file was not found: <i>" ) + currentFile->file() + "</i>" ); |
106 | mediaPlayerState->setPlaying( FALSE ); | 102 | mediaPlayerState->setPlaying( FALSE ); |
107 | return; | 103 | return; |
108 | } | 104 | } |
109 | 105 | ||
110 | if ( !mediaPlayerState->newDecoder( currentFile->file() ) ) { | 106 | if ( !mediaPlayerState->newDecoder( currentFile->file() ) ) { |
111 | QMessageBox::critical( 0, tr( "No decoder found"), tr( "Sorry, no appropriate decoders found for this file: <i>" ) + currentFile->file() + "</i>" ); | 107 | QMessageBox::critical( 0, tr( "No decoder found"), tr( "Sorry, no appropriate decoders found for this file: <i>" ) + currentFile->file() + "</i>" ); |
112 | mediaPlayerState->setPlaying( FALSE ); | 108 | mediaPlayerState->setPlaying( FALSE ); |
113 | return; | 109 | return; |
114 | } | 110 | } |
115 | 111 | ||
116 | if ( !loopControl->init( currentFile->file() ) ) { | 112 | if ( !loopControl->init( currentFile->file() ) ) { |
117 | QMessageBox::critical( 0, tr( "Error opening file"), tr( "Sorry, an error occured trying to play the file: <i>" ) + currentFile->file() + "</i>" ); | 113 | QMessageBox::critical( 0, tr( "Error opening file"), tr( "Sorry, an error occured trying to play the file: <i>" ) + currentFile->file() + "</i>" ); |
118 | mediaPlayerState->setPlaying( FALSE ); | 114 | mediaPlayerState->setPlaying( FALSE ); |
119 | return; | 115 | return; |
120 | } | 116 | } |
121 | |||
122 | long seconds = loopControl->totalPlaytime(); | 117 | long seconds = loopControl->totalPlaytime(); |
123 | QString time; time.sprintf("%li:%02i", seconds/60, (int)seconds%60 ); | 118 | QString time; time.sprintf("%li:%02i", seconds/60, (int)seconds%60 ); |
124 | QString tickerText = tr( " File: " ) + currentFile->name() + tr(", Length: ") + time; | 119 | QString tickerText = tr( " File: " ) + currentFile->name() + tr(", Length: ") + time; |
125 | QString fileInfo = mediaPlayerState->curDecoder()->fileInfo(); | 120 | QString fileInfo = mediaPlayerState->curDecoder()->fileInfo(); |
126 | if ( !fileInfo.isEmpty() ) | 121 | if ( !fileInfo.isEmpty() ) |
127 | tickerText += ", " + fileInfo; | 122 | tickerText += ", " + fileInfo; |
128 | audioUI->setTickerText( tickerText + "." ); | 123 | audioUI->setTickerText( tickerText + "." ); |
129 | 124 | ||
130 | loopControl->play(); | 125 | loopControl->play(); |
131 | 126 | ||
132 | mediaPlayerState->setView( loopControl->hasVideo() ? 'v' : 'a' ); | 127 | mediaPlayerState->setView( loopControl->hasVideo() ? 'v' : 'a' ); |
133 | } | 128 | } |
134 | 129 | ||
135 | 130 | ||
136 | void MediaPlayer::prev() { | 131 | void MediaPlayer::prev() { |
137 | if ( playList->prev() ) | 132 | if ( playList->prev() ) |
138 | play(); | 133 | play(); |
139 | else if ( mediaPlayerState->looping() ) { | 134 | else if ( mediaPlayerState->looping() ) { |
140 | if ( playList->last() ) | 135 | if ( playList->last() ) |
141 | play(); | 136 | play(); |
142 | } else | 137 | } else |
143 | mediaPlayerState->setList(); | 138 | mediaPlayerState->setList(); |
144 | } | 139 | } |
145 | 140 | ||
146 | 141 | ||
147 | void MediaPlayer::next() { | 142 | void MediaPlayer::next() { |
148 | if ( playList->next() ) | 143 | if ( playList->next() ) |
149 | play(); | 144 | play(); |
150 | else if ( mediaPlayerState->looping() ) { | 145 | else if ( mediaPlayerState->looping() ) { |
151 | if ( playList->first() ) | 146 | if ( playList->first() ) |
152 | play(); | 147 | play(); |
153 | } else | 148 | } else |
154 | mediaPlayerState->setList(); | 149 | mediaPlayerState->setList(); |
155 | } | 150 | } |
156 | 151 | ||
157 | 152 | ||
158 | void MediaPlayer::startDecreasingVolume() { | 153 | void MediaPlayer::startDecreasingVolume() { |
159 | volumeDirection = -1; | 154 | volumeDirection = -1; |
160 | startTimer( 100 ); | 155 | startTimer( 100 ); |
@@ -173,11 +168,11 @@ void MediaPlayer::stopChangingVolume() { | |||
173 | killTimers(); | 168 | killTimers(); |
174 | } | 169 | } |
175 | 170 | ||
176 | 171 | ||
177 | void MediaPlayer::timerEvent( QTimerEvent * ) { | 172 | void MediaPlayer::timerEvent( QTimerEvent * ) { |
178 | if ( volumeDirection == +1 ) | 173 | if ( volumeDirection == +1 ) |
179 | AudioDevice::increaseVolume(); | 174 | AudioDevice::increaseVolume(); |
180 | else if ( volumeDirection == -1 ) | 175 | else if ( volumeDirection == -1 ) |
181 | AudioDevice::decreaseVolume(); | 176 | AudioDevice::decreaseVolume(); |
182 | } | 177 | } |
183 | 178 | ||