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 ...
随机推荐
- FreePascal的VMT与Delphi不一致,没有负方向
因为不需要与C++兼容嘛:http://www.freepascal.org/docs-html/prog/progsu168.html 如果要想取得它真正的VMT,可以Pointer强行转换+100 ...
- 在eclipse上安装 sdk出现的各种问题
在eclipse上下进行android开发需要 有android SDK 和ADT 一般adt版本瑶台低, 会被提示安装较高版本的ADT, 不然, SDK可能无法使用 在安装 SDK过程中出现这样 ...
- BZOJ 1131: [POI2008]Sta( dfs )
对于一棵树, 考虑root的答案向它的孩子转移, 应该是 ans[son] = (ans[root] - size[son]) + (n - size[son]). so , 先 dfs 预处理一下, ...
- C-最长回文子串(2)
在上一篇的文章中说到了,最长回文子串的问题,并且提到了基本的解决办法,即暴力求解法.效率O(N^3) 中心法求最长回文子串 我们知道回文字符串是以字符串中心对称的,如abba以及aba等.一个更好的办 ...
- 解说cocos2d-x几种画图方法的用法与思考
CCRenderTexture 自己的理解 CCRenderTexture类似一张空白的“画布“,用户通过自定义笔刷(CCSprite*),在touch事件中把笔刷的移动痕迹“记录”起来,从而“画”出 ...
- 【Bootstrap3.0建站笔记一】表单元素排版
1.文字和输入框前后排列: 代码: <div class="row"> <div class="col-lg-12"> <div ...
- 解决yum升级的问题“There was a problem importing one of the Python modules”
yum命令升级的时候,报出这个错误. There was a problem importing one of the Python modules required to run yum. The ...
- SSH框架之Hibernate(1)——映射关系
ORM的实现思想就是将关系数据库中表的数据映射成对象.以对象的形式展现,这样开发者就能够把对数据库的操作转化为对这些对象的操作.Hibernate正是实现了这样的思想,达到了方便开发者以面向对象的思想 ...
- UVA 10581 - Partitioning for fun and profit(数论递推)
10581 - Partitioning for fun and profit 题目链接 题意:给定m, n,表示分配给n个格子,分配m个数字进去,每一个格子最少1,而且序列要是递增的,问第k个字典序 ...
- 读取中兴3G告警log告警文件到集合
1.文件格式 ALARM_ID=102305_404205 EVENT_TIME=-- :: NOTIFICATION_TYPE= MANAGED_OBJECT_INSTANCE=NodeId=,Bs ...