2 * This file is part of jSpeed.
4 * jSpeed is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * jSpeed is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
19 #include <QtCore/QUrl>
20 #include <QtCore/QDir>
21 #include <QMediaPlayer>
22 #include <QMediaContent>
23 #include "mediaplayer.h"
28 QString const FORMATS[MediaPlayer::FORMAT_COUNT] = {"mp3", "aac", "wav"};
29 QString const LOCAL_SOUND_DIR = ":/resources/sounds/";
32 void MediaPlayer::init()
37 bool MediaPlayer::play(QString const& file)
39 QMediaPlayer* player = getPlayer();
41 QMediaContent media(QUrl::fromLocalFile(file));
48 player->setMedia(media);
53 QMediaPlayer* MediaPlayer::getPlayer()
55 static QMediaPlayer player;
59 void MediaPlayer::getSupportedFormats(QList<QString>& formats)
63 for(int i = 0; i < FORMAT_COUNT; i++)
65 formats.push_back(FORMATS[i]);
69 QString MediaPlayer::getFormatPattern()
73 for(int i = 0; i < FORMAT_COUNT; i++)
75 result += "*." + FORMATS[i] + " ";
78 return result.trimmed();
81 QStringList MediaPlayer::getFormatPatterns()
85 for(int i = 0; i < FORMAT_COUNT; i++)
87 result.push_back("*." + FORMATS[i]);
93 QString MediaPlayer::getSoundDir()
95 return Settings::getDir() + "sounds" + QDir::separator();
98 QString const& MediaPlayer::getLocalSoundDir()
100 return LOCAL_SOUND_DIR;