Results 1 to 6 of 6

Thread: Playing an audio file with phonon

  1. #1
    Join Date
    Jan 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Playing an audio file with phonon

    Hi all,

    I'm trying to play a simple audio file with phonon, but the sound doesn't work. The compilation process is ok, and the phonon linking is ok too.

    Qt Code:
    1. MyClass::MyClass(QWidget *parent, Qt::WFlags flags)
    2. : QMainWindow(parent, flags)
    3. {
    4. ui.setupUi(this);
    5.  
    6. Phonon::MediaObject *mediaObject;
    7. Phonon::AudioOutput *audioOutput;
    8.  
    9. audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
    10. mediaObject = new Phonon::MediaObject(this);
    11. audioOutput->setVolume(0.5);
    12.  
    13. Phonon::createPath(mediaObject, audioOutput);
    14.  
    15. mediaObject->setCurrentSource(QString("vai.wav") );
    16. mediaObject->play();
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

    My development environment is windows7 + VS2010 + QT 4.7.
    There's last one thing: the path audio file is correct and it's in the same directory the generated executable.

    Thanks all so much...

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Playing an audio file with phonon

    What do the following two calls return?

    Qt Code:
    1. Phonon::BackendCapabilities::availableAudioOutputDevices()
    2. Phonon::BackendCapabilities::availableMimeTypes()
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Playing an audio file with phonon

    Wysota, the output was:

    ("Default DirectSound Device", "DirectSound: Communications Headphones (IDT High Definition Audio CODEC)", "DirectSound: Speakers and Headphones (IDT High Definition Audio CODEC)", "Speakers and Headphones (IDT Hi", "Communications Headphones (IDT ", "Default WaveOut Device")

    ("application/vnd.ms-wpl", "application/x-mplayer2", "application/x-ms-wmd", "application/x-ms-wmz", "audio/3gpp", "audio/3gpp2", "audio/aiff", "audio/basic", "audio/mid", "audio/midi", "audio/mp3", "audio/mp4", "audio/mpeg", "audio/mpegurl", "audio/mpg", "audio/vnd.dlna.adts", "audio/wav", "audio/x-aiff", "audio/x-mid", "audio/x-midi", "audio/x-mp3", "audio/x-mpeg", "audio/x-mpegurl", "audio/x-mpg", "audio/x-ms-wax", "audio/x-ms-wma", "audio/x-wav", "midi/mid", "unknown", "video/3gpp", "video/3gpp2", "video/avi", "video/mp4", "video/mpeg", "video/mpg", "video/msvideo", "video/quicktime", "video/vnd.dlna.mpeg-tts", "video/x-mpeg", "video/x-mpeg2a", "video/x-ms-asf", "video/x-ms-asf-plugin", "video/x-ms-wm", "video/x-ms-wmv", "video/x-ms-wmx", "video/x-ms-wvx", "video/x-msvideo", "vnd.ms.wmhtml")

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Playing an audio file with phonon

    Ok, so it seems Phonon itself is working. Try passing an absolute file path to the file.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Playing an audio file with phonon

    Hi, so I put the following code:

    Qt Code:
    1. mediaObject->setCurrentSource(QString("C:\vai.mp3") );
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. mediaObject->setCurrentSource(QString("C:/vai.mp3") );
    To copy to clipboard, switch view to plain text mode 

    I'll try run this code in my linux box and then I'll post here.

    thank you.

  6. #6
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Playing an audio file with phonon

    try adding your file to the resourses of your project and then just do QString (":/musicFiles/vai.mp3")

Similar Threads

  1. Replies: 4
    Last Post: 22nd June 2011, 21:12
  2. Playing file with Phonon while stil downloading it.
    By alexandernst in forum Qt Programming
    Replies: 3
    Last Post: 10th April 2011, 11:25
  3. can't get o/p by playing mp3 file in Phonon
    By dibyendu in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2011, 13:09
  4. Replies: 4
    Last Post: 28th December 2010, 04:13
  5. Playing multiple audio files with Phonon
    By MartinWalter in forum Qt Programming
    Replies: 0
    Last Post: 23rd December 2010, 11:19

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.