• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Stellarium / stellarium / 9624594036

22 Jun 2024 09:48AM UTC coverage: 12.209%. First build
9624594036

Pull #3775

github

gzotti
Silence video sound on Qt5.
This may not circumvent problems with missing hardware,
just make sure no sound emits the speakers.
Pull Request #3775: Allow disabling StelAudioMgr at runtime

0 of 61 new or added lines in 3 files covered. (0.0%)

14429 of 118188 relevant lines covered (12.21%)

18945.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/core/StelAudioMgr.cpp
1
/*
2
 * Copyright (C) 2008 Matthew Gates
3
 *
4
 * This program is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU General Public License
6
 * as published by the Free Software Foundation; either version 2
7
 * of the License, or (at your option) any later version.
8
 *
9
 * This program 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 this program; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
17
 */
18

19
#include "StelAudioMgr.hpp"
20
#include <QDebug>
21
#include <QDir>
22

23
#ifdef ENABLE_MEDIA
24

25
#include <QMediaPlayer>
26

NEW
27
StelAudioMgr::StelAudioMgr(bool enable): enabled(enable)
×
28
{
29
#if (QT_VERSION>=QT_VERSION_CHECK(6,0,0))
NEW
30
        audioOutput=(enabled ? new QAudioOutput() : nullptr);
×
31
#endif
32
}
×
33

34
StelAudioMgr::~StelAudioMgr()
×
35
{
36
        QMutableMapIterator<QString, QMediaPlayer*>it(audioObjects);
×
37
        while (it.hasNext())
×
38
        {
39
                it.next();
×
NEW
40
                if (it.value()!=nullptr)
×
41
                {
42
                        it.value()->stop();
×
43
                        it.remove();
×
44
                }
45
        }
46
#if (QT_VERSION>=QT_VERSION_CHECK(6,0,0))
47
        delete audioOutput;
×
NEW
48
        audioOutput=nullptr;
×
49
#endif
50
}
×
51

52
void StelAudioMgr::loadSound(const QString& filename, const QString& id)
×
53
{
NEW
54
        if (!enabled)
×
55
        {
NEW
56
                qWarning() << "Not loading sound -- audio system disabled by configuration.";
×
NEW
57
                return;
×
58
        }
59

60
        if (audioObjects.contains(id))
×
61
        {
62
                qWarning() << "Audio object with ID" << id << "already exists, dropping it";
×
63
                dropSound(id);
×
64
        }
65

66
        QMediaPlayer* sound = new QMediaPlayer();
×
67
        QString path = QFileInfo(filename).absoluteFilePath();
×
68
#if (QT_VERSION>=QT_VERSION_CHECK(6,0,0))
69
        sound->setSource(QUrl::fromLocalFile(path));
×
70
#else
71
        sound->setMedia(QMediaContent(QUrl::fromLocalFile(path)));
72
#endif
73
        audioObjects[id] = sound;
×
74
}
×
75

76
void StelAudioMgr::playSound(const QString& id)
×
77
{
NEW
78
        if (!enabled)
×
NEW
79
                return;
×
80

81
        if (audioObjects.contains(id))
×
82
        {
NEW
83
                if (audioObjects[id]!=nullptr)
×
84
                {
85
                        // if already playing, stop and play from the start
86
                        #if (QT_VERSION>=QT_VERSION_CHECK(6,0,0))
87
                        audioObjects[id]->setAudioOutput(audioOutput);
×
88
                        if (audioObjects[id]->playbackState()==QMediaPlayer::PlayingState)
×
89
                        #else
90
                        if (audioObjects[id]->state()==QMediaPlayer::PlayingState)
91
                        #endif
92
                                audioObjects[id]->stop();
×
93

94
                        // otherwise just play it
95
                        audioObjects[id]->play();
×
96
                }
97
                else
98
                        qDebug() << "StelAudioMgr: Cannot play sound, " << id << "not correctly loaded.";
×
99
        }
100
        else
101
                qDebug() << "StelAudioMgr: Cannot play sound, " << id << "not loaded.";
×
102
}
103

104
void StelAudioMgr::pauseSound(const QString& id)
×
105
{
NEW
106
        if (!enabled)
×
NEW
107
                return;
×
108

109
        if (audioObjects.contains(id))
×
110
        {
NEW
111
                if (audioObjects[id]!=nullptr)
×
112
                        audioObjects[id]->pause();
×
113
                else
114
                        qDebug() << "StelAudioMgr: Cannot pause sound, " << id << "not correctly loaded.";
×
115
        }
116
        else
117
                qDebug() << "StelAudioMgr: Cannot pause sound, " << id << "not loaded.";
×
118
}
119

120
void StelAudioMgr::stopSound(const QString& id)
×
121
{
NEW
122
        if (!enabled)
×
NEW
123
                return;
×
124

125
        if (audioObjects.contains(id))
×
126
        {
NEW
127
                if (audioObjects[id]!=nullptr)
×
128
                        audioObjects[id]->stop();
×
129
                else
130
                        qDebug() << "StelAudioMgr: Cannot stop sound, " << id << "not correctly loaded.";
×
131
        }
132
        else
133
                qDebug() << "StelAudioMgr: Cannot stop sound, " << id << "not loaded.";
×
134
}
135

136
void StelAudioMgr::dropSound(const QString& id)
×
137
{
NEW
138
        if (!enabled)
×
NEW
139
                return;
×
140

141
        if (!audioObjects.contains(id))
×
142
        {
143
                qDebug() << "StelAudioMgr: Cannot drop sound, " << id << "not loaded.";
×
144
                return;
×
145
        }
NEW
146
        if (audioObjects[id]!=nullptr)
×
147
        {
148
                audioObjects[id]->stop();
×
149
                delete audioObjects[id];
×
150
                audioObjects.remove(id);
×
151
        }
152
}
153

154

155
qint64 StelAudioMgr::position(const QString& id)
×
156
{
NEW
157
        if (!enabled)
×
NEW
158
                return -1;
×
159

160
        if (!audioObjects.contains(id))
×
161
        {
162
                qDebug() << "StelAudioMgr: Cannot report position for sound, " << id << "not loaded.";
×
163
                return(-1);
×
164
        }
NEW
165
        if (audioObjects[id]!=nullptr)
×
166
        {
167
                return audioObjects[id]->position();
×
168
        }
169
        return (-1);
×
170
}
171

172
qint64 StelAudioMgr::duration(const QString& id)
×
173
{
NEW
174
        if (!enabled)
×
NEW
175
                return -1;
×
176

177
        if (!audioObjects.contains(id))
×
178
        {
179
                qDebug() << "StelAudioMgr: Cannot report duration for sound, " << id << "not loaded.";
×
180
                return(-1);
×
181
        }
NEW
182
        if (audioObjects[id]!=nullptr)
×
183
        {
184
                return audioObjects[id]->duration();
×
185
        }
186
        return (-1);
×
187
}
188

189
#else 
190
void StelAudioMgr::loadSound(const QString& filename, const QString& id)
191
{
192
        qWarning() << "This build of Stellarium does not support sound - cannot load audio" << QDir::toNativeSeparators(filename) << id;
193
}
194
StelAudioMgr::StelAudioMgr(bool){}
195
StelAudioMgr::~StelAudioMgr() {;}
196
void StelAudioMgr::playSound(const QString&) {;}
197
void StelAudioMgr::pauseSound(const QString&) {;}
198
void StelAudioMgr::stopSound(const QString&) {;}
199
void StelAudioMgr::dropSound(const QString&) {;}
200
qint64 StelAudioMgr::position(const QString&){return -1;}
201
qint64 StelAudioMgr::duration(const QString&){return -1;}
202
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc