3d091129279ea64f5f1265727021c29afcb6b287
[jspeed] / src / mediaplayer.cpp
1 /*
2  * This file is part of jSpeed.
3  *
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.
8  *
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.
13  *
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/>.
16  *
17  */
18
19 #include <QtCore/QUrl>
20 #include <QtCore/QDir>
21 #include <QMediaContent>
22 #include "mediaplayer.h"
23 #include "settings.h"
24
25 namespace
26 {
27     QString const FORMATS[MediaPlayer::FORMAT_COUNT] = {"mp3", "aac", "wav"};
28     QString const LOCAL_SOUND_DIR = ":/resources/sounds/";
29 }
30
31 QMediaPlayer MediaPlayer::player_;
32
33 bool MediaPlayer::play(QString const& file)
34 {
35     QMediaContent media(QUrl::fromLocalFile(file));
36
37     if(media.isNull())
38     {
39         return false;
40     }
41
42     player_.setMedia(media);
43     player_.play();
44     return true;
45 }
46
47 void MediaPlayer::getSupportedFormats(QList<QString>& formats)
48 {
49     formats.clear();
50
51     for(int i = 0; i < FORMAT_COUNT; i++)
52     {
53         formats.push_back(FORMATS[i]);
54     }
55 }
56
57 QString MediaPlayer::getFormatPattern()
58 {
59    QString result = "";
60
61    for(int i = 0; i < FORMAT_COUNT; i++)
62    {
63        result += "*." + FORMATS[i] + " ";
64    }
65
66    return result.trimmed();
67 }
68
69 QString MediaPlayer::getSoundDir()
70 {
71     return Settings::getDir() + "sounds" + QDir::separator();
72 }
73
74 QString const& MediaPlayer::getLocalSoundDir()
75 {
76     return LOCAL_SOUND_DIR;
77 }
78