summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-11-04 00:41:07 (UTC)
committer llornkcor <llornkcor>2002-11-04 00:41:07 (UTC)
commit08fdebd78a4266642a7bdb2b1ead6e306bda64ad (patch) (unidiff)
tree8266160d575107b710457c3dfcd84e415268a92d
parentdc44b0babe9ffa7b29cc6269596703bab8edf6ab (diff)
downloadopie-08fdebd78a4266642a7bdb2b1ead6e306bda64ad.zip
opie-08fdebd78a4266642a7bdb2b1ead6e306bda64ad.tar.gz
opie-08fdebd78a4266642a7bdb2b1ead6e306bda64ad.tar.bz2
various
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/audiodevice.cpp76
-rw-r--r--core/multimedia/opieplayer/audiowidget.cpp35
-rw-r--r--core/multimedia/opieplayer/audiowidget.h13
-rw-r--r--core/multimedia/opieplayer/mediaplayer.cpp59
-rw-r--r--core/multimedia/opieplayer/mediaplayerstate.h2
5 files changed, 92 insertions, 93 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp
index 020f6be..136e06c 100644
--- a/core/multimedia/opieplayer/audiodevice.cpp
+++ b/core/multimedia/opieplayer/audiodevice.cpp
@@ -14,204 +14,159 @@
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// L.J.Potter added better error code Fri 02-15-2002 14:37:47 20// L.J.Potter added better error code Fri 02-15-2002 14:37:47
21 21
22 22
23#include <stdlib.h> 23#include <stdlib.h>
24#include <stdio.h> 24#include <stdio.h>
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26#include <qpe/config.h> 26#include <qpe/config.h>
27#include <qmessagebox.h> 27#include <qmessagebox.h>
28 28
29#include "audiodevice.h" 29#include "audiodevice.h"
30 30
31 31
32#include <errno.h> 32#include <errno.h>
33 33
34#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 34#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
35#include "qpe/qcopenvelope_qws.h" 35#include "qpe/qcopenvelope_qws.h"
36#endif 36#endif
37 37
38// #ifdef Q_WS_WIN
39// #include <windows.h>
40// #include <mmsystem.h>
41// #include <mmreg.h>
42// #endif
43#if defined(Q_WS_X11) || defined(Q_WS_QWS) 38#if defined(Q_WS_X11) || defined(Q_WS_QWS)
44#include <fcntl.h> 39#include <fcntl.h>
45#include <sys/ioctl.h> 40#include <sys/ioctl.h>
46#include <sys/soundcard.h> 41#include <sys/soundcard.h>
47#include <sys/stat.h> 42#include <sys/stat.h>
48#include <sys/time.h> 43#include <sys/time.h>
49#include <sys/types.h> 44#include <sys/types.h>
50#include <unistd.h> 45#include <unistd.h>
51#endif 46#endif
52 47
53// #if defined(Q_OS_WIN32)
54// static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000;
55// static const int timerResolutionMilliSeconds = 30;
56// static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond;
57// #else
58# if defined(QT_QWS_IPAQ) 48# if defined(QT_QWS_IPAQ)
59static const int sound_fragment_shift = 14; 49static const int sound_fragment_shift = 14;
60# else 50# else
61static const int sound_fragment_shift = 16; 51static const int sound_fragment_shift = 16;
62# endif 52# endif
63static const int sound_fragment_bytes = (1<<sound_fragment_shift); 53static const int sound_fragment_bytes = (1<<sound_fragment_shift);
64//#endif 54//#endif
65 55
66 56
67class AudioDevicePrivate { 57class AudioDevicePrivate {
68public: 58public:
69 int handle; 59 int handle;
70 unsigned int frequency; 60 unsigned int frequency;
71 unsigned int channels; 61 unsigned int channels;
72 unsigned int bytesPerSample; 62 unsigned int bytesPerSample;
73 unsigned int bufferSize; 63 unsigned int bufferSize;
74//#ifndef Q_OS_WIN32 64//#ifndef Q_OS_WIN32
75 bool can_GETOSPACE; 65 bool can_GETOSPACE;
76 char* unwrittenBuffer; 66 char* unwrittenBuffer;
77 unsigned int unwritten; 67 unsigned int unwritten;
78//#endif 68//#endif
79 69
80 static int dspFd; 70 static int dspFd;
81 static bool muted; 71 static bool muted;
82 static unsigned int leftVolume; 72 static unsigned int leftVolume;
83 static unsigned int rightVolume; 73 static unsigned int rightVolume;
84}; 74};
85 75
86 76
87#ifdef Q_WS_QWS 77#ifdef Q_WS_QWS
88// This is for keeping the device open in-between playing files when 78// This is for keeping the device open in-between playing files when
89// the device makes clicks and it starts to drive you insane! :) 79// the device makes clicks and it starts to drive you insane! :)
90// Best to have the device not open when not using it though 80// Best to have the device not open when not using it though
91//#define KEEP_DEVICE_OPEN 81//#define KEEP_DEVICE_OPEN
92#endif 82#endif
93 83
94 84
95int AudioDevicePrivate::dspFd = 0; 85int AudioDevicePrivate::dspFd = 0;
96bool AudioDevicePrivate::muted = FALSE; 86bool AudioDevicePrivate::muted = FALSE;
97unsigned int AudioDevicePrivate::leftVolume = 0; 87unsigned int AudioDevicePrivate::leftVolume = 0;
98unsigned int AudioDevicePrivate::rightVolume = 0; 88unsigned int AudioDevicePrivate::rightVolume = 0;
99 89
100 90
101void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) { 91void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) {
102 muted = AudioDevicePrivate::muted; 92 muted = AudioDevicePrivate::muted;
103 unsigned int volume; 93 unsigned int volume;
104// #ifdef Q_OS_WIN32
105// HWAVEOUT handle;
106// WAVEFORMATEX formatData;
107// formatData.cbSize = sizeof(WAVEFORMATEX);
108// formatData.wFormatTag = WAVE_FORMAT_PCM;
109// formatData.nAvgBytesPerSec = 4 * 44000;
110// formatData.nBlockAlign = 4;
111// formatData.nChannels = 2;
112// formatData.nSamplesPerSec = 44000;
113// formatData.wBitsPerSample = 16;
114// waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL);
115// if ( waveOutGetVolume( handle, (LPDWORD)&volume ) )
116// // qDebug( "get volume of audio device failed" );
117// waveOutClose( handle );
118// leftVolume = volume & 0xFFFF;
119// rightVolume = volume >> 16;
120// #else
121 int mixerHandle = open( "/dev/mixer", O_RDWR ); 94 int mixerHandle = open( "/dev/mixer", O_RDWR );
122 if ( mixerHandle >= 0 ) { 95 if ( mixerHandle >= 0 ) {
123 if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1) 96 if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1)
124 perror("ioctl(\"MIXER_READ\")"); 97 perror("ioctl(\"MIXER_READ\")");
125 close( mixerHandle ); 98 close( mixerHandle );
126 } else 99 } else
127 perror("open(\"/dev/mixer\")"); 100 perror("open(\"/dev/mixer\")");
128 leftVolume = ((volume & 0x00FF) << 16) / 101; 101 leftVolume = ((volume & 0x00FF) << 16) / 101;
129 rightVolume = ((volume & 0xFF00) << 8) / 101; 102 rightVolume = ((volume & 0xFF00) << 8) / 101;
130//#endif
131} 103}
132 104
133 105
134void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) { 106void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) {
135 AudioDevicePrivate::muted = muted; 107 AudioDevicePrivate::muted = muted;
136 if ( muted ) { 108 if ( muted ) {
137 AudioDevicePrivate::leftVolume = leftVolume; 109 AudioDevicePrivate::leftVolume = leftVolume;
138 AudioDevicePrivate::rightVolume = rightVolume; 110 AudioDevicePrivate::rightVolume = rightVolume;
139 leftVolume = 0; 111 leftVolume = 0;
140 rightVolume = 0; 112 rightVolume = 0;
141 } else { 113 } else {
142 leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume ); 114 leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume );
143 rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume ); 115 rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume );
144 } 116 }
145// #ifdef Q_OS_WIN32
146// HWAVEOUT handle;
147// WAVEFORMATEX formatData;
148// formatData.cbSize = sizeof(WAVEFORMATEX);
149// formatData.wFormatTag = WAVE_FORMAT_PCM;
150// formatData.nAvgBytesPerSec = 4 * 44000;
151// formatData.nBlockAlign = 4;
152// formatData.nChannels = 2;
153// formatData.nSamplesPerSec = 44000;
154// formatData.wBitsPerSample = 16;
155// waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL);
156// unsigned int volume = (rightVolume << 16) | leftVolume;
157// if ( waveOutSetVolume( handle, volume ) )
158// // qDebug( "set volume of audio device failed" );
159// waveOutClose( handle );
160// #else
161 // Volume can be from 0 to 100 which is 101 distinct values 117 // Volume can be from 0 to 100 which is 101 distinct values
162 unsigned int rV = (rightVolume * 101) >> 16; 118 unsigned int rV = (rightVolume * 101) >> 16;
163 119
164# if 0 120# if 0
165 unsigned int lV = (leftVolume * 101) >> 16; 121 unsigned int lV = (leftVolume * 101) >> 16;
166 unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF); 122 unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF);
167 int mixerHandle = 0; 123 int mixerHandle = 0;
168 if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) { 124 if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
169 if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1) 125 if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1)
170 perror("ioctl(\"MIXER_WRITE\")"); 126 perror("ioctl(\"MIXER_WRITE\")");
171 close( mixerHandle ); 127 close( mixerHandle );
172 } else 128 } else
173 perror("open(\"/dev/mixer\")"); 129 perror("open(\"/dev/mixer\")");
174 130
175# else 131# else
176 // This is the way this has to be done now I guess, doesn't allow for 132 // This is the way this has to be done now I guess, doesn't allow for
177 // independant right and left channel setting, or setting for different outputs 133 // independant right and left channel setting, or setting for different outputs
178 Config cfg("qpe"); // qtopia is "Sound" 134 Config cfg("qpe"); // qtopia is "Sound"
179 cfg.setGroup("Volume"); // qtopia is "Settings" 135 cfg.setGroup("Volume"); // qtopia is "Settings"
180 cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume 136 cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume
181# endif 137# endif
182 138
183//#endif 139//#endif
184// qDebug( "setting volume to: 0x%x", volume ); 140// qDebug( "setting volume to: 0x%x", volume );
185#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 141#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
186 // Send notification that the volume has changed 142 // Send notification that the volume has changed
187 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted; 143 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted;
188#endif 144#endif
189} 145}
190 146
191 147
192 148
193
194AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) { 149AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
195 qDebug("creating new audio device"); 150 qDebug("creating new audio device");
196 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; 151 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE;
197 d = new AudioDevicePrivate; 152 d = new AudioDevicePrivate;
198 d->frequency = f; 153 d->frequency = f;
199 d->channels = chs; 154 d->channels = chs;
200 d->bytesPerSample = bps; 155 d->bytesPerSample = bps;
201 qDebug("%d",bps); 156 qDebug("%d",bps);
202 int format=0; 157 int format=0;
203 if( bps == 8) format = AFMT_U8; 158 if( bps == 8) format = AFMT_U8;
204 else if( bps <= 0) format = AFMT_S16_LE; 159 else if( bps <= 0) format = AFMT_S16_LE;
205 else format = AFMT_S16_LE; 160 else format = AFMT_S16_LE;
206 qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format); 161 qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format);
207 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) ); 162 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
208 163
209 int fragments = 0x10000 * 8 + sound_fragment_shift; 164 int fragments = 0x10000 * 8 + sound_fragment_shift;
210 int capabilities = 0; 165 int capabilities = 0;
211 166
212 167
213#ifdef KEEP_DEVICE_OPEN 168#ifdef KEEP_DEVICE_OPEN
214 if ( AudioDevicePrivate::dspFd == 0 ) { 169 if ( AudioDevicePrivate::dspFd == 0 ) {
215#endif 170#endif
216 if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) { 171 if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) {
217 172
@@ -245,145 +200,114 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
245 if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) 200 if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1)
246 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 201 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
247 } 202 }
248 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; 203 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
249 204
250 d->bufferSize = sound_fragment_bytes; 205 d->bufferSize = sound_fragment_bytes;
251 d->unwrittenBuffer = new char[d->bufferSize]; 206 d->unwrittenBuffer = new char[d->bufferSize];
252 d->unwritten = 0; 207 d->unwritten = 0;
253 d->can_GETOSPACE = TRUE; // until we find otherwise 208 d->can_GETOSPACE = TRUE; // until we find otherwise
254 209
255 //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); 210 //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels );
256 //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); 211 //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency );
257 //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); 212 //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" );
258 //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); 213 //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" );
259 //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); 214 //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" );
260 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); 215 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" );
261 216
262} 217}
263 218
264 219
265AudioDevice::~AudioDevice() { 220AudioDevice::~AudioDevice() {
266 qDebug("destryo audiodevice"); 221 qDebug("destryo audiodevice");
267 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE; 222 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE;
268 223
269// #ifdef Q_OS_WIN32
270// waveOutClose( (HWAVEOUT)d->handle );
271// #else
272# ifndef KEEP_DEVICE_OPEN 224# ifndef KEEP_DEVICE_OPEN
273 close( d->handle ); // Now it should be safe to shut the handle 225 close( d->handle ); // Now it should be safe to shut the handle
274# endif 226# endif
275 delete d->unwrittenBuffer; 227 delete d->unwrittenBuffer;
276 delete d; 228 delete d;
277//#endif
278 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE; 229 QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
279 230
280} 231}
281 232
282 233
283void AudioDevice::volumeChanged( bool muted ) 234void AudioDevice::volumeChanged( bool muted )
284{ 235{
285 AudioDevicePrivate::muted = muted; 236 AudioDevicePrivate::muted = muted;
286} 237}
287 238
288 239
289void AudioDevice::write( char *buffer, unsigned int length ) 240void AudioDevice::write( char *buffer, unsigned int length )
290{ 241{
291// #ifdef Q_OS_WIN32
292// // returns immediately and (to be implemented) emits completedIO() when finished writing
293// WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) );
294// // maybe the buffer should be copied so that this fool proof, but its a performance hit
295// lpWaveHdr->lpData = buffer;
296// lpWaveHdr->dwBufferLength = length;
297// lpWaveHdr->dwFlags = 0L;
298// lpWaveHdr->dwLoops = 0L;
299// waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) );
300// // waveOutWrite returns immediately. the data is sent in the background.
301// if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) )
302// qDebug( "failed to write block to audio device" );
303// // emit completedIO();
304// #else
305 int t = ::write( d->handle, buffer, length ); 242 int t = ::write( d->handle, buffer, length );
306 if ( t<0 ) t = 0; 243 if ( t<0 ) t = 0;
307 if ( t != (int)length) { 244 if ( t != (int)length) {
308 qDebug("Ahhh!! memcpys 1"); 245 qDebug("Ahhh!! memcpys 1");
309 memcpy(d->unwrittenBuffer,buffer+t,length-t); 246 memcpy(d->unwrittenBuffer,buffer+t,length-t);
310 d->unwritten = length-t; 247 d->unwritten = length-t;
311 } 248 }
312//#endif 249//#endif
313} 250}
314 251
315 252
316unsigned int AudioDevice::channels() const 253unsigned int AudioDevice::channels() const
317{ 254{
318 return d->channels; 255 return d->channels;
319} 256}
320 257
321 258
322unsigned int AudioDevice::frequency() const 259unsigned int AudioDevice::frequency() const
323{ 260{
324 return d->frequency; 261 return d->frequency;
325} 262}
326 263
327 264
328unsigned int AudioDevice::bytesPerSample() const 265unsigned int AudioDevice::bytesPerSample() const
329{ 266{
330 return d->bytesPerSample; 267 return d->bytesPerSample;
331} 268}
332 269
333 270
334unsigned int AudioDevice::bufferSize() const 271unsigned int AudioDevice::bufferSize() const
335{ 272{
336 return d->bufferSize; 273 return d->bufferSize;
337} 274}
338 275
339unsigned int AudioDevice::canWrite() const 276unsigned int AudioDevice::canWrite() const
340{ 277{
341// #ifdef Q_OS_WIN32
342// return bufferSize(); // Any better?
343// #else
344 audio_buf_info info; 278 audio_buf_info info;
345 if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) { 279 if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) {
346 d->can_GETOSPACE = FALSE; 280 d->can_GETOSPACE = FALSE;
347 fcntl( d->handle, F_SETFL, O_NONBLOCK ); 281 fcntl( d->handle, F_SETFL, O_NONBLOCK );
348 } 282 }
349 if ( d->can_GETOSPACE ) { 283 if ( d->can_GETOSPACE ) {
350 int t = info.fragments * sound_fragment_bytes; 284 int t = info.fragments * sound_fragment_bytes;
351 return QMIN(t,(int)bufferSize()); 285 return QMIN(t,(int)bufferSize());
352 } else { 286 } else {
353 if ( d->unwritten ) { 287 if ( d->unwritten ) {
354 int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten ); 288 int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten );
355 if ( t<0 ) t = 0; 289 if ( t<0 ) t = 0;
356 if ( (unsigned)t!=d->unwritten ) { 290 if ( (unsigned)t!=d->unwritten ) {
357 memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t); 291 memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t);
358 d->unwritten -= t; 292 d->unwritten -= t;
359 } else { 293 } else {
360 d->unwritten = 0; 294 d->unwritten = 0;
361 } 295 }
362 } 296 }
363 if ( d->unwritten ) 297 if ( d->unwritten )
364 return 0; 298 return 0;
365 else 299 else
366 return d->bufferSize; 300 return d->bufferSize;
367 } 301 }
368//#endif
369} 302}
370 303
371 304
372int AudioDevice::bytesWritten() { 305int AudioDevice::bytesWritten() {
373// #ifdef Q_OS_WIN32
374// MMTIME pmmt = { TIME_BYTES, 0 };
375// if ( ( waveOutGetPosition( (HWAVEOUT)d->handle, &pmmt, sizeof(MMTIME) ) != MMSYSERR_NOERROR ) || ( pmmt.wType != TIME_BYTES ) ) {
376// qDebug( "failed to get audio device position" );
377// return -1;
378// }
379// return pmmt.u.cb;
380// #else
381 int buffered = 0; 306 int buffered = 0;
382 if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) { 307 if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) {
383 qDebug( "failed to get audio device position" ); 308 qDebug( "failed to get audio device position" );
384 return -1; 309 return -1;
385 } 310 }
386 return buffered; 311 return buffered;
387//#endif
388} 312}
389 313
diff --git a/core/multimedia/opieplayer/audiowidget.cpp b/core/multimedia/opieplayer/audiowidget.cpp
index d20d560..ef7c8dc 100644
--- a/core/multimedia/opieplayer/audiowidget.cpp
+++ b/core/multimedia/opieplayer/audiowidget.cpp
@@ -125,56 +125,56 @@ AudioWidget::AudioWidget(QWidget* parent, const char* name, WFlags f) :
125 songInfo.setFrameStyle( QFrame::NoFrame); 125 songInfo.setFrameStyle( QFrame::NoFrame);
126// songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 126// songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
127 //NoFrame 127 //NoFrame
128// songInfo.setForegroundColor(Qt::white); 128// songInfo.setForegroundColor(Qt::white);
129 129
130 slider.setFixedHeight( 20 ); 130 slider.setFixedHeight( 20 );
131 slider.setMinValue( 0 ); 131 slider.setMinValue( 0 );
132 slider.setMaxValue( 1 ); 132 slider.setMaxValue( 1 );
133 slider.setFocusPolicy( QWidget::NoFocus ); 133 slider.setFocusPolicy( QWidget::NoFocus );
134 slider.setBackgroundPixmap( *pixBg ); 134 slider.setBackgroundPixmap( *pixBg );
135 135
136 time.setFocusPolicy( QWidget::NoFocus ); 136 time.setFocusPolicy( QWidget::NoFocus );
137 time.setAlignment( Qt::AlignCenter ); 137 time.setAlignment( Qt::AlignCenter );
138 time.setFrame(FALSE); 138 time.setFrame(FALSE);
139 changeTextColor( &time ); 139 changeTextColor( &time );
140 140
141 resizeEvent( NULL ); 141 resizeEvent( NULL );
142 142
143 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); 143 connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
144 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); 144 connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
145 145
146 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) ); 146 connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) );
147 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) ); 147 connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) );
148 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); 148 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) );
149 connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); 149// connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) );
150 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) ); 150 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) );
151 151
152 // Intialise state 152 // Intialise state
153 setLength( mediaPlayerState->length() ); 153 setLength( mediaPlayerState->length() );
154 setPosition( mediaPlayerState->position() ); 154 setPosition( mediaPlayerState->position() );
155 setLooping( mediaPlayerState->fullscreen() ); 155 setLooping( mediaPlayerState->fullscreen() );
156 setPaused( mediaPlayerState->paused() ); 156// setPaused( mediaPlayerState->paused() );
157 setPlaying( mediaPlayerState->playing() ); 157 setPlaying( mediaPlayerState->playing() );
158 158
159} 159}
160 160
161 161
162AudioWidget::~AudioWidget() { 162AudioWidget::~AudioWidget() {
163 163
164 for ( int i = 0; i < 10; i++ ) { 164 for ( int i = 0; i < 10; i++ ) {
165 delete buttonPixUp[i]; 165 delete buttonPixUp[i];
166 delete buttonPixDown[i]; 166 delete buttonPixDown[i];
167 } 167 }
168 delete pixBg; 168 delete pixBg;
169 delete imgUp; 169 delete imgUp;
170 delete imgDn; 170 delete imgDn;
171 delete imgButtonMask; 171 delete imgButtonMask;
172 for ( int i = 0; i < 10; i++ ) { 172 for ( int i = 0; i < 10; i++ ) {
173 delete masks[i]; 173 delete masks[i];
174 } 174 }
175} 175}
176 176
177 177
178QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { 178QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) {
179 QPixmap pix( img.width(), img.height() ); 179 QPixmap pix( img.width(), img.height() );
180 QPainter p( &pix ); 180 QPainter p( &pix );
@@ -342,63 +342,80 @@ void AudioWidget::timerEvent( QTimerEvent * ) {
342 342
343 343
344void AudioWidget::mouseMoveEvent( QMouseEvent *event ) { 344void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
345 for ( int i = 0; i < numButtons; i++ ) { 345 for ( int i = 0; i < numButtons; i++ ) {
346 if ( event->state() == QMouseEvent::LeftButton ) { 346 if ( event->state() == QMouseEvent::LeftButton ) {
347 347
348 // The test to see if the mouse click is inside the button or not 348 // The test to see if the mouse click is inside the button or not
349 int x = event->pos().x() - xoff; 349 int x = event->pos().x() - xoff;
350 int y = event->pos().y() - yoff; 350 int y = event->pos().y() - yoff;
351 351
352 bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() 352 bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width()
353 && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 ); 353 && y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 );
354 354
355 if ( isOnButton && i == AudioVolumeUp ) 355 if ( isOnButton && i == AudioVolumeUp )
356 qDebug("on up"); 356 qDebug("on up");
357 357
358 if ( isOnButton && !audioButtons[i].isHeld ) { 358 if ( isOnButton && !audioButtons[i].isHeld ) {
359 audioButtons[i].isHeld = TRUE; 359 audioButtons[i].isHeld = TRUE;
360 toggleButton(i); 360 toggleButton(i);
361 switch (i) { 361 switch (i) {
362 case AudioVolumeUp: 362 case AudioVolumeUp:
363 qDebug("more clicked"); 363 qDebug("more clicked");
364 emit moreClicked(); 364 emit moreClicked();
365 return; 365 return;
366 case AudioVolumeDown: emit lessClicked(); return; 366 case AudioVolumeDown:
367 qDebug("less clicked");
368 emit lessClicked();
369 return;
370 case AudioForward:
371 emit forwardClicked();
372 return;
373 case AudioBack:
374 emit backClicked();
375 return;
367 } 376 }
368 } else if ( !isOnButton && audioButtons[i].isHeld ) { 377 } else if ( !isOnButton && audioButtons[i].isHeld ) {
369 audioButtons[i].isHeld = FALSE; 378 audioButtons[i].isHeld = FALSE;
370 toggleButton(i); 379 toggleButton(i);
371 } 380 }
372 } else { 381 } else {
373 if ( audioButtons[i].isHeld ) { 382 if ( audioButtons[i].isHeld ) {
374 audioButtons[i].isHeld = FALSE; 383 audioButtons[i].isHeld = FALSE;
375 if ( !audioButtons[i].isToggle ) 384 if ( !audioButtons[i].isToggle )
376 setToggleButton( i, FALSE ); 385 setToggleButton( i, FALSE );
377 switch (i) { 386 switch (i) {
378 case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return; 387 case AudioPlay:
388 if( mediaPlayerState->isPaused ) {
389 mediaPlayerState->setPaused( FALSE );
390 return;
391 } else if( !mediaPlayerState->isPaused ) {
392 mediaPlayerState->setPaused( TRUE );
393 return;
394 }
395// case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return;
379 case AudioStop: mediaPlayerState->setPlaying(FALSE); return; 396 case AudioStop: mediaPlayerState->setPlaying(FALSE); return;
380 case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return; 397// case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return;
381 case AudioNext: mediaPlayerState->setNext(); return; 398 case AudioNext: mediaPlayerState->setNext(); return;
382 case AudioPrevious: mediaPlayerState->setPrev(); return; 399 case AudioPrevious: mediaPlayerState->setPrev(); return;
383 case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return; 400 case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return;
384 case AudioVolumeUp: emit moreReleased(); return; 401 case AudioVolumeUp: emit moreReleased(); return;
385 case AudioVolumeDown: emit lessReleased(); return; 402 case AudioVolumeDown: emit lessReleased(); return;
386 case AudioPlayList: mediaPlayerState->setList(); return; 403 case AudioPlayList: mediaPlayerState->setList(); return;
387 } 404 }
388 } 405 }
389 } 406 }
390 } 407 }
391} 408}
392 409
393 410
394 411
395void AudioWidget::mousePressEvent( QMouseEvent *event ) { 412void AudioWidget::mousePressEvent( QMouseEvent *event ) {
396 mouseMoveEvent( event ); 413 mouseMoveEvent( event );
397} 414}
398 415
399 416
400void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) { 417void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) {
401 mouseMoveEvent( event ); 418 mouseMoveEvent( event );
402} 419}
403 420
404 421
@@ -442,50 +459,50 @@ void AudioWidget::keyReleaseEvent( QKeyEvent *e)
442// qDebug("Audio F9"); 459// qDebug("Audio F9");
443 break; 460 break;
444 case Key_F10: //contacts 461 case Key_F10: //contacts
445 break; 462 break;
446 case Key_F11: //menu 463 case Key_F11: //menu
447 break; 464 break;
448 case Key_F12: //home 465 case Key_F12: //home
449 break; 466 break;
450 case Key_F13: //mail 467 case Key_F13: //mail
451 break; 468 break;
452 case Key_Space: { 469 case Key_Space: {
453 470
454 if(mediaPlayerState->playing()) { 471 if(mediaPlayerState->playing()) {
455// toggleButton(1); 472// toggleButton(1);
456 mediaPlayerState->setPlaying(FALSE); 473 mediaPlayerState->setPlaying(FALSE);
457// toggleButton(1); 474// toggleButton(1);
458 } else { 475 } else {
459// toggleButton(0); 476// toggleButton(0);
460 mediaPlayerState->setPlaying(TRUE); 477 mediaPlayerState->setPlaying(TRUE);
461// toggleButton(0); 478// toggleButton(0);
462 } 479 }
463 } 480 }
464 break; 481 break;
465 case Key_Down: //volume 482 case Key_Down: //volume
466 toggleButton(6); 483// toggleButton(6);
467 emit lessClicked(); 484 emit lessClicked();
468 emit lessReleased(); 485 emit lessReleased();
469 toggleButton(6); 486// toggleButton(6);
470 break; 487 break;
471 case Key_Up: //volume 488 case Key_Up: //volume
472 toggleButton(5); 489// toggleButton(5);
473 emit moreClicked(); 490 emit moreClicked();
474 emit moreReleased(); 491 emit moreReleased();
475 toggleButton(5); 492// toggleButton(5);
476 break; 493 break;
477 case Key_Right: //next in playlist 494 case Key_Right: //next in playlist
478// toggleButton(3); 495// toggleButton(3);
479 mediaPlayerState->setNext(); 496 mediaPlayerState->setNext();
480// toggleButton(3); 497// toggleButton(3);
481 break; 498 break;
482 case Key_Left: // previous in playlist 499 case Key_Left: // previous in playlist
483// toggleButton(4); 500// toggleButton(4);
484 mediaPlayerState->setPrev(); 501 mediaPlayerState->setPrev();
485// toggleButton(4); 502// toggleButton(4);
486 break; 503 break;
487 case Key_Escape: 504 case Key_Escape:
488 break; 505 break;
489 506
490 }; 507 };
491} 508}
diff --git a/core/multimedia/opieplayer/audiowidget.h b/core/multimedia/opieplayer/audiowidget.h
index c686741..96bc55c 100644
--- a/core/multimedia/opieplayer/audiowidget.h
+++ b/core/multimedia/opieplayer/audiowidget.h
@@ -15,86 +15,91 @@
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#ifndef AUDIO_WIDGET_H 21#ifndef AUDIO_WIDGET_H
22#define AUDIO_WIDGET_H 22#define AUDIO_WIDGET_H
23 23
24#include <qwidget.h> 24#include <qwidget.h>
25#include <qpainter.h> 25#include <qpainter.h>
26#include <qdrawutil.h> 26#include <qdrawutil.h>
27#include <qpixmap.h> 27#include <qpixmap.h>
28#include <qbitmap.h> 28#include <qbitmap.h>
29#include <qstring.h> 29#include <qstring.h>
30#include <qslider.h> 30#include <qslider.h>
31#include <qlineedit.h> 31#include <qlineedit.h>
32#include <qframe.h> 32#include <qframe.h>
33 33
34#include <opie/oticker.h> 34#include <opie/oticker.h>
35 35
36class QPixmap; 36class QPixmap;
37 37
38enum AudioButtons { 38enum AudioButtons {
39 AudioPlay, 39 AudioPlay=0,
40 AudioStop, 40 AudioStop,
41 AudioPause,
42 AudioNext, 41 AudioNext,
43 AudioPrevious, 42 AudioPrevious,
44 AudioVolumeUp, 43 AudioVolumeUp,
45 AudioVolumeDown, 44 AudioVolumeDown,
46 AudioLoop, 45 AudioLoop,
47 AudioPlayList 46 AudioPlayList,
47 AudioForward,
48 AudioBack
48}; 49};
49 50
50 51
51//#define USE_DBLBUF 52//#define USE_DBLBUF
52 53
53class AudioWidget : public QWidget { 54class AudioWidget : public QWidget {
54 Q_OBJECT 55 Q_OBJECT
55public: 56public:
56 AudioWidget( QWidget* parent=0, const char* name=0, WFlags f=0 ); 57 AudioWidget( QWidget* parent=0, const char* name=0, WFlags f=0 );
57 ~AudioWidget(); 58 ~AudioWidget();
58 void setTickerText( const QString &text ) { songInfo.setText( text ); } 59 void setTickerText( const QString &text ) { songInfo.setText( text ); }
59 bool isStreaming; 60 bool isStreaming;
60public slots: 61public slots:
61 void updateSlider( long, long ); 62 void updateSlider( long, long );
62 void sliderPressed( ); 63 void sliderPressed( );
63 void sliderReleased( ); 64 void sliderReleased( );
64 void setPaused( bool b) { setToggleButton( AudioPause, b ); } 65// void setPaused( bool b) { setToggleButton( AudioPause, b ); }
65 void setLooping( bool b) { setToggleButton( AudioLoop, b ); } 66 void setLooping( bool b) { setToggleButton( AudioLoop, b ); }
66 void setPlaying( bool b) { setToggleButton( AudioPlay, b ); } 67 void setPlaying( bool b) { setToggleButton( AudioPlay, b ); }
67 void setPosition( long ); 68 void setPosition( long );
68 void setLength( long ); 69 void setLength( long );
69 void setView( char ); 70 void setView( char );
70 71
71signals: 72signals:
72 void moreClicked(); 73 void moreClicked();
73 void lessClicked(); 74 void lessClicked();
74 void moreReleased(); 75 void moreReleased();
75 void lessReleased(); 76 void lessReleased();
76 void sliderMoved(long); 77 void sliderMoved(long);
78 void forwardClicked();
79 void backClicked();
80 void forwardReleased();
81 void backReleased();
77 82
78protected: 83protected:
79 void doBlank(); 84 void doBlank();
80 void doUnblank(); 85 void doUnblank();
81 void paintEvent( QPaintEvent *pe ); 86 void paintEvent( QPaintEvent *pe );
82 void showEvent( QShowEvent *se ); 87 void showEvent( QShowEvent *se );
83 void resizeEvent( QResizeEvent *re ); 88 void resizeEvent( QResizeEvent *re );
84 void mouseMoveEvent( QMouseEvent *event ); 89 void mouseMoveEvent( QMouseEvent *event );
85 void mousePressEvent( QMouseEvent *event ); 90 void mousePressEvent( QMouseEvent *event );
86 void mouseReleaseEvent( QMouseEvent *event ); 91 void mouseReleaseEvent( QMouseEvent *event );
87 void timerEvent( QTimerEvent *event ); 92 void timerEvent( QTimerEvent *event );
88 void closeEvent( QCloseEvent *event ); 93 void closeEvent( QCloseEvent *event );
89 void keyReleaseEvent( QKeyEvent *e); 94 void keyReleaseEvent( QKeyEvent *e);
90private: 95private:
91 void toggleButton( int ); 96 void toggleButton( int );
92 void setToggleButton( int, bool ); 97 void setToggleButton( int, bool );
93 void paintButton( QPainter *p, int i ); 98 void paintButton( QPainter *p, int i );
94 QString skin; 99 QString skin;
95 QPixmap *pixBg; 100 QPixmap *pixBg;
96 QImage *imgUp; 101 QImage *imgUp;
97 QImage *imgDn; 102 QImage *imgDn;
98 QImage *imgButtonMask; 103 QImage *imgButtonMask;
99 QBitmap *masks[11]; 104 QBitmap *masks[11];
100 QPixmap *buttonPixUp[11]; 105 QPixmap *buttonPixUp[11];
diff --git a/core/multimedia/opieplayer/mediaplayer.cpp b/core/multimedia/opieplayer/mediaplayer.cpp
index b0963cf..4f3823a 100644
--- a/core/multimedia/opieplayer/mediaplayer.cpp
+++ b/core/multimedia/opieplayer/mediaplayer.cpp
@@ -85,56 +85,58 @@ void MediaPlayer::setPlaying( bool play ) {
85 mediaPlayerState->setPaused( FALSE ); 85 mediaPlayerState->setPaused( FALSE );
86 loopControl->stop( FALSE ); 86 loopControl->stop( FALSE );
87 return; 87 return;
88 } 88 }
89 89
90 if ( mediaPlayerState->paused() ) { 90 if ( mediaPlayerState->paused() ) {
91 mediaPlayerState->setPaused( FALSE ); 91 mediaPlayerState->setPaused( FALSE );
92 return; 92 return;
93 } 93 }
94 qDebug("about to ctrash"); 94 qDebug("about to ctrash");
95 const DocLnk *playListCurrent = playList->current(); 95 const DocLnk *playListCurrent = playList->current();
96 96
97 if ( playListCurrent != NULL ) { 97 if ( playListCurrent != NULL ) {
98 loopControl->stop( TRUE ); 98 loopControl->stop( TRUE );
99 currentFile = playListCurrent; 99 currentFile = playListCurrent;
100 } 100 }
101 if ( currentFile == NULL ) { 101 if ( currentFile == NULL ) {
102 QMessageBox::critical( 0, tr( "No file"), tr( "Error: There is no file selected" ) ); 102 QMessageBox::critical( 0, tr( "No file"), tr( "Error: There is no file selected" ) );
103 mediaPlayerState->setPlaying( FALSE ); 103 mediaPlayerState->setPlaying( FALSE );
104 return; 104 return;
105 } 105 }
106 106
107 if ( ((currentFile->file()).left(4) != "http") && !QFile::exists( currentFile->file() ) ) { 107 if ( ((currentFile->file()).left(4) != "http") && !QFile::exists( currentFile->file() ) ) {
108 QMessageBox::critical( 0, tr( "File not found"), 108 QMessageBox::critical( 0, tr( "File not found"),
109 tr( "The following file was not found: <i>" ) + currentFile->file() + "</i>" ); 109 tr( "The following file was not found: <i>" )
110 + currentFile->file() + "</i>" );
110 mediaPlayerState->setPlaying( FALSE ); 111 mediaPlayerState->setPlaying( FALSE );
111 return; 112 return;
112 } 113 }
113 114
114 if ( !mediaPlayerState->newDecoder( currentFile->file() ) ) { 115 if ( !mediaPlayerState->newDecoder( currentFile->file() ) ) {
115 QMessageBox::critical( 0, tr( "No decoder found"), 116 QMessageBox::critical( 0, tr( "No decoder found"),
116 tr( "Sorry, no appropriate decoders found for this file: <i>" ) + currentFile->file() + "</i>" ); 117 tr( "Sorry, no appropriate decoders found for this file: <i>" )
118 + currentFile->file() + "</i>" );
117 mediaPlayerState->setPlaying( FALSE ); 119 mediaPlayerState->setPlaying( FALSE );
118 return; 120 return;
119 } 121 }
120 122
121 if ( !loopControl->init( currentFile->file() ) ) { 123 if ( !loopControl->init( currentFile->file() ) ) {
122 QMessageBox::critical( 0, tr( "Error opening file"), 124 QMessageBox::critical( 0, tr( "Error opening file"),
123 tr( "Sorry, an error occured trying to play the file: <i>" ) + currentFile->file() + "</i>" ); 125 tr( "Sorry, an error occured trying to play the file: <i>" ) + currentFile->file() + "</i>" );
124 mediaPlayerState->setPlaying( FALSE ); 126 mediaPlayerState->setPlaying( FALSE );
125 return; 127 return;
126 } 128 }
127 long seconds = loopControl->totalPlaytime(); 129 long seconds = loopControl->totalPlaytime();
128 QString time; time.sprintf("%li:%02i", seconds/60, (int)seconds%60 ); 130 QString time; time.sprintf("%li:%02i", seconds/60, (int)seconds%60 );
129 QString tickerText; 131 QString tickerText;
130 if( currentFile->file().left(4) == "http" ) 132 if( currentFile->file().left(4) == "http" )
131 tickerText= tr( " File: " ) + currentFile->name(); 133 tickerText= tr( " File: " ) + currentFile->name();
132 else 134 else
133 tickerText = tr( " File: " ) + currentFile->name() + tr(", Length: ") + time; 135 tickerText = tr( " File: " ) + currentFile->name() + tr(", Length: ") + time;
134 136
135 QString fileInfo = mediaPlayerState->curDecoder()->fileInfo(); 137 QString fileInfo = mediaPlayerState->curDecoder()->fileInfo();
136 if ( !fileInfo.isEmpty() ) 138 if ( !fileInfo.isEmpty() )
137 tickerText += ", " + fileInfo; 139 tickerText += ", " + fileInfo;
138 audioUI->setTickerText( tickerText + "." ); 140 audioUI->setTickerText( tickerText + "." );
139 141
140 loopControl->play(); 142 loopControl->play();
@@ -155,61 +157,112 @@ void MediaPlayer::prev() {
155 157
156 158
157void MediaPlayer::next() { 159void MediaPlayer::next() {
158 if ( playList->next() ) 160 if ( playList->next() )
159 play(); 161 play();
160 else if ( mediaPlayerState->looping() ) { 162 else if ( mediaPlayerState->looping() ) {
161 if ( playList->first() ) 163 if ( playList->first() )
162 play(); 164 play();
163 } else 165 } else
164 mediaPlayerState->setList(); 166 mediaPlayerState->setList();
165} 167}
166 168
167 169
168void MediaPlayer::startDecreasingVolume() { 170void MediaPlayer::startDecreasingVolume() {
169 volumeDirection = -1; 171 volumeDirection = -1;
170 startTimer( 100 ); 172 startTimer( 100 );
171 AudioDevice::decreaseVolume(); 173 AudioDevice::decreaseVolume();
172} 174}
173 175
174 176
175void MediaPlayer::startIncreasingVolume() { 177void MediaPlayer::startIncreasingVolume() {
176 volumeDirection = +1; 178 volumeDirection = +1;
177 startTimer( 100 ); 179 startTimer( 100 );
178 AudioDevice::increaseVolume(); 180 AudioDevice::increaseVolume();
181
179} 182}
180 183
184bool drawnOnScreenDisplay = FALSE;
185unsigned int onScreenDisplayVolume = 0;
186const int yoff = 110;
181 187
182void MediaPlayer::stopChangingVolume() { 188void MediaPlayer::stopChangingVolume() {
183 killTimers(); 189 killTimers();
190
191 // Get rid of the on-screen display stuff
192 drawnOnScreenDisplay = FALSE;
193 onScreenDisplayVolume = 0;
194 int w = audioUI->width();
195 int h = audioUI->height();
196 audioUI->repaint( (w - 200) / 2, h - yoff, 200 + 9, 70, FALSE );
184} 197}
185 198
186 199
187void MediaPlayer::timerEvent( QTimerEvent * ) { 200void MediaPlayer::timerEvent( QTimerEvent * ) {
201// qDebug("timer");
188 if ( volumeDirection == +1 ) 202 if ( volumeDirection == +1 )
189 AudioDevice::increaseVolume(); 203 AudioDevice::increaseVolume();
190 else if ( volumeDirection == -1 ) 204 else if ( volumeDirection == -1 )
191 AudioDevice::decreaseVolume(); 205 AudioDevice::decreaseVolume();
206
207 // Display an on-screen display volume
208 unsigned int l, r, v; bool m;
209 AudioDevice::getVolume( l, r, m );
210 v = ((l + r) * 11) / (2*0xFFFF);
211
212 if ( drawnOnScreenDisplay && onScreenDisplayVolume == v ) {
213// qDebug("returning %d, %d, %d, %d", v, l, r, m);
214 return;
215 }
216
217 int w = audioUI->width();
218 int h = audioUI->height();
219
220 if ( drawnOnScreenDisplay ) {
221 if ( onScreenDisplayVolume > v )
222 audioUI->repaint( (w - 200) / 2 + v * 20 + 0, h - yoff + 40,
223 (onScreenDisplayVolume - v) * 20 + 9, 30, FALSE );
224 }
225
226 drawnOnScreenDisplay = TRUE;
227 onScreenDisplayVolume = v;
228
229 QPainter p( audioUI );
230 p.setPen( QColor( 0x10, 0xD0, 0x10 ) );
231 p.setBrush( QColor( 0x10, 0xD0, 0x10 ) );
232
233 QFont f;
234 f.setPixelSize( 20 );
235 f.setBold( TRUE );
236 p.setFont( f );
237 p.drawText( (w - 200) / 2, h - yoff + 20, tr("Volume") );
238
239 for ( unsigned int i = 0; i < 10; i++ ) {
240 if ( v > i )
241 p.drawRect( (w - 200) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 );
242 else
243 p.drawRect( (w - 200) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 );
244 }
192} 245}
193 246
194void MediaPlayer::keyReleaseEvent( QKeyEvent *e) { 247void MediaPlayer::keyReleaseEvent( QKeyEvent *e) {
195 switch ( e->key() ) { 248 switch ( e->key() ) {
196////////////////////////////// Zaurus keys 249////////////////////////////// Zaurus keys
197 case Key_Home: 250 case Key_Home:
198 break; 251 break;
199 case Key_F9: //activity 252 case Key_F9: //activity
200 break; 253 break;
201 case Key_F10: //contacts 254 case Key_F10: //contacts
202 break; 255 break;
203 case Key_F11: //menu 256 case Key_F11: //menu
204 break; 257 break;
205 case Key_F12: //home 258 case Key_F12: //home
206 qDebug("Blank here"); 259 qDebug("Blank here");
207 break; 260 break;
208 case Key_F13: //mail 261 case Key_F13: //mail
209 break; 262 break;
210 } 263 }
211} 264}
212 265
213void MediaPlayer::doBlank() { 266void MediaPlayer::doBlank() {
214 267
215} 268}
diff --git a/core/multimedia/opieplayer/mediaplayerstate.h b/core/multimedia/opieplayer/mediaplayerstate.h
index 26185c5..1c65599 100644
--- a/core/multimedia/opieplayer/mediaplayerstate.h
+++ b/core/multimedia/opieplayer/mediaplayerstate.h
@@ -12,48 +12,49 @@
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#ifndef MEDIA_PLAYER_STATE_H 20#ifndef MEDIA_PLAYER_STATE_H
21#define MEDIA_PLAYER_STATE_H 21#define MEDIA_PLAYER_STATE_H
22 22
23 23
24#include <qobject.h> 24#include <qobject.h>
25 25
26 26
27class MediaPlayerDecoder; 27class MediaPlayerDecoder;
28class Config; 28class Config;
29 29
30 30
31class MediaPlayerState : public QObject { 31class MediaPlayerState : public QObject {
32Q_OBJECT 32Q_OBJECT
33public: 33public:
34 MediaPlayerState( QObject *parent, const char *name ); 34 MediaPlayerState( QObject *parent, const char *name );
35 ~MediaPlayerState(); 35 ~MediaPlayerState();
36 bool isPaused;
36 37
37 bool isStreaming; 38 bool isStreaming;
38 bool fullscreen() { return isFullscreen; } 39 bool fullscreen() { return isFullscreen; }
39 bool scaled() { return isScaled; } 40 bool scaled() { return isScaled; }
40 bool looping() { return isLooping; } 41 bool looping() { return isLooping; }
41 bool shuffled() { return isShuffled; } 42 bool shuffled() { return isShuffled; }
42 bool playlist() { return usePlaylist; } 43 bool playlist() { return usePlaylist; }
43 bool paused() { return isPaused; } 44 bool paused() { return isPaused; }
44 bool playing() { return isPlaying; } 45 bool playing() { return isPlaying; }
45 long position() { return curPosition; } 46 long position() { return curPosition; }
46 long length() { return curLength; } 47 long length() { return curLength; }
47 char view() { return curView; } 48 char view() { return curView; }
48 49
49 MediaPlayerDecoder *newDecoder( const QString& file ); 50 MediaPlayerDecoder *newDecoder( const QString& file );
50 MediaPlayerDecoder *curDecoder(); 51 MediaPlayerDecoder *curDecoder();
51 MediaPlayerDecoder *libMpeg3Decoder(); // ### Yucky hack needed to use libmpeg3plugin to get the 52 MediaPlayerDecoder *libMpeg3Decoder(); // ### Yucky hack needed to use libmpeg3plugin to get the
52 // number of audio samples if we are using the libmad plugin 53 // number of audio samples if we are using the libmad plugin
53public slots: 54public slots:
54 void setFullscreen( bool b ) { if ( isFullscreen == b ) return; isFullscreen = b; emit fullscreenToggled(b); } 55 void setFullscreen( bool b ) { if ( isFullscreen == b ) return; isFullscreen = b; emit fullscreenToggled(b); }
55 void setScaled( bool b ) { if ( isScaled == b ) return; isScaled = b; emit scaledToggled(b); } 56 void setScaled( bool b ) { if ( isScaled == b ) return; isScaled = b; emit scaledToggled(b); }
56 void setLooping( bool b ) { if ( isLooping == b ) return; isLooping = b; emit loopingToggled(b); } 57 void setLooping( bool b ) { if ( isLooping == b ) return; isLooping = b; emit loopingToggled(b); }
57 void setShuffled( bool b ) { if ( isShuffled == b ) return; isShuffled = b; emit shuffledToggled(b); } 58 void setShuffled( bool b ) { if ( isShuffled == b ) return; isShuffled = b; emit shuffledToggled(b); }
58 void setPlaylist( bool b ) { if ( usePlaylist == b ) return; usePlaylist = b; emit playlistToggled(b); } 59 void setPlaylist( bool b ) { if ( usePlaylist == b ) return; usePlaylist = b; emit playlistToggled(b); }
59 void setPaused( bool b ) { if ( isPaused == b ) return; isPaused = b; emit pausedToggled(b); } 60 void setPaused( bool b ) { if ( isPaused == b ) return; isPaused = b; emit pausedToggled(b); }
@@ -80,42 +81,41 @@ public slots:
80 void togglePlaying() { setPlaying( !isPlaying); } 81 void togglePlaying() { setPlaying( !isPlaying); }
81 82
82signals: 83signals:
83 void fullscreenToggled( bool ); 84 void fullscreenToggled( bool );
84 void scaledToggled( bool ); 85 void scaledToggled( bool );
85 void loopingToggled( bool ); 86 void loopingToggled( bool );
86 void shuffledToggled( bool ); 87 void shuffledToggled( bool );
87 void playlistToggled( bool ); 88 void playlistToggled( bool );
88 void pausedToggled( bool ); 89 void pausedToggled( bool );
89 void playingToggled( bool ); 90 void playingToggled( bool );
90 void positionChanged( long ); // When the slider is moved 91 void positionChanged( long ); // When the slider is moved
91 void positionUpdated( long ); // When the media file progresses 92 void positionUpdated( long ); // When the media file progresses
92 void lengthChanged( long ); 93 void lengthChanged( long );
93 void viewChanged( char ); 94 void viewChanged( char );
94 95
95 void prev(); 96 void prev();
96 void next(); 97 void next();
97 98
98private: 99private:
99 bool isFullscreen; 100 bool isFullscreen;
100 bool isScaled; 101 bool isScaled;
101 bool isLooping; 102 bool isLooping;
102 bool isShuffled; 103 bool isShuffled;
103 bool usePlaylist; 104 bool usePlaylist;
104 bool isPaused;
105 bool isPlaying; 105 bool isPlaying;
106 long curPosition; 106 long curPosition;
107 long curLength; 107 long curLength;
108 char curView; 108 char curView;
109 109
110 MediaPlayerDecoder *decoder; 110 MediaPlayerDecoder *decoder;
111 MediaPlayerDecoder *libmpeg3decoder; 111 MediaPlayerDecoder *libmpeg3decoder;
112// MediaPlayerDecoder *libwavdecoder; 112// MediaPlayerDecoder *libwavdecoder;
113 113
114 void loadPlugins(); 114 void loadPlugins();
115 void readConfig( Config& cfg ); 115 void readConfig( Config& cfg );
116 void writeConfig( Config& cfg ) const; 116 void writeConfig( Config& cfg ) const;
117}; 117};
118 118
119 119
120#endif // MEDIA_PLAYER_STATE_H 120#endif // MEDIA_PLAYER_STATE_H
121 121