I am using Qt Version 5.14.1.
When I was trying to play a video(.mp3), the program stopped working
And given error is DirectShowPlayerService::doSetUrlSource: Unresolved error code 0x8007007b ()
AudioPlayer::AudioPlayer(QObject *parent)
: QObject(parent)
, m_backgroundMusic(NULL) //QMediaPlayer * m_backgroundMusic
{
QUrl backgroundMusicUrl = QUrl::fromLocalFile(":/music/8bitDungeonLevel.mp3");
if (QFile::exists(backgroundMusicUrl.toLocalFile()))
{
m_backgroundMusic = new QMediaPlayer(this);
QMediaPlaylist * backgroundMusicList = new QMediaPlaylist();
QMediaContent media(backgroundMusicUrl);
backgroundMusicList->addMedia(media);
backgroundMusicList->setCurrentIndex(0);
backgroundMusicList->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop);
m_backgroundMusic->setPlaylist(backgroundMusicList);
}
}
void AudioPlayer::startBGM()
{
if (m_backgroundMusic)
{
qDebug() << m_backgroundMusic;
m_backgroundMusic->play();
}
}
the output as below
QMediaPlayer(0x3987eb0)
DirectShowPlayerService::doSetUrlSource: Unresolved error code 0x8007007b ()
I search the Internet and add LAV Filters to QT installation directory , I also restart the computer but nothing changes.So how to fix it?
Your path in QUrl::fromLocalFile(":/music/8bitDungeonLevel.mp3")
appears to be off, AFIK there is no (at least not common) path naming scheme that uses :
to begin paths.
UPDATE:
I was told that :/
refers to resources that have been compiled into a Qt application, I think using the Qt Resource Compiler (rcc)
Use this code to load mp3 from resources:
m_mediaPlayer.setMedia(QUrl("qrc:/Audio/MouseOver.mp3"));
(do no forget do delete fromLocalFile
)
User contributions licensed under CC BY-SA 3.0