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
Qt Code:
  1. int i,c;
  2. QGridLayout *gridLayout;
  3. QString fileName(QDir::currentPath()+"/jmq.mp3");
  4. QString fileName2(QDir::currentPath()+"/wmpaud.wav");
  5. QFile *file = new QFile(fileName2);
  6.  
  7. i = c = 0;
  8. file->open(QIODevice::ReadOnly);
  9. QList<Phonon::AudioOutputDevice> audioOutputDevices = Phonon::BackendCapabilities::availableAudioOutputDevices();
  10. QStringList audioMimeSupport = Phonon::BackendCapabilities::availableMimeTypes();
  11.  
  12. if(file->exists()){
  13. gridLayout->addWidget(new QLabel(QString("File exists!:")+fileName2), 0, 4, Qt::AlignCenter);
  14. Phonon::MediaSource *audioSource = new Phonon::MediaSource(file);
  15. Phonon::AudioOutput *aO = new Phonon::AudioOutput(Phonon::MusicCategory, this);
  16. Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);
  17. mediaObject->setCurrentSource(*audioSource);
  18. Phonon::Path path = Phonon::createPath(mediaObject, aO);
  19. }
  20. else {
  21. gridLayout->addWidget(new QLabel(QString("File Name does not exist: ")+fileName2), 0, 4, Qt::AlignCenter);
  22. return (1);
  23. }
  24.  
  25. QList<Phonon::AudioOutputDevice>::const_iterator iterator = audioOutputDevices.begin();
  26.  
  27. // Show list of devices
  28. for(iterator; iterator != audioOutputDevices.end(); iterator++) {
  29. gridLayout->addWidget(new QLabel(audioOutputDevices.at(i).name()), i, 0, Qt::AlignLeft);
  30. i++;
  31. }
  32.  
  33. // Show defult device
  34. gridLayout->addWidget(new QLabel(QString("Default device: ")+aO->outputDevice().name()), i++, 0, Qt::AlignLeft);
  35.  
  36. // Show size of available devices list
  37. gridLayout->addWidget(new QLabel(QString("Devices list size: %1").arg(audioOutputDevices.size())), i++, 0, Qt::AlignLeft);
  38.  
  39. // Show current device ID
  40. gridLayout->addWidget(new QLabel(QString("Current device ID: %1").arg(aO->outputDevice().index())), i++, 0, Qt::AlignLeft);
  41.  
  42. // Show current source type
  43. gridLayout->addWidget(new QLabel("MEDIA SOURCE"), 0, 3, Qt::AlignCenter);
  44.  
  45. switch (mediaObject->currentSource().type()){
  46. case Phonon::MediaSource::Invalid:
  47. gridLayout->addWidget(new QLabel("Invalid"), 1, 3, Qt::AlignCenter);
  48. break;
  49. case Phonon::MediaSource::Empty:
  50. gridLayout->addWidget(new QLabel("Empty"), 2, 3, Qt::AlignCenter);
  51. break;
  52. case Phonon::MediaSource::LocalFile:
  53. gridLayout->addWidget(new QLabel("LocalFile"), 3, 3, Qt::AlignCenter);
  54. break;
  55. case Phonon::MediaSource::Stream:
  56. gridLayout->addWidget(new QLabel("Stream"), 4, 3, Qt::AlignCenter);
  57. break;
  58. case Phonon::MediaSource::Url:
  59. gridLayout->addWidget(new QLabel("Url"), 5, 3, Qt::AlignCenter);
  60. break;
  61. case Phonon::MediaSource::Disc:
  62. gridLayout->addWidget(new QLabel("Disc"), 5, 3, Qt::AlignCenter);
  63. break;
  64. }
  65.  
  66. // Show current MIME support file types
  67. for(c;c<=audioMimeSupport.size(); ++c) {
  68. gridLayout->addWidget(new QLabel(audioMimeSupport.at(c)), c, 1, Qt::AlignLeft);
  69. c++;
  70. }
  71.  
  72. mediaObject->play();
To copy to clipboard, switch view to plain text mode 

If I change to the mp3 fileName, then the problem will be produced by the line that sets the MediaSource to the MediaObject
Qt Code:
  1. mediaObject->setCurrentSource(*audioSource);
To copy to clipboard, switch view to plain text mode 

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