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



  • 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


  • Lifetime Qt Champion

    Hi,

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



  • 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


  • Lifetime Qt Champion

    Do you have
    @QT += multimedia@

    in your pro file ?



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



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



  • 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)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.