Added Qt Multimedia support in order to replace Phonon. Currently does not work on Mac.

This commit is contained in:
xawotihs
2014-01-26 23:56:15 +01:00
parent aad54fd98d
commit 03d4f8ffa1
4 changed files with 252 additions and 191 deletions
+32 -20
View File
@@ -23,28 +23,32 @@
#include "SLES/OpenSLES_Android.h" #include "SLES/OpenSLES_Android.h"
#elif defined USE_PHONON #elif defined USE_PHONON
#include <phonon/AudioOutput> #include <phonon/AudioOutput>
#include <phonon/MediaObject> #include <phonon/MediaObject>
#elif defined WIN32 #elif defined WIN32
#include <windows.h> #include <windows.h>
#define WITH_FMOD #define WITH_FMOD
#elif defined (PSP) #elif defined (PSP)
#include <pspgu.h> #include <pspgu.h>
#include <pspkernel.h> #include <pspkernel.h>
#include <pspdisplay.h> #include <pspdisplay.h>
#include <pspdebug.h> #include <pspdebug.h>
#include <pspctrl.h> #include <pspctrl.h>
#include <time.h> #include <time.h>
#include <string.h> #include <string.h>
#include <pspaudiolib.h> #include <pspaudiolib.h>
#include <psprtc.h> #include <psprtc.h>
#include "JAudio.h" #include "JAudio.h"
#include "JMP3.h" #include "JMP3.h"
#elif defined QT_CONFIG
#include "QMediaPlayer"
#include "QMediaPlaylist"
#include "QSoundEffect"
#endif #endif
#ifdef WITH_FMOD #ifdef WITH_FMOD
#include "../Dependencies/include/fmod.h" #include "../Dependencies/include/fmod.h"
#endif #endif
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
@@ -67,7 +71,7 @@ public:
#ifdef USE_PHONON #ifdef USE_PHONON
Phonon::AudioOutput* mOutput; Phonon::AudioOutput* mOutput;
Phonon::MediaObject* mMediaObject; Phonon::MediaObject* mMediaObject;
public slots: public slots:
void seekAtTheBegining(); void seekAtTheBegining();
#elif defined (PSP) #elif defined (PSP)
JMP3* mTrack; JMP3* mTrack;
@@ -82,6 +86,10 @@ public:
SLPlayItf playInterface; SLPlayItf playInterface;
SLSeekItf seekInterface; SLSeekItf seekInterface;
SLVolumeItf musicVolumeInterface; SLVolumeItf musicVolumeInterface;
#elif defined QT_CONFIG
QMediaPlaylist* playlist;
QMediaPlayer* player;
string fullpath;
#else #else
void* mTrack; void* mTrack;
#endif //WITH_FMOD #endif //WITH_FMOD
@@ -92,13 +100,15 @@ public:
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
class JSample class JSample
{ {
public: public:
JSample(); JSample();
~JSample(); ~JSample();
unsigned long fileSize(); unsigned long fileSize();
#ifdef QT_CONFIG
#if defined (PSP) QSoundEffect effect;
void* mSample;
#elif defined (PSP)
WAVDATA *mSample; WAVDATA *mSample;
#elif defined (IOS) #elif defined (IOS)
std::string filename; std::string filename;
@@ -242,9 +252,10 @@ protected:
void DestroySoundSystem(); void DestroySoundSystem();
private: private:
#ifdef PSP
JMusic *mCurrentMusic; JMusic *mCurrentMusic;
JSample *mCurrentSample; JSample *mCurrentSample;
#endif
int mVolume; int mVolume;
int mMusicVolume; int mMusicVolume;
@@ -256,3 +267,4 @@ private:
}; };
#endif #endif
+65 -16
View File
@@ -22,6 +22,8 @@
JMusic::JMusic() JMusic::JMusic()
#ifdef USE_PHONON #ifdef USE_PHONON
: mOutput(0), mMediaObject(0) : mOutput(0), mMediaObject(0)
#elif defined QT_CONFIG
: playlist(0), player(0)
#endif #endif
{ {
} }
@@ -40,7 +42,12 @@ int JMusic::getPlayTime(){
JMusic::~JMusic() JMusic::~JMusic()
{ {
#ifdef USE_PHONON #ifdef QT_CONFIG
if(player)
delete player;
if(playlist)
delete playlist;
#elif defined USE_PHONON
if(mOutput) if(mOutput)
delete mOutput; delete mOutput;
if(mMediaObject) if(mMediaObject)
@@ -144,8 +151,20 @@ void JSoundSystem::DestroySoundSystem()
JMusic *JSoundSystem::LoadMusic(const char *fileName) JMusic *JSoundSystem::LoadMusic(const char *fileName)
{ {
#ifdef USE_PHONON JMusic* music = NULL;
JMusic* music = new JMusic(); #ifdef QT_CONFIG
music = new JMusic();
if (music)
{
music->player = new QMediaPlayer;
music->player->setVolume(100);
music->playlist = new QMediaPlaylist;
music->fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName);
music->playlist->addMedia(QUrl(music->fullpath.c_str()));
music->playlist->setCurrentIndex(0);
}
#elif defined USE_PHONON
music = new JMusic();
if (music) if (music)
{ {
music->mOutput = new Phonon::AudioOutput(Phonon::GameCategory, 0); music->mOutput = new Phonon::AudioOutput(Phonon::GameCategory, 0);
@@ -155,9 +174,8 @@ JMusic *JSoundSystem::LoadMusic(const char *fileName)
Phonon::Path mediapath = Phonon::createPath(music->mMediaObject, music->mOutput); Phonon::Path mediapath = Phonon::createPath(music->mMediaObject, music->mOutput);
Q_ASSERT(mediapath.isValid()); Q_ASSERT(mediapath.isValid());
} }
return music;
#elif (defined WITH_FMOD) #elif (defined WITH_FMOD)
JMusic* music = new JMusic(); music = new JMusic();
if (music) if (music)
{ {
JFileSystem* fileSystem = JFileSystem::GetInstance(); JFileSystem* fileSystem = JFileSystem::GetInstance();
@@ -172,17 +190,29 @@ JMusic *JSoundSystem::LoadMusic(const char *fileName)
fileSystem->CloseFile(); fileSystem->CloseFile();
} }
} }
return music;
#else #else
cerr << fileName << endl; cerr << fileName << endl;
return NULL;
#endif #endif
return music;
} }
void JSoundSystem::PlayMusic(JMusic *music, bool looping) void JSoundSystem::PlayMusic(JMusic *music, bool looping)
{ {
#ifdef USE_PHONON #ifdef QT_CONFIG
if(music && music->player && music->playlist)
{
if(looping)
music->playlist->setPlaybackMode(QMediaPlaylist::Loop);
// music->player->setPlaylist(music->playlist);
music->player->setMedia(QUrl(music->fullpath.c_str()));
music->player->play();
stringstream stream;
stream << "Player state : " << music->player->state();
DebugTrace(stream.str());
}
#elif USE_PHONON
if (music && music->mMediaObject && music->mOutput) if (music && music->mMediaObject && music->mOutput)
{ {
if(looping) if(looping)
@@ -213,7 +243,12 @@ void JSoundSystem::PlayMusic(JMusic *music, bool looping)
void JSoundSystem::StopMusic(JMusic *music) void JSoundSystem::StopMusic(JMusic *music)
{ {
#ifdef USE_PHONON #ifdef QT_CONFIG
if (music && music->player && music->playlist)
{
music->player->stop();
}
#elif defined USE_PHONON
if (music && music->mMediaObject && music->mOutput) if (music && music->mMediaObject && music->mOutput)
{ {
music->mMediaObject->stop(); music->mMediaObject->stop();
@@ -264,8 +299,19 @@ void JSoundSystem::SetSfxVolume(int volume){
JSample *JSoundSystem::LoadSample(const char *fileName) JSample *JSoundSystem::LoadSample(const char *fileName)
{ {
#if (defined USE_PHONON) JSample* sample = NULL;
JSample* sample = new JSample(); #ifdef QT_CONFIG
sample = new JSample();
if (sample)
{
string fullpath = JFileSystem::GetInstance()->GetResourceFile(fileName);
sample->effect.setSource(QUrl::fromLocalFile(fullpath.c_str()));
sample->effect.setLoopCount(0);
sample->effect.setVolume(1);
sample->mSample = &(sample->effect);
}
#elif (defined USE_PHONON)
sample = new JSample();
if (sample) if (sample)
{ {
sample->mOutput = new Phonon::AudioOutput(Phonon::GameCategory, 0); sample->mOutput = new Phonon::AudioOutput(Phonon::GameCategory, 0);
@@ -275,9 +321,8 @@ JSample *JSoundSystem::LoadSample(const char *fileName)
Phonon::Path mediapath = Phonon::createPath(sample->mMediaObject, sample->mOutput); Phonon::Path mediapath = Phonon::createPath(sample->mMediaObject, sample->mOutput);
Q_ASSERT(mediapath.isValid()); Q_ASSERT(mediapath.isValid());
} }
return sample;
#elif (defined WITH_FMOD) #elif (defined WITH_FMOD)
JSample* sample = new JSample(); sample = new JSample();
if (sample) if (sample)
{ {
JFileSystem* fileSystem = JFileSystem::GetInstance(); JFileSystem* fileSystem = JFileSystem::GetInstance();
@@ -294,17 +339,21 @@ JSample *JSoundSystem::LoadSample(const char *fileName)
sample->mSample = NULL; sample->mSample = NULL;
} }
return sample;
#else #else
cerr << fileName << endl; cerr << fileName << endl;
return NULL;
#endif #endif
return sample;
} }
void JSoundSystem::PlaySample(JSample *sample) void JSoundSystem::PlaySample(JSample *sample)
{ {
#ifdef USE_PHONON #ifdef QT_CONFIG
if(sample)
{
sample->effect.play();
}
#elif defined USE_PHONON
if (sample && sample->mMediaObject && sample->mOutput) if (sample && sample->mMediaObject && sample->mOutput)
{ {
sample->mOutput->setVolume((qreal)mSampleVolume*0.01); sample->mOutput->setVolume((qreal)mSampleVolume*0.01);
+2 -1
View File
@@ -17,7 +17,7 @@ else:CONFIG(graphics, graphics|console){
folder_01.source = qml/QmlWagic folder_01.source = qml/QmlWagic
folder_01.target = /usr/share folder_01.target = /usr/share
DEPLOYMENTFOLDERS = folder_01 DEPLOYMENTFOLDERS = folder_01
QT += core gui opengl network QT += core gui opengl network multimedia
QT -= declarative quick qml QT -= declarative quick qml
#maemo5:DEFINES += QT_WIDGET #maemo5:DEFINES += QT_WIDGET
DEFINES += QT_WIDGET DEFINES += QT_WIDGET
@@ -46,6 +46,7 @@ CONFIG(graphics, graphics|console){
../../JGE/src/qt/corewrapper.cpp\ ../../JGE/src/qt/corewrapper.cpp\
../../JGE/src/Qtmain.cpp\ ../../JGE/src/Qtmain.cpp\
../../JGE/src/JMD2Model.cpp\ ../../JGE/src/JMD2Model.cpp\
../../JGE/src/pc/JSfx.cpp\
../../JGE/src/pc/JGfx.cpp ../../JGE/src/pc/JGfx.cpp
} }
else:CONFIG(console, graphics|console){ else:CONFIG(console, graphics|console){
-1
View File
@@ -303,7 +303,6 @@ SOURCES += \
../../JGE/src/JSpline.cpp\ ../../JGE/src/JSpline.cpp\
../../JGE/src/JNetwork.cpp\ ../../JGE/src/JNetwork.cpp\
../../JGE/src/pc/JSocket.cpp\ ../../JGE/src/pc/JSocket.cpp\
../../JGE/src/pc/JSfx.cpp\
../../JGE/src/JSprite.cpp\ ../../JGE/src/JSprite.cpp\
../../JGE/src/Vector2D.cpp\ ../../JGE/src/Vector2D.cpp\
../../JGE/src/tinyxml/tinystr.cpp\ ../../JGE/src/tinyxml/tinystr.cpp\