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 | |||
@@ -3,181 +3,176 @@ | |||
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include <qpe/qpeapplication.h> | 21 | #include <qpe/qpeapplication.h> |
22 | #include <qpe/qlibrary.h> | 22 | #include <qpe/qlibrary.h> |
23 | #include <qpe/resource.h> | 23 | #include <qpe/resource.h> |
24 | #include <qpe/config.h> | 24 | #include <qpe/config.h> |
25 | 25 | ||
26 | #include <qmainwindow.h> | 26 | #include <qmainwindow.h> |
27 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
28 | #include <qwidgetstack.h> | 28 | #include <qwidgetstack.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | 30 | ||
31 | #include "mediaplayer.h" | 31 | #include "mediaplayer.h" |
32 | #include "playlistwidget.h" | 32 | #include "playlistwidget.h" |
33 | #include "audiowidget.h" | 33 | #include "audiowidget.h" |
34 | #include "loopcontrol.h" | 34 | #include "loopcontrol.h" |
35 | #include "audiodevice.h" | 35 | #include "audiodevice.h" |
36 | 36 | ||
37 | #include "mediaplayerstate.h" | 37 | #include "mediaplayerstate.h" |
38 | 38 | ||
39 | 39 | ||
40 | extern AudioWidget *audioUI; | 40 | extern AudioWidget *audioUI; |
41 | extern PlayListWidget *playList; | 41 | extern PlayListWidget *playList; |
42 | extern LoopControl *loopControl; | 42 | extern LoopControl *loopControl; |
43 | extern MediaPlayerState *mediaPlayerState; | 43 | extern MediaPlayerState *mediaPlayerState; |
44 | 44 | ||
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 | } |
59 | 59 | ||
60 | 60 | ||
61 | MediaPlayer::~MediaPlayer() { | 61 | 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 ); |
161 | AudioDevice::decreaseVolume(); | 156 | AudioDevice::decreaseVolume(); |
162 | } | 157 | } |
163 | 158 | ||
164 | 159 | ||
165 | void MediaPlayer::startIncreasingVolume() { | 160 | void MediaPlayer::startIncreasingVolume() { |
166 | volumeDirection = +1; | 161 | volumeDirection = +1; |
167 | startTimer( 100 ); | 162 | startTimer( 100 ); |
168 | AudioDevice::increaseVolume(); | 163 | AudioDevice::increaseVolume(); |
169 | } | 164 | } |
170 | 165 | ||
171 | 166 | ||
172 | void MediaPlayer::stopChangingVolume() { | 167 | 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 | ||