遇到了一个坑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. Android中如何查找内存泄露

    1.首先确定是否有内存泄露及哪个程序造成. 1.1.内存泄露已弹出out of memory对话框的情况. 这种情况很简单,直接看对话框就知道是哪个应用的问题了.然后再分析该应用是否是因为内存泄露造成 ...

  2. POJ1700(过河问题)

    #include<iostream> #include<algorithm> using namespace std; ]; int main() { int t,i; cin ...

  3. uva 10330 - Power Transmission(网络流)

    uva 10330 - Power Transmission 题目大意:最大流问题. 解题思路:増广路算法. #include <stdio.h> #include <string. ...

  4. 高级UIKit-06(UIImagePickerController)

    [day07-1-getSystemImage]:获取系统相册 UIImagePickerController图片采集控制器 picker采集者,采摘者 该方法继承自:UINavigationCont ...

  5. Ajax的三种实现及JSON解析

    本文为学习笔记,属新手文章,欢迎指教!! 本文主要是比较三种实现Ajax的方式,为以后的学习开个头. 准备: 1.  prototype.js 2.  jquery1.3.2.min.js 3.  j ...

  6. 一、Mongo的安装

    注:学习为主,平台为WIN7 32位系统 一.Mongo的安装 1.1 下载 到官方下载地址(http://www.mongodb.org/downloads)去下载所需要的版本 1.2 安装与运行 ...

  7. 清华集训2014 day1 task1 玛里苟斯

    题目 这可算是描述很简单的一道题了!但是不简单. \(S\)是一个可重集合,\(S = \{a_1, a_2, \dots, a_n \}\). 等概率随机取\(S\)的一个子集\(A = \{a_{ ...

  8. Ubuntu Gnome下如何改动应用的图标icon

    我在我机器上安装了一个matlab,但在软件搜索里找不到matlab. 我发现是matlab没有相应的.desktop文件. 顺便我将matlab的图标也改动下.过程例如以下: 1.准备一个icon图 ...

  9. BZOJ 3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛( dp )

    水题...忘了取模就没1A了.... --------------------------------------------------------------------------- #incl ...

  10. 抽象类(abstract class)和 接口(interface)

    PHP中的 抽象类(abstract class)和 接口(interface) 一. 抽象类abstract class 1 .抽象类是指在 class 前加了 abstract 关键字且存在抽象方 ...