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] How to add local file to the MediaPlayer class?
Forum Update on Monday, May 27th 2025

[Solved] How to add local file to the MediaPlayer class?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 4.3k 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.
  • I Offline
    I Offline
    inblueswithu
    wrote on 11 Sept 2013, 10:19 last edited by
    #1

    Hi,

    I'm trying to make a media player.
    In the process I want to add a playlist to the MediaPlayer. I did as follows:
    @QMediaPlaylist *list = new QMediaPlaylist();
    list->addMedia(new QMediaContent(QUrl::fromLocalFile("C:/Users/inblueswithu/Songs/MySong.mp3")));@

    But Its throwing an error.
    @MediaPlayer.cpp:11: error: C2664: 'bool QMediaPlaylist::addMedia(const QMediaContent &)' : cannot convert parameter 1 from 'QMediaContent *' to 'const QMediaContent &'
    Reason: cannot convert from 'QMediaContent *' to 'const QMediaContent'
    No constructor could take the source type, or constructor overload resolution was ambiguous@
    Please help me!

    Regards,
    inblueswithu

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 11 Sept 2013, 10:29 last edited by
      #2

      Hi,

      Just remove the new and you should be good. addMedia doesn't take a pointer to a QMediaContent.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • I Offline
        I Offline
        inblueswithu
        wrote on 11 Sept 2013, 10:36 last edited by
        #3

        Thanks. I did it. But it got a whole new set of errors saying:

        @MediaPlayer.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QMediaContent::QMediaContent(class QUrl const &)" (_imp??0QMediaContent@@QEAA@AEBVQUrl@@@Z) referenced in function "public: bool __cdecl MediaPlayer::createPlaylist(void)" (?createPlaylist@MediaPlayer@@QEAA_NXZ)
        MediaPlayer.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QMediaContent::~QMediaContent(void)" (_imp??1QMediaContent@@QEAA@XZ) referenced in function "public: bool __cdecl MediaPlayer::createPlaylist(void)" (?createPlaylist@MediaPlayer@@QEAA_NXZ)

        So on.. @
        I did qmake & rebuild all. But same error persists

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 11 Sept 2013, 10:37 last edited by
          #4

          Do you have
          @QT += multimedia@

          in your pro file ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • I Offline
            I Offline
            inblueswithu
            wrote on 11 Sept 2013, 10:43 last edited by
            #5

            nope :( I just did. Got rid off all those errors :)
            Thank you so much :)

            1 Reply Last reply
            0
            • I Offline
              I Offline
              inblueswithu
              wrote on 11 Sept 2013, 10:47 last edited by
              #6

              Just Curious:
              How come without adding a new keyword QMediaContent can produce a new object?

              1 Reply Last reply
              0
              • K Offline
                K Offline
                koval
                wrote on 11 Sept 2013, 10:58 last edited by
                #7

                Without the new keyword temporary object is created on the stack and a reference is passed to the function (new creates objects on heap and returns pointers - this is why the compiler complained about conversions)

                1 Reply Last reply
                0

                1/7

                11 Sept 2013, 10:19

                • Login

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