Skepsor
9th June 2010, 17:03
Hello everyone, I'm having troubles when trying to play an mp3 file with phonon on WindowsXP.
WAV files are OK, I can play them, but when I try to play an mp3 the application compiles with success but it crashes after execution.
Here is my code
int i,c;
QGridLayout *gridLayout;
QString fileName(QDir::currentPath()+"/jmq.mp3");
QString fileName2(QDir::currentPath()+"/wmpaud.wav");
QFile *file = new QFile(fileName2);
i = c = 0;
file->open(QIODevice::ReadOnly);
QList<Phonon::AudioOutputDevice> audioOutputDevices = Phonon::BackendCapabilities::availableAudioOutputD evices();
QStringList audioMimeSupport = Phonon::BackendCapabilities::availableMimeTypes();
if(file->exists()){
gridLayout->addWidget(new QLabel(QString("File exists!:")+fileName2), 0, 4, Qt::AlignCenter);
Phonon::MediaSource *audioSource = new Phonon::MediaSource(file);
Phonon::AudioOutput *aO = new Phonon::AudioOutput(Phonon::MusicCategory, this);
Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);
mediaObject->setCurrentSource(*audioSource);
Phonon::Path path = Phonon::createPath(mediaObject, aO);
}
else {
gridLayout->addWidget(new QLabel(QString("File Name does not exist: ")+fileName2), 0, 4, Qt::AlignCenter);
return (1);
}
QList<Phonon::AudioOutputDevice>::const_iterator iterator = audioOutputDevices.begin();
// Show list of devices
for(iterator; iterator != audioOutputDevices.end(); iterator++) {
gridLayout->addWidget(new QLabel(audioOutputDevices.at(i).name()), i, 0, Qt::AlignLeft);
i++;
}
// Show defult device
gridLayout->addWidget(new QLabel(QString("Default device: ")+aO->outputDevice().name()), i++, 0, Qt::AlignLeft);
// Show size of available devices list
gridLayout->addWidget(new QLabel(QString("Devices list size: %1").arg(audioOutputDevices.size())), i++, 0, Qt::AlignLeft);
// Show current device ID
gridLayout->addWidget(new QLabel(QString("Current device ID: %1").arg(aO->outputDevice().index())), i++, 0, Qt::AlignLeft);
// Show current source type
gridLayout->addWidget(new QLabel("MEDIA SOURCE"), 0, 3, Qt::AlignCenter);
switch (mediaObject->currentSource().type()){
case Phonon::MediaSource::Invalid:
gridLayout->addWidget(new QLabel("Invalid"), 1, 3, Qt::AlignCenter);
break;
case Phonon::MediaSource::Empty:
gridLayout->addWidget(new QLabel("Empty"), 2, 3, Qt::AlignCenter);
break;
case Phonon::MediaSource::LocalFile:
gridLayout->addWidget(new QLabel("LocalFile"), 3, 3, Qt::AlignCenter);
break;
case Phonon::MediaSource::Stream:
gridLayout->addWidget(new QLabel("Stream"), 4, 3, Qt::AlignCenter);
break;
case Phonon::MediaSource::Url:
gridLayout->addWidget(new QLabel("Url"), 5, 3, Qt::AlignCenter);
break;
case Phonon::MediaSource::Disc:
gridLayout->addWidget(new QLabel("Disc"), 5, 3, Qt::AlignCenter);
break;
}
// Show current MIME support file types
for(c;c<=audioMimeSupport.size(); ++c) {
gridLayout->addWidget(new QLabel(audioMimeSupport.at(c)), c, 1, Qt::AlignLeft);
c++;
}
mediaObject->play();
If I change to the mp3 fileName, then the problem will be produced by the line that sets the MediaSource to the MediaObject
mediaObject->setCurrentSource(*audioSource);
I've tryied also with mediaObject->setCurrentSource(fileName); and it fails.
The variables for MediaObject, MediaSource, AudioOutput (and those that are not present) are defined in the class definition scope as public. Also the includes have been avoided.
As you can see I've addded some information in a gridlayout to know if everything was OK, and it seems to be OK, because here I get audio/mp3, and audio/x-mp3 as part of the support mime type list (between a list of other 18th supported formats). I'm stocked.
Any help would be appretiated, thanks in advice
Regards
WAV files are OK, I can play them, but when I try to play an mp3 the application compiles with success but it crashes after execution.
Here is my code
int i,c;
QGridLayout *gridLayout;
QString fileName(QDir::currentPath()+"/jmq.mp3");
QString fileName2(QDir::currentPath()+"/wmpaud.wav");
QFile *file = new QFile(fileName2);
i = c = 0;
file->open(QIODevice::ReadOnly);
QList<Phonon::AudioOutputDevice> audioOutputDevices = Phonon::BackendCapabilities::availableAudioOutputD evices();
QStringList audioMimeSupport = Phonon::BackendCapabilities::availableMimeTypes();
if(file->exists()){
gridLayout->addWidget(new QLabel(QString("File exists!:")+fileName2), 0, 4, Qt::AlignCenter);
Phonon::MediaSource *audioSource = new Phonon::MediaSource(file);
Phonon::AudioOutput *aO = new Phonon::AudioOutput(Phonon::MusicCategory, this);
Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);
mediaObject->setCurrentSource(*audioSource);
Phonon::Path path = Phonon::createPath(mediaObject, aO);
}
else {
gridLayout->addWidget(new QLabel(QString("File Name does not exist: ")+fileName2), 0, 4, Qt::AlignCenter);
return (1);
}
QList<Phonon::AudioOutputDevice>::const_iterator iterator = audioOutputDevices.begin();
// Show list of devices
for(iterator; iterator != audioOutputDevices.end(); iterator++) {
gridLayout->addWidget(new QLabel(audioOutputDevices.at(i).name()), i, 0, Qt::AlignLeft);
i++;
}
// Show defult device
gridLayout->addWidget(new QLabel(QString("Default device: ")+aO->outputDevice().name()), i++, 0, Qt::AlignLeft);
// Show size of available devices list
gridLayout->addWidget(new QLabel(QString("Devices list size: %1").arg(audioOutputDevices.size())), i++, 0, Qt::AlignLeft);
// Show current device ID
gridLayout->addWidget(new QLabel(QString("Current device ID: %1").arg(aO->outputDevice().index())), i++, 0, Qt::AlignLeft);
// Show current source type
gridLayout->addWidget(new QLabel("MEDIA SOURCE"), 0, 3, Qt::AlignCenter);
switch (mediaObject->currentSource().type()){
case Phonon::MediaSource::Invalid:
gridLayout->addWidget(new QLabel("Invalid"), 1, 3, Qt::AlignCenter);
break;
case Phonon::MediaSource::Empty:
gridLayout->addWidget(new QLabel("Empty"), 2, 3, Qt::AlignCenter);
break;
case Phonon::MediaSource::LocalFile:
gridLayout->addWidget(new QLabel("LocalFile"), 3, 3, Qt::AlignCenter);
break;
case Phonon::MediaSource::Stream:
gridLayout->addWidget(new QLabel("Stream"), 4, 3, Qt::AlignCenter);
break;
case Phonon::MediaSource::Url:
gridLayout->addWidget(new QLabel("Url"), 5, 3, Qt::AlignCenter);
break;
case Phonon::MediaSource::Disc:
gridLayout->addWidget(new QLabel("Disc"), 5, 3, Qt::AlignCenter);
break;
}
// Show current MIME support file types
for(c;c<=audioMimeSupport.size(); ++c) {
gridLayout->addWidget(new QLabel(audioMimeSupport.at(c)), c, 1, Qt::AlignLeft);
c++;
}
mediaObject->play();
If I change to the mp3 fileName, then the problem will be produced by the line that sets the MediaSource to the MediaObject
mediaObject->setCurrentSource(*audioSource);
I've tryied also with mediaObject->setCurrentSource(fileName); and it fails.
The variables for MediaObject, MediaSource, AudioOutput (and those that are not present) are defined in the class definition scope as public. Also the includes have been avoided.
As you can see I've addded some information in a gridlayout to know if everything was OK, and it seems to be OK, because here I get audio/mp3, and audio/x-mp3 as part of the support mime type list (between a list of other 18th supported formats). I'm stocked.
Any help would be appretiated, thanks in advice
Regards