[SOLVED] QMediaPlayer won't play files
I have a rather strange problem with code which uses the class QMediaPlayer from the MultimediaWidgets library in QT 5.0.1. I found the "Player" example from "examples\multimediawidgets\player", and that works. However, in my application, it doesn't, and I get an error saying "Failed to load source." from the error(QMediaPlayer::Error) signal. This happens after the mediaStatusChanged signal is emitted with QMediaPlayer::LoadingMedia. Note: I'm using basically the same code as in the Player example, except I'm not using a playlist, but rather I'm calling setMedia directly (since I only plan to play one file at the time).
When I instruct the Player example to play the exact same files as I try to play using my code, it works, so I know the files are OK. I've also compared the paths to the files, and they are identical. The only thing I can see as different between those two applications is that my application uses QDeclarative to render the UI, i.e. QQuick 1. My first guess is that it is highly unlikely that this should interfere with the playback of media files, but you never know.
So, has anyone seen something similar? Are there ways for me to get more debug information about what error exactly is occurring? Any help whatsoever would be greatly appreciated.
For future reference, I found the solution to this problem, and it was basically twofold:
a) calling play() immediately after calling setMedia() was not working. I had to listen to the mediaStateChanged signal, and when the state changes to QMediaPlayer::LoadedMedia, I can call play(). Since I had to do this for two different media players (I have a separate player for video and another for audio on the same window), I created a subclass which takes care of this.
b) calling QUrl::fromLocalFile() with a path which already includes the "file:" prefix, will result in an URL which has this prefix twice, i.e. file:file///C:/path/to/file.mp3.
Hi, first thanks for your experience sharing.
I got my QMediaPlayer connect to a SLOT handleMediaStateChange(), handleError(). Here's the output:
btn clicked media path : "qrc://sound/sound/System.mp3" is audio available? Error : QMediaPlayer::FormatError Media state : QMediaPlayer::InvalidMedia
According to the log, is that mean the mp3 couldn't play due the codec problem? I'm running it on the Mac with Qt 5.3.0. What other format could be used?
Secondly, could the media file be set from reading resource like?
hello guys for its showing codec missing i have all the codec then also its showing codec missing please nayone could you help us plz