summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-11-04 00:41:07 (UTC)
committer llornkcor <llornkcor>2002-11-04 00:41:07 (UTC)
commit08fdebd78a4266642a7bdb2b1ead6e306bda64ad (patch) (side-by-side diff)
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 @@
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
// L.J.Potter added better error code Fri 02-15-2002 14:37:47
#include <stdlib.h>
#include <stdio.h>
#include <qpe/qpeapplication.h>
#include <qpe/config.h>
#include <qmessagebox.h>
#include "audiodevice.h"
#include <errno.h>
#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
#include "qpe/qcopenvelope_qws.h"
#endif
-// #ifdef Q_WS_WIN
-// #include <windows.h>
-// #include <mmsystem.h>
-// #include <mmreg.h>
-// #endif
#if defined(Q_WS_X11) || defined(Q_WS_QWS)
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#endif
-// #if defined(Q_OS_WIN32)
-// static const int expectedBytesPerMilliSecond = 2 * 2 * 44000 / 1000;
-// static const int timerResolutionMilliSeconds = 30;
-// static const int sound_fragment_bytes = timerResolutionMilliSeconds * expectedBytesPerMilliSecond;
-// #else
# if defined(QT_QWS_IPAQ)
static const int sound_fragment_shift = 14;
# else
static const int sound_fragment_shift = 16;
# endif
static const int sound_fragment_bytes = (1<<sound_fragment_shift);
//#endif
class AudioDevicePrivate {
public:
int handle;
unsigned int frequency;
unsigned int channels;
unsigned int bytesPerSample;
unsigned int bufferSize;
//#ifndef Q_OS_WIN32
bool can_GETOSPACE;
char* unwrittenBuffer;
unsigned int unwritten;
//#endif
static int dspFd;
static bool muted;
static unsigned int leftVolume;
static unsigned int rightVolume;
};
#ifdef Q_WS_QWS
// This is for keeping the device open in-between playing files when
// the device makes clicks and it starts to drive you insane! :)
// Best to have the device not open when not using it though
//#define KEEP_DEVICE_OPEN
#endif
int AudioDevicePrivate::dspFd = 0;
bool AudioDevicePrivate::muted = FALSE;
unsigned int AudioDevicePrivate::leftVolume = 0;
unsigned int AudioDevicePrivate::rightVolume = 0;
void AudioDevice::getVolume( unsigned int& leftVolume, unsigned int& rightVolume, bool &muted ) {
muted = AudioDevicePrivate::muted;
unsigned int volume;
-// #ifdef Q_OS_WIN32
-// HWAVEOUT handle;
-// WAVEFORMATEX formatData;
-// formatData.cbSize = sizeof(WAVEFORMATEX);
-// formatData.wFormatTag = WAVE_FORMAT_PCM;
-// formatData.nAvgBytesPerSec = 4 * 44000;
-// formatData.nBlockAlign = 4;
-// formatData.nChannels = 2;
-// formatData.nSamplesPerSec = 44000;
-// formatData.wBitsPerSample = 16;
-// waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL);
-// if ( waveOutGetVolume( handle, (LPDWORD)&volume ) )
-// // qDebug( "get volume of audio device failed" );
-// waveOutClose( handle );
-// leftVolume = volume & 0xFFFF;
-// rightVolume = volume >> 16;
-// #else
int mixerHandle = open( "/dev/mixer", O_RDWR );
if ( mixerHandle >= 0 ) {
if(ioctl( mixerHandle, MIXER_READ(0), &volume )==-1)
perror("ioctl(\"MIXER_READ\")");
close( mixerHandle );
} else
perror("open(\"/dev/mixer\")");
leftVolume = ((volume & 0x00FF) << 16) / 101;
rightVolume = ((volume & 0xFF00) << 8) / 101;
-//#endif
}
void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume, bool muted ) {
AudioDevicePrivate::muted = muted;
if ( muted ) {
AudioDevicePrivate::leftVolume = leftVolume;
AudioDevicePrivate::rightVolume = rightVolume;
leftVolume = 0;
rightVolume = 0;
} else {
leftVolume = ( (int) leftVolume < 0 ) ? 0 : (( leftVolume > 0xFFFF ) ? 0xFFFF : leftVolume );
rightVolume = ( (int)rightVolume < 0 ) ? 0 : (( rightVolume > 0xFFFF ) ? 0xFFFF : rightVolume );
}
-// #ifdef Q_OS_WIN32
-// HWAVEOUT handle;
-// WAVEFORMATEX formatData;
-// formatData.cbSize = sizeof(WAVEFORMATEX);
-// formatData.wFormatTag = WAVE_FORMAT_PCM;
-// formatData.nAvgBytesPerSec = 4 * 44000;
-// formatData.nBlockAlign = 4;
-// formatData.nChannels = 2;
-// formatData.nSamplesPerSec = 44000;
-// formatData.wBitsPerSample = 16;
-// waveOutOpen(&handle, WAVE_MAPPER, &formatData, 0L, 0L, CALLBACK_NULL);
-// unsigned int volume = (rightVolume << 16) | leftVolume;
-// if ( waveOutSetVolume( handle, volume ) )
-// // qDebug( "set volume of audio device failed" );
-// waveOutClose( handle );
-// #else
// Volume can be from 0 to 100 which is 101 distinct values
unsigned int rV = (rightVolume * 101) >> 16;
# if 0
unsigned int lV = (leftVolume * 101) >> 16;
unsigned int volume = ((rV << 8) & 0xFF00) | (lV & 0x00FF);
int mixerHandle = 0;
if ( ( mixerHandle = open( "/dev/mixer", O_RDWR ) ) >= 0 ) {
if(ioctl( mixerHandle, MIXER_WRITE(0), &volume ) ==-1)
perror("ioctl(\"MIXER_WRITE\")");
close( mixerHandle );
} else
perror("open(\"/dev/mixer\")");
# else
// This is the way this has to be done now I guess, doesn't allow for
// independant right and left channel setting, or setting for different outputs
Config cfg("qpe"); // qtopia is "Sound"
cfg.setGroup("Volume"); // qtopia is "Settings"
cfg.writeEntry("VolumePercent",(int)rV); //qtopia is Volume
# endif
//#endif
// qDebug( "setting volume to: 0x%x", volume );
#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
// Send notification that the volume has changed
QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << muted;
#endif
}
-
AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
qDebug("creating new audio device");
QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE;
d = new AudioDevicePrivate;
d->frequency = f;
d->channels = chs;
d->bytesPerSample = bps;
qDebug("%d",bps);
int format=0;
if( bps == 8) format = AFMT_U8;
else if( bps <= 0) format = AFMT_S16_LE;
else format = AFMT_S16_LE;
qDebug("AD- freq %d, channels %d, b/sample %d, bitrate %d",f,chs,bps,format);
connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
int fragments = 0x10000 * 8 + sound_fragment_shift;
int capabilities = 0;
#ifdef KEEP_DEVICE_OPEN
if ( AudioDevicePrivate::dspFd == 0 ) {
#endif
if ( ( d->handle = ::open( "/dev/dsp", O_WRONLY ) ) < 0 ) {
@@ -245,145 +200,114 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1)
perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
}
QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
d->bufferSize = sound_fragment_bytes;
d->unwrittenBuffer = new char[d->bufferSize];
d->unwritten = 0;
d->can_GETOSPACE = TRUE; // until we find otherwise
//if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels );
//if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency );
//if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" );
//if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" );
//if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" );
//if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" );
}
AudioDevice::~AudioDevice() {
qDebug("destryo audiodevice");
QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE;
-// #ifdef Q_OS_WIN32
-// waveOutClose( (HWAVEOUT)d->handle );
-// #else
# ifndef KEEP_DEVICE_OPEN
close( d->handle ); // Now it should be safe to shut the handle
# endif
delete d->unwrittenBuffer;
delete d;
-//#endif
QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
}
void AudioDevice::volumeChanged( bool muted )
{
AudioDevicePrivate::muted = muted;
}
void AudioDevice::write( char *buffer, unsigned int length )
{
-// #ifdef Q_OS_WIN32
-// // returns immediately and (to be implemented) emits completedIO() when finished writing
-// WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) );
-// // maybe the buffer should be copied so that this fool proof, but its a performance hit
-// lpWaveHdr->lpData = buffer;
-// lpWaveHdr->dwBufferLength = length;
-// lpWaveHdr->dwFlags = 0L;
-// lpWaveHdr->dwLoops = 0L;
-// waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) );
-// // waveOutWrite returns immediately. the data is sent in the background.
-// if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) )
-// qDebug( "failed to write block to audio device" );
-// // emit completedIO();
-// #else
int t = ::write( d->handle, buffer, length );
if ( t<0 ) t = 0;
if ( t != (int)length) {
qDebug("Ahhh!! memcpys 1");
memcpy(d->unwrittenBuffer,buffer+t,length-t);
d->unwritten = length-t;
}
//#endif
}
unsigned int AudioDevice::channels() const
{
return d->channels;
}
unsigned int AudioDevice::frequency() const
{
return d->frequency;
}
unsigned int AudioDevice::bytesPerSample() const
{
return d->bytesPerSample;
}
unsigned int AudioDevice::bufferSize() const
{
return d->bufferSize;
}
unsigned int AudioDevice::canWrite() const
{
-// #ifdef Q_OS_WIN32
-// return bufferSize(); // Any better?
-// #else
audio_buf_info info;
if ( d->can_GETOSPACE && ioctl(d->handle,SNDCTL_DSP_GETOSPACE,&info) ) {
d->can_GETOSPACE = FALSE;
fcntl( d->handle, F_SETFL, O_NONBLOCK );
}
if ( d->can_GETOSPACE ) {
int t = info.fragments * sound_fragment_bytes;
return QMIN(t,(int)bufferSize());
} else {
if ( d->unwritten ) {
int t = ::write( d->handle, d->unwrittenBuffer, d->unwritten );
if ( t<0 ) t = 0;
if ( (unsigned)t!=d->unwritten ) {
memcpy(d->unwrittenBuffer,d->unwrittenBuffer+t,d->unwritten-t);
d->unwritten -= t;
} else {
d->unwritten = 0;
}
}
if ( d->unwritten )
return 0;
else
return d->bufferSize;
}
-//#endif
}
int AudioDevice::bytesWritten() {
-// #ifdef Q_OS_WIN32
-// MMTIME pmmt = { TIME_BYTES, 0 };
-// if ( ( waveOutGetPosition( (HWAVEOUT)d->handle, &pmmt, sizeof(MMTIME) ) != MMSYSERR_NOERROR ) || ( pmmt.wType != TIME_BYTES ) ) {
-// qDebug( "failed to get audio device position" );
-// return -1;
-// }
-// return pmmt.u.cb;
-// #else
int buffered = 0;
if ( ioctl( d->handle, SNDCTL_DSP_GETODELAY, &buffered ) ) {
qDebug( "failed to get audio device position" );
return -1;
}
return buffered;
-//#endif
}
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) :
songInfo.setFrameStyle( QFrame::NoFrame);
// songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken );
//NoFrame
// songInfo.setForegroundColor(Qt::white);
slider.setFixedHeight( 20 );
slider.setMinValue( 0 );
slider.setMaxValue( 1 );
slider.setFocusPolicy( QWidget::NoFocus );
slider.setBackgroundPixmap( *pixBg );
time.setFocusPolicy( QWidget::NoFocus );
time.setAlignment( Qt::AlignCenter );
time.setFrame(FALSE);
changeTextColor( &time );
resizeEvent( NULL );
connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) );
connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) );
connect( mediaPlayerState, SIGNAL( lengthChanged(long) ), this, SLOT( setLength(long) ) );
connect( mediaPlayerState, SIGNAL( viewChanged(char) ), this, SLOT( setView(char) ) );
connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) );
- connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) );
+// connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) );
connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), this, SLOT( setPlaying(bool) ) );
// Intialise state
setLength( mediaPlayerState->length() );
setPosition( mediaPlayerState->position() );
setLooping( mediaPlayerState->fullscreen() );
- setPaused( mediaPlayerState->paused() );
+// setPaused( mediaPlayerState->paused() );
setPlaying( mediaPlayerState->playing() );
}
AudioWidget::~AudioWidget() {
for ( int i = 0; i < 10; i++ ) {
delete buttonPixUp[i];
delete buttonPixDown[i];
}
delete pixBg;
delete imgUp;
delete imgDn;
delete imgButtonMask;
for ( int i = 0; i < 10; i++ ) {
delete masks[i];
}
}
QPixmap *combineImageWithBackground( QImage img, QPixmap bg, QPoint offset ) {
QPixmap pix( img.width(), img.height() );
QPainter p( &pix );
@@ -342,63 +342,80 @@ void AudioWidget::timerEvent( QTimerEvent * ) {
void AudioWidget::mouseMoveEvent( QMouseEvent *event ) {
for ( int i = 0; i < numButtons; i++ ) {
if ( event->state() == QMouseEvent::LeftButton ) {
// The test to see if the mouse click is inside the button or not
int x = event->pos().x() - xoff;
int y = event->pos().y() - yoff;
bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width()
&& y < imgButtonMask->height() && imgButtonMask->pixelIndex( x, y ) == i + 1 );
if ( isOnButton && i == AudioVolumeUp )
qDebug("on up");
if ( isOnButton && !audioButtons[i].isHeld ) {
audioButtons[i].isHeld = TRUE;
toggleButton(i);
switch (i) {
case AudioVolumeUp:
qDebug("more clicked");
emit moreClicked();
return;
- case AudioVolumeDown: emit lessClicked(); return;
+ case AudioVolumeDown:
+ qDebug("less clicked");
+ emit lessClicked();
+ return;
+ case AudioForward:
+ emit forwardClicked();
+ return;
+ case AudioBack:
+ emit backClicked();
+ return;
}
} else if ( !isOnButton && audioButtons[i].isHeld ) {
audioButtons[i].isHeld = FALSE;
toggleButton(i);
}
} else {
if ( audioButtons[i].isHeld ) {
audioButtons[i].isHeld = FALSE;
if ( !audioButtons[i].isToggle )
setToggleButton( i, FALSE );
switch (i) {
- case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return;
+ case AudioPlay:
+ if( mediaPlayerState->isPaused ) {
+ mediaPlayerState->setPaused( FALSE );
+ return;
+ } else if( !mediaPlayerState->isPaused ) {
+ mediaPlayerState->setPaused( TRUE );
+ return;
+ }
+// case AudioPlay: mediaPlayerState->setPlaying(audioButtons[i].isDown); return;
case AudioStop: mediaPlayerState->setPlaying(FALSE); return;
- case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return;
+// case AudioPause: mediaPlayerState->setPaused(audioButtons[i].isDown); return;
case AudioNext: mediaPlayerState->setNext(); return;
case AudioPrevious: mediaPlayerState->setPrev(); return;
case AudioLoop: mediaPlayerState->setLooping(audioButtons[i].isDown); return;
case AudioVolumeUp: emit moreReleased(); return;
case AudioVolumeDown: emit lessReleased(); return;
case AudioPlayList: mediaPlayerState->setList(); return;
}
}
}
}
}
void AudioWidget::mousePressEvent( QMouseEvent *event ) {
mouseMoveEvent( event );
}
void AudioWidget::mouseReleaseEvent( QMouseEvent *event ) {
mouseMoveEvent( event );
}
@@ -442,50 +459,50 @@ void AudioWidget::keyReleaseEvent( QKeyEvent *e)
// qDebug("Audio F9");
break;
case Key_F10: //contacts
break;
case Key_F11: //menu
break;
case Key_F12: //home
break;
case Key_F13: //mail
break;
case Key_Space: {
if(mediaPlayerState->playing()) {
// toggleButton(1);
mediaPlayerState->setPlaying(FALSE);
// toggleButton(1);
} else {
// toggleButton(0);
mediaPlayerState->setPlaying(TRUE);
// toggleButton(0);
}
}
break;
case Key_Down: //volume
- toggleButton(6);
+// toggleButton(6);
emit lessClicked();
emit lessReleased();
- toggleButton(6);
+// toggleButton(6);
break;
case Key_Up: //volume
- toggleButton(5);
+// toggleButton(5);
emit moreClicked();
emit moreReleased();
- toggleButton(5);
+// toggleButton(5);
break;
case Key_Right: //next in playlist
// toggleButton(3);
mediaPlayerState->setNext();
// toggleButton(3);
break;
case Key_Left: // previous in playlist
// toggleButton(4);
mediaPlayerState->setPrev();
// toggleButton(4);
break;
case Key_Escape:
break;
};
}
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 @@
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef AUDIO_WIDGET_H
#define AUDIO_WIDGET_H
#include <qwidget.h>
#include <qpainter.h>
#include <qdrawutil.h>
#include <qpixmap.h>
#include <qbitmap.h>
#include <qstring.h>
#include <qslider.h>
#include <qlineedit.h>
#include <qframe.h>
#include <opie/oticker.h>
class QPixmap;
enum AudioButtons {
- AudioPlay,
+ AudioPlay=0,
AudioStop,
- AudioPause,
AudioNext,
AudioPrevious,
AudioVolumeUp,
AudioVolumeDown,
AudioLoop,
- AudioPlayList
+ AudioPlayList,
+ AudioForward,
+ AudioBack
};
//#define USE_DBLBUF
class AudioWidget : public QWidget {
Q_OBJECT
public:
AudioWidget( QWidget* parent=0, const char* name=0, WFlags f=0 );
~AudioWidget();
void setTickerText( const QString &text ) { songInfo.setText( text ); }
bool isStreaming;
public slots:
void updateSlider( long, long );
void sliderPressed( );
void sliderReleased( );
- void setPaused( bool b) { setToggleButton( AudioPause, b ); }
+// void setPaused( bool b) { setToggleButton( AudioPause, b ); }
void setLooping( bool b) { setToggleButton( AudioLoop, b ); }
void setPlaying( bool b) { setToggleButton( AudioPlay, b ); }
void setPosition( long );
void setLength( long );
void setView( char );
signals:
void moreClicked();
void lessClicked();
void moreReleased();
void lessReleased();
void sliderMoved(long);
+ void forwardClicked();
+ void backClicked();
+ void forwardReleased();
+ void backReleased();
protected:
void doBlank();
void doUnblank();
void paintEvent( QPaintEvent *pe );
void showEvent( QShowEvent *se );
void resizeEvent( QResizeEvent *re );
void mouseMoveEvent( QMouseEvent *event );
void mousePressEvent( QMouseEvent *event );
void mouseReleaseEvent( QMouseEvent *event );
void timerEvent( QTimerEvent *event );
void closeEvent( QCloseEvent *event );
void keyReleaseEvent( QKeyEvent *e);
private:
void toggleButton( int );
void setToggleButton( int, bool );
void paintButton( QPainter *p, int i );
QString skin;
QPixmap *pixBg;
QImage *imgUp;
QImage *imgDn;
QImage *imgButtonMask;
QBitmap *masks[11];
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 ) {
mediaPlayerState->setPaused( FALSE );
loopControl->stop( FALSE );
return;
}
if ( mediaPlayerState->paused() ) {
mediaPlayerState->setPaused( FALSE );
return;
}
qDebug("about to ctrash");
const DocLnk *playListCurrent = playList->current();
if ( playListCurrent != NULL ) {
loopControl->stop( TRUE );
currentFile = playListCurrent;
}
if ( currentFile == NULL ) {
QMessageBox::critical( 0, tr( "No file"), tr( "Error: There is no file selected" ) );
mediaPlayerState->setPlaying( FALSE );
return;
}
if ( ((currentFile->file()).left(4) != "http") && !QFile::exists( currentFile->file() ) ) {
QMessageBox::critical( 0, tr( "File not found"),
- tr( "The following file was not found: <i>" ) + currentFile->file() + "</i>" );
+ tr( "The following file was not found: <i>" )
+ + currentFile->file() + "</i>" );
mediaPlayerState->setPlaying( FALSE );
return;
}
if ( !mediaPlayerState->newDecoder( currentFile->file() ) ) {
QMessageBox::critical( 0, tr( "No decoder found"),
- tr( "Sorry, no appropriate decoders found for this file: <i>" ) + currentFile->file() + "</i>" );
+ tr( "Sorry, no appropriate decoders found for this file: <i>" )
+ + currentFile->file() + "</i>" );
mediaPlayerState->setPlaying( FALSE );
return;
}
if ( !loopControl->init( currentFile->file() ) ) {
QMessageBox::critical( 0, tr( "Error opening file"),
tr( "Sorry, an error occured trying to play the file: <i>" ) + currentFile->file() + "</i>" );
mediaPlayerState->setPlaying( FALSE );
return;
}
long seconds = loopControl->totalPlaytime();
QString time; time.sprintf("%li:%02i", seconds/60, (int)seconds%60 );
QString tickerText;
if( currentFile->file().left(4) == "http" )
tickerText= tr( " File: " ) + currentFile->name();
else
tickerText = tr( " File: " ) + currentFile->name() + tr(", Length: ") + time;
QString fileInfo = mediaPlayerState->curDecoder()->fileInfo();
if ( !fileInfo.isEmpty() )
tickerText += ", " + fileInfo;
audioUI->setTickerText( tickerText + "." );
loopControl->play();
@@ -155,61 +157,112 @@ void MediaPlayer::prev() {
void MediaPlayer::next() {
if ( playList->next() )
play();
else if ( mediaPlayerState->looping() ) {
if ( playList->first() )
play();
} else
mediaPlayerState->setList();
}
void MediaPlayer::startDecreasingVolume() {
volumeDirection = -1;
startTimer( 100 );
AudioDevice::decreaseVolume();
}
void MediaPlayer::startIncreasingVolume() {
volumeDirection = +1;
startTimer( 100 );
AudioDevice::increaseVolume();
+
}
+bool drawnOnScreenDisplay = FALSE;
+unsigned int onScreenDisplayVolume = 0;
+const int yoff = 110;
void MediaPlayer::stopChangingVolume() {
killTimers();
+
+ // Get rid of the on-screen display stuff
+ drawnOnScreenDisplay = FALSE;
+ onScreenDisplayVolume = 0;
+ int w = audioUI->width();
+ int h = audioUI->height();
+ audioUI->repaint( (w - 200) / 2, h - yoff, 200 + 9, 70, FALSE );
}
void MediaPlayer::timerEvent( QTimerEvent * ) {
+// qDebug("timer");
if ( volumeDirection == +1 )
- AudioDevice::increaseVolume();
+ AudioDevice::increaseVolume();
else if ( volumeDirection == -1 )
AudioDevice::decreaseVolume();
+
+ // Display an on-screen display volume
+ unsigned int l, r, v; bool m;
+ AudioDevice::getVolume( l, r, m );
+ v = ((l + r) * 11) / (2*0xFFFF);
+
+ if ( drawnOnScreenDisplay && onScreenDisplayVolume == v ) {
+// qDebug("returning %d, %d, %d, %d", v, l, r, m);
+ return;
+ }
+
+ int w = audioUI->width();
+ int h = audioUI->height();
+
+ if ( drawnOnScreenDisplay ) {
+ if ( onScreenDisplayVolume > v )
+ audioUI->repaint( (w - 200) / 2 + v * 20 + 0, h - yoff + 40,
+ (onScreenDisplayVolume - v) * 20 + 9, 30, FALSE );
+ }
+
+ drawnOnScreenDisplay = TRUE;
+ onScreenDisplayVolume = v;
+
+ QPainter p( audioUI );
+ p.setPen( QColor( 0x10, 0xD0, 0x10 ) );
+ p.setBrush( QColor( 0x10, 0xD0, 0x10 ) );
+
+ QFont f;
+ f.setPixelSize( 20 );
+ f.setBold( TRUE );
+ p.setFont( f );
+ p.drawText( (w - 200) / 2, h - yoff + 20, tr("Volume") );
+
+ for ( unsigned int i = 0; i < 10; i++ ) {
+ if ( v > i )
+ p.drawRect( (w - 200) / 2 + i * 20 + 0, h - yoff + 40, 9, 30 );
+ else
+ p.drawRect( (w - 200) / 2 + i * 20 + 3, h - yoff + 50, 3, 10 );
+ }
}
void MediaPlayer::keyReleaseEvent( QKeyEvent *e) {
switch ( e->key() ) {
////////////////////////////// Zaurus keys
case Key_Home:
break;
case Key_F9: //activity
break;
case Key_F10: //contacts
break;
case Key_F11: //menu
break;
case Key_F12: //home
qDebug("Blank here");
break;
case Key_F13: //mail
break;
}
}
void MediaPlayer::doBlank() {
}
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 @@
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef MEDIA_PLAYER_STATE_H
#define MEDIA_PLAYER_STATE_H
#include <qobject.h>
class MediaPlayerDecoder;
class Config;
class MediaPlayerState : public QObject {
Q_OBJECT
public:
MediaPlayerState( QObject *parent, const char *name );
~MediaPlayerState();
+ bool isPaused;
bool isStreaming;
bool fullscreen() { return isFullscreen; }
bool scaled() { return isScaled; }
bool looping() { return isLooping; }
bool shuffled() { return isShuffled; }
bool playlist() { return usePlaylist; }
bool paused() { return isPaused; }
bool playing() { return isPlaying; }
long position() { return curPosition; }
long length() { return curLength; }
char view() { return curView; }
MediaPlayerDecoder *newDecoder( const QString& file );
MediaPlayerDecoder *curDecoder();
MediaPlayerDecoder *libMpeg3Decoder(); // ### Yucky hack needed to use libmpeg3plugin to get the
// number of audio samples if we are using the libmad plugin
public slots:
void setFullscreen( bool b ) { if ( isFullscreen == b ) return; isFullscreen = b; emit fullscreenToggled(b); }
void setScaled( bool b ) { if ( isScaled == b ) return; isScaled = b; emit scaledToggled(b); }
void setLooping( bool b ) { if ( isLooping == b ) return; isLooping = b; emit loopingToggled(b); }
void setShuffled( bool b ) { if ( isShuffled == b ) return; isShuffled = b; emit shuffledToggled(b); }
void setPlaylist( bool b ) { if ( usePlaylist == b ) return; usePlaylist = b; emit playlistToggled(b); }
void setPaused( bool b ) { if ( isPaused == b ) return; isPaused = b; emit pausedToggled(b); }
@@ -80,42 +81,41 @@ public slots:
void togglePlaying() { setPlaying( !isPlaying); }
signals:
void fullscreenToggled( bool );
void scaledToggled( bool );
void loopingToggled( bool );
void shuffledToggled( bool );
void playlistToggled( bool );
void pausedToggled( bool );
void playingToggled( bool );
void positionChanged( long ); // When the slider is moved
void positionUpdated( long ); // When the media file progresses
void lengthChanged( long );
void viewChanged( char );
void prev();
void next();
private:
bool isFullscreen;
bool isScaled;
bool isLooping;
bool isShuffled;
bool usePlaylist;
- bool isPaused;
bool isPlaying;
long curPosition;
long curLength;
char curView;
MediaPlayerDecoder *decoder;
MediaPlayerDecoder *libmpeg3decoder;
// MediaPlayerDecoder *libwavdecoder;
void loadPlugins();
void readConfig( Config& cfg );
void writeConfig( Config& cfg ) const;
};
#endif // MEDIA_PLAYER_STATE_H