PDA

View Full Version : Playing an audio file with phonon



epaduel
30th January 2012, 04:35
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.




MyClass::MyClass(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);

Phonon::MediaObject *mediaObject;
Phonon::AudioOutput *audioOutput;

audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
mediaObject = new Phonon::MediaObject(this);
audioOutput->setVolume(0.5);

Phonon::createPath(mediaObject, audioOutput);

mediaObject->setCurrentSource(QString("vai.wav") );
mediaObject->play();

}



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...

wysota
30th January 2012, 11:34
What do the following two calls return?


Phonon::BackendCapabilities::availableAudioOutputD evices()
Phonon::BackendCapabilities::availableMimeTypes()

epaduel
30th January 2012, 19:19
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")

wysota
30th January 2012, 19:22
Ok, so it seems Phonon itself is working. Try passing an absolute file path to the file.

epaduel
31st January 2012, 01:03
Hi, so I put the following code:



mediaObject->setCurrentSource(QString("C:\vai.mp3") );


and



mediaObject->setCurrentSource(QString("C:/vai.mp3") );


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

thank you.

KillGabio
31st January 2012, 02:48
try adding your file to the resourses of your project and then just do QString (":/musicFiles/vai.mp3")