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 bool MediaPlayer::play(QString const& file)
34 static QMediaPlayer player;
36 QMediaContent media(QUrl::fromLocalFile(file));
43 player.setMedia(media);
48 void MediaPlayer::getSupportedFormats(QList<QString>& formats)
52 for(int i = 0; i < FORMAT_COUNT; i++)
54 formats.push_back(FORMATS[i]);
58 QString MediaPlayer::getFormatPattern()
62 for(int i = 0; i < FORMAT_COUNT; i++)
64 result += "*." + FORMATS[i] + " ";
67 return result.trimmed();
70 QStringList MediaPlayer::getFormatPatterns()
74 for(int i = 0; i < FORMAT_COUNT; i++)
76 result.push_back("*." + FORMATS[i]);
82 QString MediaPlayer::getSoundDir()
84 return Settings::getDir() + "sounds" + QDir::separator();
87 QString const& MediaPlayer::getLocalSoundDir()
89 return LOCAL_SOUND_DIR;