Results 1 to 12 of 12

Thread: Cnan't play mp3 with phonon

  1. #1
    Join Date
    Oct 2009
    Posts
    19
    Thanked 1 Time in 1 Post

    Angry Cnan't play mp3 with phonon

    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

  2. #2
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: Cnan't play mp3 with phonon

    have you built and run music player example provided by Qt?

  3. #3
    Join Date
    Oct 2009
    Posts
    19
    Thanked 1 Time in 1 Post

    Default Re: Cnan't play mp3 with phonon

    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

  4. #4
    Join Date
    Jun 2010
    Posts
    23
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Cnan't play mp3 with phonon

    Hey,

    maybe you forgot to put the volume?

    Qt Code:
    1. aO->setVolume(0.9);
    To copy to clipboard, switch view to plain text mode 
    Stelios: What the hell are you laughing at?
    Astinos: Well, you had to say it!
    Stelios: What?
    Astinos: "Fight in the shade"!
    -------------------------------------------
    If my answer has helped you, i would appreciate it if you use the thanks button.

  5. #5
    Join Date
    Oct 2009
    Posts
    19
    Thanked 1 Time in 1 Post

    Default Re: Cnan't play mp3 with phonon

    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.

  6. #6
    Join Date
    Jun 2010
    Posts
    23
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Cnan't play mp3 with phonon

    so you get an error message?
    Stelios: What the hell are you laughing at?
    Astinos: Well, you had to say it!
    Stelios: What?
    Astinos: "Fight in the shade"!
    -------------------------------------------
    If my answer has helped you, i would appreciate it if you use the thanks button.

  7. #7
    Join Date
    Oct 2009
    Posts
    19
    Thanked 1 Time in 1 Post

    Default Re: Cnan't play mp3 with phonon

    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

  8. #8
    Join Date
    Jun 2010
    Posts
    23
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Cnan't play mp3 with phonon

    it is very strange that a wave file is play and mp3 not...


    my code looks like this:

    Qt Code:
    1. if(file->exists())
    2. {
    3. gridLayout->addWidget(new QLabel(QString("File exists!:")+fileName2), 0, 4, Qt::AlignCenter);
    4.  
    5. Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);
    6. Phonon::AudioOutput *aO = new Phonon::AudioOutput(Phonon::MusicCategory, this);
    7.  
    8. VideoWidget *videoWidget = new VideoWidget();
    9. Phonon::createPath(mediaObject, videoWidget);
    10. Phonon::createPath(mediaObject, aO);
    11.  
    12. mediaObject->setCurrentSource(new Phonon::MediaSource(file));
    13. ...
    14. mediaObject->play();
    15. }
    To copy to clipboard, switch view to plain text mode 

    but i cant imagine that this change something, maybe you could debug your code?
    Stelios: What the hell are you laughing at?
    Astinos: Well, you had to say it!
    Stelios: What?
    Astinos: "Fight in the shade"!
    -------------------------------------------
    If my answer has helped you, i would appreciate it if you use the thanks button.

  9. #9
    Join Date
    Oct 2009
    Posts
    19
    Thanked 1 Time in 1 Post

    Default Re: Cnan't play mp3 with phonon

    Hello CeeKey, thanks for your reply
    With that code you can play mp3 ? I see just a difference:
    Qt Code:
    1. VideoWidget *videoWidget = new VideoWidget();
    2. Phonon::createPath(mediaObject, videoWidget);
    To copy to clipboard, switch view to plain text mode 
    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

  10. #10
    Join Date
    Jun 2010
    Posts
    23
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Cnan't play mp3 with phonon

    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.
    Stelios: What the hell are you laughing at?
    Astinos: Well, you had to say it!
    Stelios: What?
    Astinos: "Fight in the shade"!
    -------------------------------------------
    If my answer has helped you, i would appreciate it if you use the thanks button.

  11. #11
    Join Date
    Apr 2010
    Posts
    98
    Thanks
    19
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Cnan't play mp3 with phonon

    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.
    It's not the goodbye that hurts,but the flashback that follow.

  12. #12
    Join Date
    Oct 2009
    Posts
    19
    Thanked 1 Time in 1 Post

    Default Re: Cnan't play mp3 with phonon

    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

Similar Threads

  1. Play video file with Phonon and GStreamer show black screen
    By SimbadSubZero in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2010, 11:47
  2. Replies: 6
    Last Post: 23rd December 2009, 10:45
  3. Phonon Cannot Play Sound (without Error)
    By padawan in forum Qt Programming
    Replies: 5
    Last Post: 16th September 2009, 15:17
  4. Replies: 0
    Last Post: 5th August 2008, 10:54
  5. Phonon Media Object blocking on play()
    By traetox in forum Qt Programming
    Replies: 0
    Last Post: 21st May 2008, 05:43

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.