QMediaPlaylist::addMedia() returns true for nonexistent files

怎甘沉沦 提交于 2019-12-24 16:08:05

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/29603018/qmediaplaylistaddmedia-returns-true-for-nonexistent-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!