[Solved] How to add local file to the MediaPlayer class?
-
wrote on 11 Sept 2013, 10:19 last edited by
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 -
Hi,
Just remove the new and you should be good. addMedia doesn't take a pointer to a QMediaContent.
-
wrote on 11 Sept 2013, 10:36 last edited by
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 -
Do you have
@QT += multimedia@in your pro file ?
-
wrote on 11 Sept 2013, 10:43 last edited by
nope :( I just did. Got rid off all those errors :)
Thank you so much :) -
wrote on 11 Sept 2013, 10:47 last edited by
Just Curious:
How come without adding a new keyword QMediaContent can produce a new object? -
wrote on 11 Sept 2013, 10:58 last edited by
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/7