PDA

View Full Version : Phonon and simple player...



make
6th March 2011, 21:22
i want to make a simple console mp3 player. I want my program to take a name of the music file in console as a paramenter argv[]. But i have a problem:


#include <QCoreApplication>
#include <phonon/AudioOutput>
#include <phonon/MediaObject>

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);

Phonon::MediaObject obj;
Phonon::AudioOutput out;

obj.setCurrentSource(Phonon::MediaSource(argv[1])); //!!!!!!!!!!!!!!
Phonon::createPath(&obj, &out);
obj.play();

return app.exec();
}


the problem is here


obj.setCurrentSource(Phonon::MediaSource(argv[1])); //!!!!!!!!!!!!!!

i think it is because MediaSource takes CONST QSTRING & parameter
but i do not know what to do! help me please!:(

megazig
6th March 2011, 23:06
QString foo = argv[1];

That's one possible way to get a QString from a char*

make
7th March 2011, 09:15
QString foo = argv[1];

That's one possible way to get a QString from a char*

no that also does not work... i use mingw and during compilling i get this:



PS C:\my\cbp> make
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/my/cbp'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_
HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\Qt\
4.7.1\include\QtCore" -I"..\..\Qt\4.7.1\include\QtGui" -I"..\..\Qt\4.7.1\include" -I"." -I"..\..\Qt\4.7.1\include\Active
Qt" -I"debug" -I"..\..\Qt\4.7.1\mkspecs\default" -o debug\main.o main.cpp
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows
-o debug\cbp.exe debug/main.o -L"c:\Qt\4.7.1\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
debug/main.o: In function `main':
C:\my\cbp/main.cpp:12: undefined reference to `_imp___ZN6Phonon11MediaObjectC1EP7QObject'
C:\my\cbp/main.cpp:13: undefined reference to `_imp___ZN6Phonon11AudioOutputC1EP7QObject'
C:\my\cbp/main.cpp:17: undefined reference to `_imp___ZN6Phonon11MediaSourceC1ERK7QString'
C:\my\cbp/main.cpp:17: undefined reference to `_imp___ZN6Phonon11MediaObject16setCurrentSourceER KNS_11MediaSourceE'
C:\my\cbp/main.cpp:17: undefined reference to `_imp___ZN6Phonon11MediaSourceD1Ev'
C:\my\cbp/main.cpp:18: undefined reference to `_imp___ZN6Phonon10createPathEPNS_9MediaNodeES1_'
C:\my\cbp/main.cpp:18: undefined reference to `_imp___ZN6Phonon4PathD1Ev'
C:\my\cbp/main.cpp:19: undefined reference to `_imp___ZN6Phonon11MediaObject4playEv'
C:\my\cbp/main.cpp:12: undefined reference to `_imp___ZN6Phonon11MediaObjectD1Ev'
C:\my\cbp/main.cpp:17: undefined reference to `_imp___ZN6Phonon11MediaSourceD1Ev'
C:\my\cbp/main.cpp:12: undefined reference to `_imp___ZN6Phonon11MediaObjectD1Ev'
debug/main.o: In function `~AudioOutput':
C:\my\cbp/../../Qt/4.7.1/include/phonon/../../src/phonon/../3rdparty/phonon/phonon/audiooutput.h:51: undefined reference
to `_imp___ZTVN6Phonon11AudioOutputE'
C:\my\cbp/../../Qt/4.7.1/include/phonon/../../src/phonon/../3rdparty/phonon/phonon/audiooutput.h:51: undefined reference
to `_imp___ZTVN6Phonon11AudioOutputE'
C:\my\cbp/../../Qt/4.7.1/include/phonon/../../src/phonon/../3rdparty/phonon/phonon/audiooutput.h:51: undefined reference
to `_imp___ZN6Phonon19AbstractAudioOutputD2Ev'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\cbp.exe] Error 1
mingw32-make[1]: Leaving directory `C:/my/cbp'
mingw32-make: *** [debug] Error 2


i even tried to write

const QString foo = argv[1];
maybe there is another way to make such program...
help me please!:(

aya_lawliet
8th March 2011, 13:00
and i shall answer my own question, such a noob :D i finally found the answer after a lot of googling..

i did not include phonon in the .pro file..

this solved my problem:

QT += network xml webkit phonon

you only have to include the things you need.

@make i hope this will help you too :)