Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QMediaPlayer won't play files

[SOLVED] QMediaPlayer won't play files

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 10.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    danielbsig
    wrote on last edited by
    #1

    Hi,

    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.

    Regards,
    Daniel

    1 Reply Last reply
    0
    • D Offline
      D Offline
      danielbsig
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cyberrob
        wrote on last edited by
        #3

        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?

        player.setMedia(QUrl("qrc://sound/sound/System.mp3"));

        1 Reply Last reply
        0
        • H Offline
          H Offline
          herculis
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved