简体   繁体   中英

Qt and audio playback

I'm trying to get some audio in my Qt desktop application, however all seems FUBAR. I tried QSound, like this:

QSound *sound=new QSound("/home/kajos/Projects/Flatland-build-desktop/mario.wav", this);
sound->setLoops(3);
sound->play();

and Phonon like this:

QFile file("mario.mp3");
if (!file.open(QIODevice::ReadOnly)) {
    qDebug("Music not found");
} else {
    Phonon::MediaObject *mediaObject = Phonon::createPlayer(Phonon::MusicCategory);

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

QSound doesn't do anything (with mid, mp3, wav) and Phonon throws this error:

ASSERT: "d->connected" in file ../../phonon/streaminterface.cpp, line 89
The program has unexpectedly finished.

Any idea on how to get some sound in my app? I can play sounds fine on my system, ubuntu 11.10. I'm open to midi only suggestions, since that is what I would like to focus on if possible.

I read with a similar case with Phonon, that it happens in debug mode, but I would like to debug.

我在台式机上使用了QT移动性。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM