版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/qq_32768743/article/details/89046925
首先是编译,依赖为
sudo apt install qttools5-dev-tools libdtkwidget-dev libavformat-dev
运行起来的第一个界面
这个界面很简单,就是一个按钮定义三种状态
recordButton = new DImageButton(
Utils::getQrcPath("home_page_record_normal.svg"),
Utils::getQrcPath("home_page_record_hover.svg"),
Utils::getQrcPath("home_page_record_press.svg")
);
发现控制台输出
defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.mediaplayer"
defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.audiosource"
我运行深度自带的
输出为
support codecs: ("audio/x-adpcm, layout=(string)dvi", "audio/x-alaw", "audio/x-flac", "audio/x-gsm", "audio/mpeg, mpegversion=(int)1, layer=(int)3", "audio/x-mulaw", "audio/x-opus", "audio/x-speex", "audio/mpeg, mpegversion=(int)1, layer=(int)2", "audio/x-vorbis", "audio/AMR", "audio/mpeg, mpegversion=(int)4", "audio/AMR-WB", "audio/x-siren")
support containers: ("video/quicktime, variant=(string)3gpp", "audio/x-aiff", "video/x-ms-asf", "video/x-msvideo", "video/x-flv", "video/quicktime, variant=(string)iso-fragmented", "video/x-matroska", "video/x-matroska-3d", "audio/x-matroska", "video/mj2", "video/quicktime, variant=(string)iso", "video/mpeg, mpegversion=(int)2", "video/mpegts", "application/mxf", "application/ogg", "audio/ogg", "video/ogg", "video/quicktime, variant=(string)apple", "video/quicktime", "audio/x-wav", "audio/x-rf64", "video/webm", "audio/webm", "audio/mpeg, mpegversion=(int)1")
对应的代码为
audioRecorder = new QAudioRecorder(this);
qDebug() << "support codecs:" << audioRecorder->supportedAudioCodecs();
qDebug() << "support containers:" << audioRecorder->supportedContainers();
然后发现flatpak版本可以用,deb版本不可以使用
这个是录音界面,
这个是播放录音界面,有三部分组成。上面是录音列表,中间是播放的时候的波形,下面的和主页的那个一样是录音按钮。
点击录音时,有一个动画效果
这个使用代码直接画的
if (renderTicker <= animationFrames) {
painter.setOpacity(1 * Utils::easeOutQuad(std::min(renderTicker, opacityFrames) / (opacityFrames * 1.0)));
painter.drawPixmap(QPoint((rect().width() - pauseButtonImg.width() / devicePixelRatio) / 2 - Utils::easeOutQuad((renderTicker) / (animationFrames * 1.0)) * ANIMATION_WIDTH,
(rect().height() - pauseButtonImg.height() / devicePixelRatio) / 2),
pauseButtonImg);
painter.setOpacity(1 * Utils::easeOutQuad(std::min(renderTicker, opacityFrames) / (opacityFrames * 1.0)));
painter.drawPixmap(QPoint((rect().width() - finishButtonImg.width() / devicePixelRatio) / 2 + Utils::easeOutQuad((renderTicker) / (animationFrames * 1.0)) * ANIMATION_WIDTH,
(rect().height() - finishButtonImg.height() / devicePixelRatio) / 2),
finishButtonImg);
}
至于这个动画曲线,还没懂
右键有三个Action
在文件管理器中显示实现为
DDesktopServices::showFileItem(fileItem->getFileInfo().absoluteFilePath());
移动到回收站的实现为
Dtk::Widget::DDesktopServices::trash(fileItem->getRecodingFilepath());
当录音文件多了以后,滑动的感觉很不好
代码中还有一个计算音频长度的代码,单独展示Demo在:https://blog.csdn.net/qq_32768743/article/details/89047038
int FileItem::getDuration()
{
int64_t duration = 0;
av_register_all();
AVFormatContext *pFormatCtx = avformat_alloc_context();
avformat_open_input(&pFormatCtx, fileInfo.absoluteFilePath().toStdString().c_str(), NULL, NULL);
if (pFormatCtx) {
avformat_find_stream_info(pFormatCtx, NULL);
duration = pFormatCtx->duration / 1000;
}
avformat_close_input(&pFormatCtx);
avformat_free_context(pFormatCtx);
return duration;
}
我觉得比较难的点
-
录音的实现
这是这个软件最重要的功能 -
波形的绘制