QMediaPlayer的duration问题
遇到了一个坑QMediaPlayer::duration的坑.
这个坑是当你setMedia之后, 直接使用duration获取播放时长会得到0, 出错时候的代码片段例如以下:
void MainWindow::slotPlayAudio(const QString &audioFilePath)
{
currentAudioFilePath_ = audioFilePath; player_->setMedia(QUrl::fromLocalFile(audioFilePath));
player_->setVolume(50);
horizontalSliderMusic->setMinimum(0);
horizontalSliderMusic->setMaximum(player_->duration()); //这里的duration返回是0, 从而导致之后处理进度的时候出错
player_->play();
pushButtonPlay->setText("pause");
}
针对这个问题文档中对此描写叙述是"The value may change across the
life time of the QMediaPlayer object and may not be available when initial playback begins"
要解决问题能够在响应durationChanged信号的槽中获取duration, 这个时候duration是正确的, 如此能够使用诸如以下的代码进行处理:
connect(player_, &QMediaPlayer::positionChanged, [this](qint64 position){
if(player_->duration() != horizontalSliderMusic->maximum())
{
horizontalSliderMusic->setMaximum(player_->duration());
}
horizontalSliderMusic->setValue(position);
});
QMediaPlayer的duration问题的更多相关文章
- FFMpeg video duration
1. 代码 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import ...
- OutputCache属性详解(一)一Duration、VaryByParam
目录 OutputCache概念学习 OutputCache属性详解(一) OutputCache属性详解(二) OutputCache属性详解(三) OutputCache属性详解(四)— SqlD ...
- Window 下 Qt5 使用QMediaplayer 进行视频播放 流播放问题
int main(int argc, char *argv[]) { QApplication a(argc, argv); QWidget *widget = new QWidget; widget ...
- golang time and duration
package mainimport "fmt"import "time"func main() { p := fmt.Println // We'll sta ...
- css3动画属性(transitions:property duration timing transition-delay)
transitions:property duration timing-function; transitionst他有三个参数:1) property:属性设置,例如background,colo ...
- A python tool to static sim.log duration time
When working ALU IMS Patch team, we need to static the SU duration to add it to the patch report, th ...
- org.openqa.selenium.WebDriverException: f.QueryInterface is not a function Command duration or timeout:
今天偶遇一个问题,运行项目时,发现这个问题: org.openqa.selenium.WebDriverException: f.QueryInterface is not a functionCom ...
- RxCache 的代码分析,含缓存时间duration的在代码中改变的自己实现的机制
当应用进程创建 RxCache 的实例后,会给应用进程返回一个 rxcache实例及一个 ProxyProvider,代码如下: CacheProviders providers = new RxCa ...
- transcode_step()在转码过程中对pts、dts、duration的处理
对pts.dts.duration的处理主要集中在两大函数里面 1.process_input()读入数据并处理,放到滤镜里面 2.reap_filters()从滤镜读出数据,处理后写入文件 proc ...
随机推荐
- 【HTTP 2】简介(Introduction)
前情提要 在上一篇文章<[HTTP 2.0] 序言>中,我们简要介绍了 HTTP 2 协议的概要和协议状态. 在本篇文章中,我们将会了解到 HTTP 2 协议简介(Introduction ...
- Linux命令之find(一)
find命令的使用格式为:find options path expressions find命令事实上有两种options,一种是"真正属于自己的",还有一种位于expressi ...
- ASP.NET Excel导入到SQL Server数据库
本文转自:http://www.cnblogs.com/lhking/archive/2009/06/08/1499002.html 提供把Excel里的数据导入到SQL Server 数据库,前提是 ...
- getopt、getopt_long和getopt_long_only
GNU/Linux的命令行选项有两种类型:短选项和长选项,前者以 '-' 作为前导符,后者以 '--' 作为前导符.比如有一个命令: $ myprog -a vv --add -b --file a. ...
- Qt实现QQ好友下拉列表(用QListView实现,所以还得定义它的Model)
偶然发现Qt有个控件可以实现下拉列表,所以就试着实现一下类似QQ面板的下拉列表,这里主要实现几个功能: 1.可以删除列表中图标 2.可以像qq一样的,把某个分组下的图标转移到另外的分组 3.添加分组 ...
- Java基础10 接口的继承与抽象类
链接地址:http://www.cnblogs.com/vamei/archive/2013/03/31/2982240.html 作者:Vamei 出处:http://www.cnblogs.com ...
- Eclipse 优化方法(经典收藏)
第一步: 取消自动validationvalidation有一堆,什么xml.jsp.jsf.js等等,我们没有必要全部都去自动校验一下,只是需要的时候才会手工校验一下! 取消方法:windows–& ...
- VS2008+Qt 项目目录
1.项目开发环境:VS2008,QT4.7 2.项目的目录: 1)PETCT是解决方案名字 2)Bin目录存放所有动态链接库和执行档,包括自己的产出和第三方库,区分Release和Debug两个版本. ...
- C# c++ 传递函数指针
C#和c++之间相互传递函数指针 在C++和C#之中都有很多callback method,可以相互调用吗,怎么传递,是我表弟的问题. 1.定义c++ dll ,导出方法 // sort.cpp : ...
- 设计模式模式适配器(Adapter)摘录
23种子GOF设计模式一般分为三类:创建模式.结构模型.行为模式. 创建模式抽象的实例,他们帮助建立一个系统,是独立于如何.这是一个这些对象和陈述的组合.创建使用继承一个类架构更改实例,一个对象类型模 ...