编程语言
首页 > 编程语言> > c++(qt)播放wav文件的四种方式

c++(qt)播放wav文件的四种方式

作者:互联网

  //方法一(要符合RIFF规范)
1     QSound::play("E:/Projects/报警声1-1.wav");
  //方法二(要符合RIFF规范)
1     QSoundEffect in_effect;
2     in_effect.setSource(QUrl::fromLocalFile("E:/Projects/报警声1-1.wav"));
3     in_effect.setLoopCount(QSoundEffect::Infinite);
4     in_effect.setVolume(0.25f);    
5     in_effect.play();
  //方法三(要符合RIFF规范)
 1     QFile in_wavFile;
 2     in_wavFile.setFileName("E:/Projects/报警声2-1.wav");
 3     in_wavFile.open(QIODevice::ReadOnly);
 4     QAudioFormatin_audioFormat;
 5     in_audioFormat.setSampleRate(44100);
 6     in_audioFormat.setChannelCount(2);
 7     in_audioFormat.setSampleSize(16);
 8     in_audioFormat.setCodec("audio/pcm");
 9     in_audioFormat.setByteOrder(QAudioFormat::LittleEndian);
10     in_audioFormat.setSampleType(QAudioFormat::UnSignedInt);
11     QAudioOutput*in_audio=newQAudioOutput(in_audioFormat,0);
12     in_audio->start(&in_wavFile);
  //方法四(限MP3格式编码的wav文件)
1     QMediaPlayer *in_player = new QMediaPlayer;
2     in_player->setMedia(QUrl::fromLocalFile("E:/Projects/报警声2-1.wav"));
3     in_player->setVolume(50);
4     in_player->play();
   
  //最近离职了,三年如一日,有意者 -> qq邮箱 1358849798@qq.com,非诚勿扰
   

标签:qt,effect,c++,player,audioFormat,wav,Projects,wavFile
来源: https://www.cnblogs.com/Kevinsh-Lee/p/15325158.html