遇到了一个坑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. 安卓Launcher之获取手机安装的应用列表,安卓launcher

    Launcher中最主要的就是获取所有应用列表的入口以及图标,一般获取的方法有两种: PackageInfo ResolveInfo 运行获取所有APP的Launcher并且允许进行点击事件,进入到应 ...

  2. 基于visual Studio2013解决C语言竞赛题之0514单词统计

     题目 解决代码及点评 /************************************************************************/ /* 14. 有一行字 ...

  3. 基于html5 localStorage , web SQL, websocket的简单聊天程序

    new function() { var ws = null; var connected = false; var serverUrl; var connectionStatus; var send ...

  4. test code

    <?php abstract class Mediator{ abstract public function send($message, $colleague); } abstract cl ...

  5. winform判断输入是否是数字

    private bool IsNum(string str) { try { foreach (char c in str) { if (char.IsDigit(c)) return true; r ...

  6. 一口一口吃掉Hibernate(八)——Hibernate中inverse的用法

    一.Inverse是hibernate双向关系中的基本概念.inverse的真正作用就是指定由哪一方来维护之间的关联关系.当一方中指定了“inverse=false”(默认),那么那一方就有责任负责之 ...

  7. Hadoop 配置文件简介

    1.core-site.xml文件 这是一个描述集群中NameNode结点的URI-统一资源标识符(包括协议,主机名称,端口号),集群里面的每一台机器都需要知道 NameNode的地址.DataNod ...

  8. 08-UIKit(UITableTableViewCell、自定义Cell、xcode调试)

    目录: 1. UITableTableViewCell 2. tag技术 3. 自定义Cell 4. 用nib文件构造自定义的静态表 5. TableView数据模型总结 6. Xcode代码调试 & ...

  9. JAVA刚碰见的问题( java.lang.SecurityException: The jurisdiction policy files are not signed by a trusted signer)

    原文:刚碰见的问题 1.  failed to load the jni shared library jre bin server jvm.dll 解决:这个主要是eclipse的版本和安装的jdk ...

  10. BNU Questions and answers

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=2490 这个题是先输入一个整数n,说明有几个数据,然后输入n个整数,然后用三个#分开,后面输入整数k, ...