遇到了一个坑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问题的更多相关文章

  1. FFMpeg video duration

    1. 代码 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import ...

  2. OutputCache属性详解(一)一Duration、VaryByParam

    目录 OutputCache概念学习 OutputCache属性详解(一) OutputCache属性详解(二) OutputCache属性详解(三) OutputCache属性详解(四)— SqlD ...

  3. Window 下 Qt5 使用QMediaplayer 进行视频播放 流播放问题

    int main(int argc, char *argv[]) { QApplication a(argc, argv); QWidget *widget = new QWidget; widget ...

  4. golang time and duration

    package mainimport "fmt"import "time"func main() { p := fmt.Println // We'll sta ...

  5. css3动画属性(transitions:property duration timing transition-delay)

    transitions:property duration timing-function; transitionst他有三个参数:1) property:属性设置,例如background,colo ...

  6. 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 ...

  7. org.openqa.selenium.WebDriverException: f.QueryInterface is not a function Command duration or timeout:

    今天偶遇一个问题,运行项目时,发现这个问题: org.openqa.selenium.WebDriverException: f.QueryInterface is not a functionCom ...

  8. RxCache 的代码分析,含缓存时间duration的在代码中改变的自己实现的机制

    当应用进程创建 RxCache 的实例后,会给应用进程返回一个 rxcache实例及一个 ProxyProvider,代码如下: CacheProviders providers = new RxCa ...

  9. transcode_step()在转码过程中对pts、dts、duration的处理

    对pts.dts.duration的处理主要集中在两大函数里面 1.process_input()读入数据并处理,放到滤镜里面 2.reap_filters()从滤镜读出数据,处理后写入文件 proc ...

随机推荐

  1. poj 2356鸽笼原理水题

    关于鸽笼原理的知识看我写的另一篇博客 http://blog.csdn.net/u011026968/article/details/11564841 (需要说明的是,我写的代码在有答案时就输出结果了 ...

  2. JavaScript自调用匿名函数

    Self-Invoking Anonymous Function,即自调用匿名函数.顾名思义,该函数没有名称,不同的是,该函数定义后立即被调用.该函数的作用是在应用中初始化或做一次性工作. 普通匿名函 ...

  3. 基于visual Studio2013解决C语言竞赛题之0510求最大和

     题目

  4. SQL Server 基础 01 数据库、表操作

    对着书慢慢学习,一天一点点! 数据库操作 (create.alter.drop)  --3-3-1 /create database 语句创建数据库 create database testSQL - ...

  5. 07-UIKit(tableview的编辑模式、accessoryView)

    目录: 一.tableview的编辑模式-增删改查 二.不使用继承创建tableview 三.accessoryView辅助视图 回到顶部 一.tableview的编辑模式-增删改查 [1-conta ...

  6. 05-OC多态

    目录: 一.继承的缺陷 二.为什么使用继承 三.组合和聚合 四.多态 回到顶部 一.继承的缺陷 1 提高了程序的复杂度,维护性和扩展性低 2 破坏了类的封装性 回到顶部 二.为什么使用继承 1 代码复 ...

  7. 知识点2-5:了解Razor语法

    以往开发ASP.NET Web Form时,在ASPX页面上都会出现许多夹杂C#/VB.NET与HTML的情况,而先前使用<%...%>这种传统圆角括号的表示法会让HTML标签与ASP.N ...

  8. 演练5-2:Contoso大学校园管理2

    一.添加列标题排序功能 我们将增加Student/Index页面的功能,为列标题添加超链接,用户可以点击列标题对那一列进行排序. 1.修改Index方法 public ActionResult Ind ...

  9. 线程:Message和Runnable

    原文地址http://blog.csdn.net/flowingflying/article/details/6370184 程序需要相应用户的操作,最要能在200ms(0.2s)之内,如果超过5秒没 ...

  10. RAID级别与规范

    1.RAID 0 RAID 0是最早出现的RAID模式,即Data Stripping数据分条技术.RAID 0是组建磁盘阵列中最简单的一种形式,只需要2块以上的硬盘即可,成本低,可以提高整个磁盘的性 ...