QT_PC学习_多媒体入门_Avdio

本文中内容参见QT 官方参考文档:

1. 播放压缩音频文件

player = new QMediaPlayer;
// ...
player->setMedia(QUrl::fromLocalFile("/Users/me/Music/coolsong.mp3"));
player->setVolume(50);
player->play();

QMediaPlayer也可以播放在线的音频文件按Qurl("http:://example.com/flie1.mp3")

使用QMediaPlaylist(player), 播放时可以设置播放的序列, 播放时playerList,setCurrentIndex(1);设置播放的顺序

常见的信号处理:

positionChanged()

2.录音

audioRecorder = new QAudioRecorder;
QAudioEncoderSettings audioSettings;
audioSettings.setCodec("audio/amr");
audioSettings.setQuality(QMultimedia::HighQuality);

audioRecorder->setEncodingSettings(audioSettings);

audioRecorder->setOutputLocation(QUrl::fromLocalFile("test.amr"));
audioRecorder->record();



3.音效

QSoundEffect effect;
effect.setSource(QUrl::fromLocalFile("engine.wav"));
effect.setLoopCount(QSoundEffect::Infinite);
effect.setVolume(0.25f);
effect.play();

4. 数据流控制

常用于和上层类QMediaPlayer QAudioRecorder QCamer数据交互,用于获取QAudioProbe处理的缓存数据。

audioProbe = new QAudioProbe(this);
if (audioProbe->setSource(audioRecorder)) {
<span style="white-space:pre">	</span>// Probing succeeded, audioProbe->isValid() should be true.
    	connect(audioProbe, SIGNAL(audioBufferProbed(QAudioBuffer)),
        		this, SLOT(calculateLevel(QAudioBuffer)));
}

5. 音频数据解码
QAudioFormat desiredFormat;
desiredFormat.setChannelCount(2);
desiredFormat.setCodec("audio/x-raw");
desiredFormat.setSampleType(QAudioFormat::UnSignedInt);
desiredFormat.setSampleRate(48000);
desiredFormat.setSampleSize(16);

QAudioDecoder *decoder = new QAudioDecoder(this);
decoder->setAudioFormat(desiredFormat);
decoder->setSourceFilename("level1.mp3");

connect(decoder, SIGNAL(bufferReady()), this, SLOT(readBuffer()));
decoder->start();

注意bufferReady()信号发出之后,QIODevice进行读取,这里读取缓存 decoder->read();

      

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值