PDA

View Full Version : Cnan't play mp3 with phonon



Skepsor
9th June 2010, 18: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

saa7_go
10th June 2010, 09:09
have you built and run music player example (http://doc.qt.nokia.com/4.6/phonon-qmusicplayer.html) provided by Qt?

Skepsor
10th June 2010, 16:21
No I haven't, I don't see how that could help. I never compile demos and examples, just a waste of time; I don't want to be compiling during 2 hours to realise then that I forgot a parameter or something failed. I guess in case of compiling them I could test if it works but well, I must said that I've seen the code of the player, in fact I've taken all my code from that player code....so I can say that the player won't work without compiling it. I need solutions no more problems :).
My code is OK as far as I know (if not, so the player example code is also wrong) I need someone who allready plays mp3 that helps me, this is very simple example program it should run.

Regards

CeeKey
10th June 2010, 16:44
Hey,

maybe you forgot to put the volume?


aO->setVolume(0.9);

Skepsor
10th June 2010, 16:58
Mmmhh I'll try it out but the WAV file just played well without setting the volume, the MP3 should also play as well as the WAV file. Have in mind that I'm not even capable of assigning the MediaSource to the MediaObject. That assignment is what causes the program to hang up when it starts.

CeeKey
10th June 2010, 17:05
so you get an error message?

Skepsor
10th June 2010, 17:18
Hey, thanks for your reply.
I tryied the volume with no success :(. I don't get an error, I just compile the program with no errors, I run it, it constructs the main widget and it hangs there with the XP window report error that says to send the bug, or debug....sure you know it. I'm getting crazy

CeeKey
11th June 2010, 08:06
it is very strange that a wave file is play and mp3 not...


my code looks like this:


if(file->exists())
{
gridLayout->addWidget(new QLabel(QString("File exists!:")+fileName2), 0, 4, Qt::AlignCenter);

Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);
Phonon::AudioOutput *aO = new Phonon::AudioOutput(Phonon::MusicCategory, this);

VideoWidget *videoWidget = new VideoWidget();
Phonon::createPath(mediaObject, videoWidget);
Phonon::createPath(mediaObject, aO);

mediaObject->setCurrentSource(new Phonon::MediaSource(file));
...
mediaObject->play();
}

but i cant imagine that this change something, maybe you could debug your code?

Skepsor
11th June 2010, 14:05
Hello CeeKey, thanks for your reply
With that code you can play mp3 ? I see just a difference:


VideoWidget *videoWidget = new VideoWidget();
Phonon::createPath(mediaObject, videoWidget);

There you use a VideoWidget and createPath with it....that would be why...? I see the later createPath() call with the AudioOutput and another difference where you just create a new AudioSource in the way....I'll try to change that and see what happens.
Any sugestion is welcome

Regards

CeeKey
11th June 2010, 14:41
Hello Skepsor,

i use the VideoWidget to display a video, for you it should not be necessary to use this, if you play a mp3 file. But in that case, the mediaObject has to be connected with the VideoWidget. My first thought was exactly the same, maybe you have to set the MediaSource at least, too?! Please keep me informed.

MorrisLiang
11th June 2010, 15:24
Are you using Directshow as the phonon backend.
AFAIK,if you're playing a mp3 whose IDv3 tag is large enough(i.e. containing a large picture),the backend won't recognize it(actually it's the default filter's fault).
But I don't know it will crash your app.You're working under windows xp,so I guess you can try mplayer backend out.

Skepsor
11th June 2010, 15:54
CeeKey, I'll try it out and let you know.
Morris, I'll see the ID3 and clean it all. How could I know which backend I'm using ? I'm not so happy with my self about using XP jaja, at home I run linux but here at work I only have XP, in the weekend I'll try to run my prog in linux and see what happen.

Thanks for your replies,
Regards