summaryrefslogtreecommitdiff
path: root/core
Side-by-side diff
Diffstat (limited to 'core') (more/less context) (show whitespace changes)
-rw-r--r--core/multimedia/opieplayer/audiodevice.cpp15
-rw-r--r--core/multimedia/opieplayer/playlistwidget.cpp10
2 files changed, 18 insertions, 7 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp
index faadd72..8f04d0d 100644
--- a/core/multimedia/opieplayer/audiodevice.cpp
+++ b/core/multimedia/opieplayer/audiodevice.cpp
@@ -1,76 +1,81 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** 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.
**
**********************************************************************/
// 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;
@@ -164,98 +169,104 @@ void AudioDevice::setVolume( unsigned int leftVolume, unsigned int rightVolume,
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 ) {
- perror("open(\"/dev/dsp\") sending to /dev/null instead");
- d->handle = ::open( "/dev/null", O_WRONLY );
+
+// perror("open(\"/dev/dsp\") sending to /dev/null instead");
+ perror("open(\"/dev/dsp\")");
+ QString errorMsg=tr("Somethin's wrong with\nyour sound device.\nopen(\"/dev/dsp\")\n")+(QString)strerror(errno)+tr("\n\nClosing player now.");
+ QMessageBox::critical(0, "Vmemo", errorMsg, tr("Abort"));
+ exit(-1); //harsh?
+// d->handle = ::open( "/dev/null", O_WRONLY );
+ // WTF?!?!
}
#ifdef KEEP_DEVICE_OPEN
AudioDevicePrivate::dspFd = d->handle;
} else {
d->handle = AudioDevicePrivate::dspFd;
}
#endif
if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1)
perror("ioctl(\"SNDCTL_DSP_GETCAPS\")");
if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1)
perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")");
if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1)
perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
qDebug("freq %d", d->frequency);
if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1)
perror("ioctl(\"SNDCTL_DSP_SPEED\")");
qDebug("channels %d",d->channels);
if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) {
d->channels = ( d->channels == 1 ) ? 2 : d->channels;
if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1)
perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
}
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" );
QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
}
AudioDevice::~AudioDevice() {
qDebug("destryo audiodevice");
QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << TRUE;
// #ifdef Q_OS_WIN32
// waveOutClose( (HWAVEOUT)d->handle );
// #else
# ifndef KEEP_DEVICE_OPEN
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp
index ae25fe3..0332237 100644
--- a/core/multimedia/opieplayer/playlistwidget.cpp
+++ b/core/multimedia/opieplayer/playlistwidget.cpp
@@ -372,109 +372,109 @@ void PlayListWidget::readConfig( Config& cfg ) {
DocLnk lnk( linkFile );
if ( lnk.isValid() ) {
d->selectedFiles->addToSelection( lnk );
}
}
d->selectedFiles->setSelectedItem( currentString);
// d->selectedFiles->setSelectedItem( (const QString &)currentString);
}
void PlayListWidget::writeConfig( Config& cfg ) const {
d->selectedFiles->writeCurrent( cfg);
cfg.setGroup("PlayList");
int noOfFiles = 0;
d->selectedFiles->first();
do {
const DocLnk *lnk = d->selectedFiles->current();
if ( lnk ) {
QString entryName;
entryName.sprintf( "File%i", noOfFiles + 1 );
// qDebug(entryName);
cfg.writeEntry( entryName, lnk->linkFile() );
// if this link does exist, add it so we have the file
// next time...
if ( !QFile::exists( lnk->linkFile() ) ) {
// the way writing lnks doesn't really check for out
// of disk space, but check it anyway.
if ( !lnk->writeLink() ) {
QMessageBox::critical( 0, tr("Out of space"),
tr( "There was a problem saving "
"the playlist.\n"
"Your playlist "
"may be missing some entries\n"
"the next time you start it." )
);
}
}
noOfFiles++;
}
}
while ( d->selectedFiles->next() );
cfg.writeEntry("NumberOfFiles", noOfFiles );
}
void PlayListWidget::addToSelection( const DocLnk& lnk ) {
// qDebug("add");
- if( lnk.file().find(" ",0,TRUE) != -1 || lnk.file().find("%20",0,TRUE) != -1) {
- QMessageBox::message("Note","You are trying to play\na malformed url.");
+// if( lnk.file().find(" ",0,TRUE) != -1 || lnk.file().find("%20",0,TRUE) != -1) {
+// QMessageBox::message("Note","You are trying to play\na malformed url.");
- } else {
+// } else {
d->setDocumentUsed = FALSE;
if ( mediaPlayerState->playlist() ) {
if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" )
d->selectedFiles->addToSelection( lnk );
}
else
mediaPlayerState->setPlaying( TRUE );
- }
+// }
}
void PlayListWidget::clearList() {
while ( first() )
d->selectedFiles->removeSelected();
}
void PlayListWidget::addAllToList() {
DocLnkSet filesAll;
Global::findDocuments(&filesAll, "video/*;audio/*");
QListIterator<DocLnk> Adit( filesAll.children() );
for ( ; Adit.current(); ++Adit )
if(QFileInfo(Adit.current()->file()).exists())
d->selectedFiles->addToSelection( **Adit );
}
void PlayListWidget::addAllMusicToList() {
QListIterator<DocLnk> dit( files.children() );
for ( ; dit.current(); ++dit )
if(QFileInfo(dit.current()->file()).exists())
d->selectedFiles->addToSelection( **dit );
}
void PlayListWidget::addAllVideoToList() {
QListIterator<DocLnk> dit( vFiles.children() );
for ( ; dit.current(); ++dit )
if(QFileInfo( dit.current()->file()).exists())
d->selectedFiles->addToSelection( **dit );
}
void PlayListWidget::setDocument(const QString& fileref) {
qDebug(fileref);
fromSetDocument = TRUE;
if ( fileref.isNull() ) {
QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) );
return;
}
// qDebug("setDocument "+fileref);
if(fileref.find("m3u",0,TRUE) != -1) { //is m3u
readm3u( fileref);
}
else if(fileref.find("pls",0,TRUE) != -1) { //is pls
readPls( fileref);
@@ -810,97 +810,97 @@ void PlayListWidget::tabChanged(QWidget *widg) {
switch ( tabWidget->currentPageIndex()) {
case 0:
{
if( !tbDeletePlaylist->isHidden())
tbDeletePlaylist->hide();
d->tbRemoveFromList->setEnabled(TRUE);
d->tbAddToList->setEnabled(FALSE);
}
break;
case 1:
{
audioView->clear();
populateAudioView();
if( !tbDeletePlaylist->isHidden())
tbDeletePlaylist->hide();
d->tbRemoveFromList->setEnabled(FALSE);
d->tbAddToList->setEnabled(TRUE);
}
break;
case 2:
{
videoView->clear();
populateVideoView();
if( !tbDeletePlaylist->isHidden())
tbDeletePlaylist->hide();
d->tbRemoveFromList->setEnabled(FALSE);
d->tbAddToList->setEnabled(TRUE);
}
break;
case 3:
{
if( tbDeletePlaylist->isHidden())
tbDeletePlaylist->show();
playLists->reread();
}
break;
};
}
void PlayListWidget::btnPlay(bool b) {
// mediaPlayerState->setPlaying(b);
switch ( tabWidget->currentPageIndex()) {
case 0:
{
// if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1
// if( d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) {
- QMessageBox::message("Note","You are trying to play\na malformed url.");
+// QMessageBox::message("Note","You are trying to play\na malformed url.");
// } else {
mediaPlayerState->setPlaying(b);
// }
}
break;
case 1:
{
addToSelection( audioView->currentItem() );
mediaPlayerState->setPlaying(b);
d->selectedFiles->removeSelected( );
tabWidget->setCurrentPage(1);
d->selectedFiles->unSelect();
insanityBool=FALSE;
}// audioView->clearSelection();
break;
case 2:
{
addToSelection( videoView->currentItem() );
mediaPlayerState->setPlaying(b);
qApp->processEvents();
d->selectedFiles->removeSelected( );
tabWidget->setCurrentPage(2);
d->selectedFiles->unSelect();
insanityBool=FALSE;
}// videoView->clearSelection();
break;
};
}
void PlayListWidget::deletePlaylist() {
switch( QMessageBox::information( this, (tr("Remove Playlist?")),
(tr("You really want to delete\nthis playlist?")),
(tr("Yes")), (tr("No")), 0 )){
case 0: // Yes clicked,
QFile().remove(playLists->selected()->file());
QFile().remove(playLists->selected()->linkFile());
playLists->reread();
break;
case 1: // Cancel
break;
};
}
void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i)
{
switch (mouse) {
case 1: