QT5 QSound does not play all wave files

前端 未结 2 1320
暖寄归人
暖寄归人 2021-01-21 09:17

I am in the midst of migrating our app based on QT4.X to QT5. Phonon support has been removed in QT5, so I have changed my code that plays a wave file to use QSound.

Cha

相关标签:
2条回答
  • 2021-01-21 09:35

    Also note that Qt has several different sound playback APIs. For small file playback with lower latency I found this to be much faster: http://doc.qt.io/qt-5/qsoundeffect.html#details

    Also: http://doc.qt.io/qt-5/qmediaplayer.html

    0 讨论(0)
  • 2021-01-21 09:47

    It turns out that some wave files confuse QSound. Still not sure exactly what causes the issue. When I loaded my wave file in Audacity, and then exported it back to a different wave file without any changes(same sample rate...). QSound played the file just fine.

    In MacOSX when I click "Get Info" on the problematic wave file, general wave info record from the wave file was not available; so perhaps QSound was unable to get sample rate information from; and because it did not know which sample rate to expect from the wave file?

    The interesting part is that iTunes played the original file just fine, and it had the correct sample rate somehow. Also Phonon used to play the original file as well just fine.

    Anyhow, hopefully this helps with some people that had issues with QSound::play() method.

    UPDATE: Since QSound::play() was very buggy on the mac, I opted to use the native NSSound to play my wave files from QT application on the mac. Here is the code:

    void play_sound( const char* file)
    {
        NSSound *sound = [[NSSound alloc] initWithContentsOfFile:[NSString stringWithUTF8String:file] byReference:NO];
        [sound play];
        [sound release];
    }
    
    0 讨论(0)
提交回复
热议问题