QMediaPlaylist :: addMedia()对不存在的文件返回true

编程入门 行业动态 更新时间:2024-10-27 18:25:01
本文介绍了QMediaPlaylist :: addMedia()对不存在的文件返回true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

文档说如果QMediaPlaylist :: addMedia失败,则返回false:

bool QMediaPlaylist :: addMedia(const QMediaContent& content )将媒体内容附加到播放列表。 如果操作成功返回true,否则返回false。

但是这个代码将打印为true, 't exists:

QMediaPlayer * player = new QMediaPlayer; QMediaPlaylist * playlist = new QMediaPlaylist(player); qDebug()<< playlist-> addMedia(QUrl(this file does not exist.mp4));

如果文件不存在,操作如何才能成功?

$ b在进入Qt源后,我看到QMediaPlaylist :: addMedia()调用 QMediaNetworkPlaylistProvider :: addMedia() code>,它总是返回true:

bool QMediaPlaylist :: addMedia(const QMediaContent& content) { return d_func() - > control-> playlistProvider() - > addMedia(content); } bool QMediaNetworkPlaylistProvider :: addMedia(const QMediaContent& content) { Q_D(QMediaNetworkPlaylistProvider); int pos = d-> resources.count(); emit mediaAboutToBeInserted(pos,pos); d-> resources.append(content); emit mediaInserted(pos,pos); return true; }

虽然为什么它需要返回一个总是真的bool是一个谜。

The docs say that QMediaPlaylist::addMedia returns false if it fails:

bool QMediaPlaylist::addMedia(const QMediaContent & content) Append the media content to the playlist. Returns true if the operation is successful, otherwise return false.

But this code will print true even though the file doesn't exist:

QMediaPlayer *player = new QMediaPlayer; QMediaPlaylist *playlist = new QMediaPlaylist(player); qDebug() << playlist->addMedia(QUrl("this file doesn't exist.mp4"));

If the file doesn't exist how can the operation be considered successful?

解决方案

After stepping into the Qt sources, I saw that QMediaPlaylist::addMedia() calls QMediaNetworkPlaylistProvider::addMedia(), which always returns true:

bool QMediaPlaylist::addMedia(const QMediaContent &content) { return d_func()->control->playlistProvider()->addMedia(content); } bool QMediaNetworkPlaylistProvider::addMedia(const QMediaContent &content) { Q_D(QMediaNetworkPlaylistProvider); int pos = d->resources.count(); emit mediaAboutToBeInserted(pos, pos); d->resources.append(content); emit mediaInserted(pos, pos); return true; }

Although why it needs to return a bool that's always true is a mystery to me.

更多推荐

QMediaPlaylist :: addMedia()对不存在的文件返回true

本文发布于:2023-06-08 14:30:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/583107.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对不   文件   QMediaPlaylist   addMedia   true

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!