Added POI text field. Some tuning to detail screen item position.
[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 <QMediaPlayer>
22 #include <QMediaContent>
23 #include "mediaplayer.h"
24 #include "settings.h"
25
26 namespace
27 {
28     QString const FORMATS[MediaPlayer::FORMAT_COUNT] = {"mp3", "aac", "wav"};
29     QString const LOCAL_SOUND_DIR = ":/resources/sounds/";
30 }
31
32 void MediaPlayer::init()
33 {
34     getPlayer();
35 }
36
37 bool MediaPlayer::play(QString const& file)
38 {
39     QMediaPlayer* player = getPlayer();
40
41     QMediaContent media(QUrl::fromLocalFile(file));
42
43     if(media.isNull())
44     {
45         return false;
46     }
47
48     player->setMedia(media);
49     player->play();
50     return true;
51 }
52
53 QMediaPlayer* MediaPlayer::getPlayer()
54 {
55     static QMediaPlayer player;
56     return &player;
57 }
58
59 void MediaPlayer::getSupportedFormats(QList<QString>& formats)
60 {
61     formats.clear();
62
63     for(int i = 0; i < FORMAT_COUNT; i++)
64     {
65         formats.push_back(FORMATS[i]);
66     }
67 }
68
69 QString MediaPlayer::getFormatPattern()
70 {
71    QString result = "";
72
73    for(int i = 0; i < FORMAT_COUNT; i++)
74    {
75        result += "*." + FORMATS[i] + " ";
76    }
77
78    return result.trimmed();
79 }
80
81 QStringList MediaPlayer::getFormatPatterns()
82 {
83     QStringList result;
84
85     for(int i = 0; i < FORMAT_COUNT; i++)
86     {
87         result.push_back("*." + FORMATS[i]);
88     }
89
90     return result;
91 }
92
93 QString MediaPlayer::getSoundDir()
94 {
95     return Settings::getDir() + "sounds" + QDir::separator();
96 }
97
98 QString const& MediaPlayer::getLocalSoundDir()
99 {
100     return LOCAL_SOUND_DIR;
101 }
102