Merge lp:~stellarium/stellarium/video-playback into lp:stellarium
- video-playback
- Merge into trunk
Proposed by
Alexander Wolf
Status: | Merged |
---|---|
Merged at revision: | 5374 |
Proposed branch: | lp:~stellarium/stellarium/video-playback |
Merge into: | lp:stellarium |
Diff against target: |
555 lines (+437/-0) 8 files modified
scripts/tests/videotest.ssc (+19/-0) src/CMakeLists.txt (+3/-0) src/core/StelApp.cpp (+4/-0) src/core/StelApp.hpp (+7/-0) src/core/StelVideoMgr.cpp (+197/-0) src/core/StelVideoMgr.hpp (+65/-0) src/scripting/StelMainScriptAPI.cpp (+74/-0) src/scripting/StelMainScriptAPI.hpp (+68/-0) |
To merge this branch: | bzr merge lp:~stellarium/stellarium/video-playback |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alexander Wolf | Approve | ||
Bogdan Marinov | Pending | ||
treaves | Pending | ||
Matthew Gates | Pending | ||
gzotti | Pending | ||
Review via email: mp+104440@code.launchpad.net |
This proposal supersedes a proposal from 2012-04-13.
Commit message
Description of the change
Sibi Antony are add the video playback feature
To post a comment you must log in.
Revision history for this message
Alexander Wolf (alexwolf) wrote : Posted in a previous version of this proposal | # |
review:
Approve
Revision history for this message
treaves (treaves) wrote : Posted in a previous version of this proposal | # |
All conditional statements need to use braces.
review:
Needs Fixing
Revision history for this message
Alexander Wolf (alexwolf) : | # |
review:
Approve
- 5296. By Alexander Wolf
-
sync with trunk
- 5297. By Alexander Wolf
-
drop videotest.flv file
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file 'scripts/tests/videotest.ssc' | |||
2 | --- scripts/tests/videotest.ssc 1970-01-01 00:00:00 +0000 | |||
3 | +++ scripts/tests/videotest.ssc 2012-06-02 18:10:26 +0000 | |||
4 | @@ -0,0 +1,19 @@ | |||
5 | 1 | // Name: Video Test | ||
6 | 2 | // Author: Alexander Wolf | ||
7 | 3 | // License: Public Domain | ||
8 | 4 | // Description: This script plays several formats of video file. | ||
9 | 5 | // Note that video support is a build-time option and | ||
10 | 6 | // may not be supported for the version of Stellarium | ||
11 | 7 | // which you have. Also, different playforms may | ||
12 | 8 | // support different video formats. | ||
13 | 9 | // | ||
14 | 10 | |||
15 | 11 | core.loadVideo("tests/videotest.flv", "flv", 100, 70, true, 0.5); | ||
16 | 12 | |||
17 | 13 | lab = LabelMgr.labelScreen("Playing video file...", 100, 20, true, 20, "#ff0000"); | ||
18 | 14 | core.playVideo("flv"); | ||
19 | 15 | core.wait(182); | ||
20 | 16 | LabelMgr.deleteLabel(lab); | ||
21 | 17 | core.wait(0.4); | ||
22 | 18 | |||
23 | 19 | core.dropVideo("flv"); | ||
24 | 0 | 20 | ||
25 | === modified file 'src/CMakeLists.txt' | |||
26 | --- src/CMakeLists.txt 2012-04-24 14:53:02 +0000 | |||
27 | +++ src/CMakeLists.txt 2012-06-02 18:10:26 +0000 | |||
28 | @@ -38,6 +38,8 @@ | |||
29 | 38 | SET(stellarium_lib_SRCS | 38 | SET(stellarium_lib_SRCS |
30 | 39 | core/StelAudioMgr.hpp | 39 | core/StelAudioMgr.hpp |
31 | 40 | core/StelAudioMgr.cpp | 40 | core/StelAudioMgr.cpp |
32 | 41 | core/StelVideoMgr.hpp | ||
33 | 42 | core/StelVideoMgr.cpp | ||
34 | 41 | core/StelGeodesicGrid.cpp | 43 | core/StelGeodesicGrid.cpp |
35 | 42 | core/StelGeodesicGrid.hpp | 44 | core/StelGeodesicGrid.hpp |
36 | 43 | core/StelMovementMgr.cpp | 45 | core/StelMovementMgr.cpp |
37 | @@ -335,6 +337,7 @@ | |||
38 | 335 | # that is, all the headers with SIGNAL/SLOTS/PLUGIN_INTERFACE etc.. | 337 | # that is, all the headers with SIGNAL/SLOTS/PLUGIN_INTERFACE etc.. |
39 | 336 | SET(stellarium_MOC_HDRS | 338 | SET(stellarium_MOC_HDRS |
40 | 337 | core/StelAudioMgr.hpp | 339 | core/StelAudioMgr.hpp |
41 | 340 | core/StelVideoMgr.hpp | ||
42 | 338 | core/StelModuleMgr.hpp | 341 | core/StelModuleMgr.hpp |
43 | 339 | core/StelObjectMgr.hpp | 342 | core/StelObjectMgr.hpp |
44 | 340 | core/StelObserver.hpp | 343 | core/StelObserver.hpp |
45 | 341 | 344 | ||
46 | === modified file 'src/core/StelApp.cpp' | |||
47 | --- src/core/StelApp.cpp 2012-03-22 06:18:01 +0000 | |||
48 | +++ src/core/StelApp.cpp 2012-06-02 18:10:26 +0000 | |||
49 | @@ -44,6 +44,7 @@ | |||
50 | 44 | #include "StelJsonParser.hpp" | 44 | #include "StelJsonParser.hpp" |
51 | 45 | #include "StelSkyLayerMgr.hpp" | 45 | #include "StelSkyLayerMgr.hpp" |
52 | 46 | #include "StelAudioMgr.hpp" | 46 | #include "StelAudioMgr.hpp" |
53 | 47 | #include "StelVideoMgr.hpp" | ||
54 | 47 | #include "StelGuiBase.hpp" | 48 | #include "StelGuiBase.hpp" |
55 | 48 | #include "StelPainter.hpp" | 49 | #include "StelPainter.hpp" |
56 | 49 | 50 | ||
57 | @@ -292,6 +293,9 @@ | |||
58 | 292 | // Init audio manager | 293 | // Init audio manager |
59 | 293 | audioMgr = new StelAudioMgr(); | 294 | audioMgr = new StelAudioMgr(); |
60 | 294 | 295 | ||
61 | 296 | // Init video manager | ||
62 | 297 | videoMgr = new StelVideoMgr(); | ||
63 | 298 | |||
64 | 295 | // Constellations | 299 | // Constellations |
65 | 296 | ConstellationMgr* asterisms = new ConstellationMgr(hip_stars); | 300 | ConstellationMgr* asterisms = new ConstellationMgr(hip_stars); |
66 | 297 | asterisms->init(); | 301 | asterisms->init(); |
67 | 298 | 302 | ||
68 | === modified file 'src/core/StelApp.hpp' | |||
69 | --- src/core/StelApp.hpp 2012-02-17 18:12:37 +0000 | |||
70 | +++ src/core/StelApp.hpp 2012-06-02 18:10:26 +0000 | |||
71 | @@ -38,6 +38,7 @@ | |||
72 | 38 | class StelLocationMgr; | 38 | class StelLocationMgr; |
73 | 39 | class StelSkyLayerMgr; | 39 | class StelSkyLayerMgr; |
74 | 40 | class StelAudioMgr; | 40 | class StelAudioMgr; |
75 | 41 | class StelVideoMgr; | ||
76 | 41 | class StelGuiBase; | 42 | class StelGuiBase; |
77 | 42 | 43 | ||
78 | 43 | //! @class StelApp | 44 | //! @class StelApp |
79 | @@ -109,6 +110,9 @@ | |||
80 | 109 | //! Get the audio manager | 110 | //! Get the audio manager |
81 | 110 | StelAudioMgr* getStelAudioMgr() {return audioMgr;} | 111 | StelAudioMgr* getStelAudioMgr() {return audioMgr;} |
82 | 111 | 112 | ||
83 | 113 | //! Get the video manager | ||
84 | 114 | StelVideoMgr* getStelVideoMgr() {return videoMgr;} | ||
85 | 115 | |||
86 | 112 | //! Get the core of the program. | 116 | //! Get the core of the program. |
87 | 113 | //! It is the one which provide the projection, navigation and tone converter. | 117 | //! It is the one which provide the projection, navigation and tone converter. |
88 | 114 | //! @return the StelCore instance of the program | 118 | //! @return the StelCore instance of the program |
89 | @@ -226,6 +230,9 @@ | |||
90 | 226 | // The audio manager. Must execute in the main thread. | 230 | // The audio manager. Must execute in the main thread. |
91 | 227 | StelAudioMgr* audioMgr; | 231 | StelAudioMgr* audioMgr; |
92 | 228 | 232 | ||
93 | 233 | // The video manager. Must execute in the main thread. | ||
94 | 234 | StelVideoMgr* videoMgr; | ||
95 | 235 | |||
96 | 229 | StelSkyLayerMgr* skyImageMgr; | 236 | StelSkyLayerMgr* skyImageMgr; |
97 | 230 | 237 | ||
98 | 231 | StelGuiBase* stelGui; | 238 | StelGuiBase* stelGui; |
99 | 232 | 239 | ||
100 | === added file 'src/core/StelVideoMgr.cpp' | |||
101 | --- src/core/StelVideoMgr.cpp 1970-01-01 00:00:00 +0000 | |||
102 | +++ src/core/StelVideoMgr.cpp 2012-06-02 18:10:26 +0000 | |||
103 | @@ -0,0 +1,197 @@ | |||
104 | 1 | /* | ||
105 | 2 | * Copyright (C) 2012 Sibi Antony | ||
106 | 3 | * | ||
107 | 4 | * This program is free software; you can redistribute it and/or | ||
108 | 5 | * modify it under the terms of the GNU General Public License | ||
109 | 6 | * as published by the Free Software Foundation; either version 2 | ||
110 | 7 | * of the License, or (at your option) any later version. | ||
111 | 8 | * | ||
112 | 9 | * This program is distributed in the hope that it will be useful, | ||
113 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
114 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
115 | 12 | * GNU General Public License for more details. | ||
116 | 13 | * | ||
117 | 14 | * You should have received a copy of the GNU General Public License | ||
118 | 15 | * along with this program; if not, write to the Free Software | ||
119 | 16 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. | ||
120 | 17 | */ | ||
121 | 18 | |||
122 | 19 | #include "StelVideoMgr.hpp" | ||
123 | 20 | #include "StelMainGraphicsView.hpp" | ||
124 | 21 | #include <QDebug> | ||
125 | 22 | |||
126 | 23 | |||
127 | 24 | StelVideoMgr::StelVideoMgr() | ||
128 | 25 | { | ||
129 | 26 | } | ||
130 | 27 | |||
131 | 28 | #ifdef HAVE_QT_PHONON | ||
132 | 29 | StelVideoMgr::~StelVideoMgr() | ||
133 | 30 | { | ||
134 | 31 | foreach(QString id, videoObjects.keys()) | ||
135 | 32 | { | ||
136 | 33 | dropVideo(id); | ||
137 | 34 | } | ||
138 | 35 | } | ||
139 | 36 | |||
140 | 37 | void StelVideoMgr::loadVideo(const QString& filename, const QString& id, float x, float y, bool show, float alpha) | ||
141 | 38 | { | ||
142 | 39 | if (videoObjects.contains(id)) | ||
143 | 40 | { | ||
144 | 41 | qWarning() << "[StelVideoMgr] Video object with ID" << id << "already exists, dropping it"; | ||
145 | 42 | dropVideo(id); | ||
146 | 43 | } | ||
147 | 44 | |||
148 | 45 | videoObjects[id] = new VideoPlayer; | ||
149 | 46 | videoObjects[id]->widget = new QWidget(); | ||
150 | 47 | videoObjects[id]->player = new Phonon::VideoPlayer(Phonon::VideoCategory, videoObjects[id]->widget); | ||
151 | 48 | |||
152 | 49 | videoObjects[id]->player->load(Phonon::MediaSource(filename)); | ||
153 | 50 | videoObjects[id]->pWidget = | ||
154 | 51 | StelMainGraphicsView::getInstance().scene()->addWidget(videoObjects[id]->widget, Qt::FramelessWindowHint); | ||
155 | 52 | |||
156 | 53 | videoObjects[id]->pWidget->setPos(x, y); | ||
157 | 54 | videoObjects[id]->pWidget->setOpacity(alpha); | ||
158 | 55 | videoObjects[id]->pWidget->setVisible(show); | ||
159 | 56 | videoObjects[id]->player->show(); | ||
160 | 57 | |||
161 | 58 | } | ||
162 | 59 | |||
163 | 60 | void StelVideoMgr::playVideo(const QString& id) | ||
164 | 61 | { | ||
165 | 62 | if (videoObjects.contains(id)) | ||
166 | 63 | { | ||
167 | 64 | if (videoObjects[id]->player!=NULL) | ||
168 | 65 | { | ||
169 | 66 | // if already playing, stop and play from the start | ||
170 | 67 | if (videoObjects[id]->player->isPlaying() == true) | ||
171 | 68 | { | ||
172 | 69 | videoObjects[id]->player->stop(); | ||
173 | 70 | } | ||
174 | 71 | |||
175 | 72 | // otherwise just play it | ||
176 | 73 | videoObjects[id]->player->play(); | ||
177 | 74 | } | ||
178 | 75 | } | ||
179 | 76 | } | ||
180 | 77 | |||
181 | 78 | void StelVideoMgr::pauseVideo(const QString& id) | ||
182 | 79 | { | ||
183 | 80 | if (videoObjects.contains(id)) | ||
184 | 81 | { | ||
185 | 82 | if (videoObjects[id]->player!=NULL) | ||
186 | 83 | { | ||
187 | 84 | videoObjects[id]->player->pause(); | ||
188 | 85 | } | ||
189 | 86 | } | ||
190 | 87 | } | ||
191 | 88 | |||
192 | 89 | void StelVideoMgr::stopVideo(const QString& id) | ||
193 | 90 | { | ||
194 | 91 | if (videoObjects.contains(id)) | ||
195 | 92 | { | ||
196 | 93 | if (videoObjects[id]->player!=NULL) | ||
197 | 94 | { | ||
198 | 95 | videoObjects[id]->player->stop(); | ||
199 | 96 | } | ||
200 | 97 | } | ||
201 | 98 | } | ||
202 | 99 | |||
203 | 100 | void StelVideoMgr::seekVideo(const QString& id, qint64 ms) | ||
204 | 101 | { | ||
205 | 102 | if (videoObjects.contains(id)) | ||
206 | 103 | { | ||
207 | 104 | if (videoObjects[id]->player!=NULL) | ||
208 | 105 | { | ||
209 | 106 | if (videoObjects[id]->player->mediaObject()->isSeekable()) | ||
210 | 107 | { | ||
211 | 108 | videoObjects[id]->player->seek(ms); | ||
212 | 109 | // Seek capability depends on the backend used. | ||
213 | 110 | } | ||
214 | 111 | else | ||
215 | 112 | { | ||
216 | 113 | qDebug() << "[StelVideoMgr] Cannot seek media source."; | ||
217 | 114 | } | ||
218 | 115 | } | ||
219 | 116 | } | ||
220 | 117 | } | ||
221 | 118 | |||
222 | 119 | void StelVideoMgr::dropVideo(const QString& id) | ||
223 | 120 | { | ||
224 | 121 | if (!videoObjects.contains(id)) | ||
225 | 122 | return; | ||
226 | 123 | if (videoObjects[id]->player!=NULL) | ||
227 | 124 | { | ||
228 | 125 | videoObjects[id]->player->stop(); | ||
229 | 126 | delete videoObjects[id]->player; | ||
230 | 127 | delete videoObjects[id]->pWidget; | ||
231 | 128 | delete videoObjects[id]; | ||
232 | 129 | |||
233 | 130 | videoObjects.remove(id); | ||
234 | 131 | } | ||
235 | 132 | } | ||
236 | 133 | |||
237 | 134 | void StelVideoMgr::setVideoXY(const QString& id, float x, float y) | ||
238 | 135 | { | ||
239 | 136 | if (videoObjects.contains(id)) | ||
240 | 137 | { | ||
241 | 138 | if (videoObjects[id]->pWidget!=NULL) | ||
242 | 139 | { | ||
243 | 140 | videoObjects[id]->pWidget->setPos(x, y); | ||
244 | 141 | } | ||
245 | 142 | } | ||
246 | 143 | |||
247 | 144 | } | ||
248 | 145 | |||
249 | 146 | void StelVideoMgr::setVideoAlpha(const QString& id, float alpha) | ||
250 | 147 | { | ||
251 | 148 | if (videoObjects.contains(id)) | ||
252 | 149 | { | ||
253 | 150 | if (videoObjects[id]->pWidget!=NULL) | ||
254 | 151 | { | ||
255 | 152 | videoObjects[id]->pWidget->setOpacity(alpha); | ||
256 | 153 | } | ||
257 | 154 | } | ||
258 | 155 | } | ||
259 | 156 | |||
260 | 157 | void StelVideoMgr::resizeVideo(const QString& id, float w, float h) | ||
261 | 158 | { | ||
262 | 159 | if (videoObjects.contains(id)) | ||
263 | 160 | { | ||
264 | 161 | if (videoObjects[id]->pWidget!=NULL) | ||
265 | 162 | { | ||
266 | 163 | videoObjects[id]->pWidget->resize(w, h); | ||
267 | 164 | videoObjects[id]->player->resize(w, h); | ||
268 | 165 | } | ||
269 | 166 | } | ||
270 | 167 | } | ||
271 | 168 | |||
272 | 169 | void StelVideoMgr::showVideo(const QString& id, bool show) | ||
273 | 170 | { | ||
274 | 171 | if (videoObjects.contains(id)) | ||
275 | 172 | { | ||
276 | 173 | if (videoObjects[id]->pWidget!=NULL) | ||
277 | 174 | { | ||
278 | 175 | videoObjects[id]->pWidget->setVisible(show); | ||
279 | 176 | } | ||
280 | 177 | } | ||
281 | 178 | } | ||
282 | 179 | |||
283 | 180 | #else // HAVE_QT_PHONON | ||
284 | 181 | void StelVideoMgr::loadVideo(const QString& filename, const QString& id, float x, float y, bool show, float alpha) | ||
285 | 182 | { | ||
286 | 183 | qWarning() << "[StelVideoMgr] This build of Stellarium does not support video - cannot load video" << filename << id << x << y << show << alpha; | ||
287 | 184 | } | ||
288 | 185 | StelVideoMgr::~StelVideoMgr() {;} | ||
289 | 186 | void StelVideoMgr::playVideo(const QString&) {;} | ||
290 | 187 | void StelVideoMgr::pauseVideo(const QString&) {;} | ||
291 | 188 | void StelVideoMgr::stopVideo(const QString&) {;} | ||
292 | 189 | void StelVideoMgr::dropVideo(const QString&) {;} | ||
293 | 190 | void StelVideoMgr::seekVideo(const QString&, qint64) {;} | ||
294 | 191 | void StelVideoMgr::setVideoXY(const QString&, float, float) {;} | ||
295 | 192 | void StelVideoMgr::setVideoAlpha(const QString&, float) {;} | ||
296 | 193 | void StelVideoMgr::resizeVideo(const QString&, float, float) {;} | ||
297 | 194 | void StelVideoMgr::showVideo(const QString&, bool) {;} | ||
298 | 195 | #endif // HAVE_QT_PHONON | ||
299 | 196 | |||
300 | 197 | |||
301 | 0 | 198 | ||
302 | === added file 'src/core/StelVideoMgr.hpp' | |||
303 | --- src/core/StelVideoMgr.hpp 1970-01-01 00:00:00 +0000 | |||
304 | +++ src/core/StelVideoMgr.hpp 2012-06-02 18:10:26 +0000 | |||
305 | @@ -0,0 +1,65 @@ | |||
306 | 1 | /* | ||
307 | 2 | * Copyright (C) 2012 Sibi Antony | ||
308 | 3 | * | ||
309 | 4 | * This program is free software; you can redistribute it and/or | ||
310 | 5 | * modify it under the terms of the GNU General Public License | ||
311 | 6 | * as published by the Free Software Foundation; either version 2 | ||
312 | 7 | * of the License, or (at your option) any later version. | ||
313 | 8 | * | ||
314 | 9 | * This program is distributed in the hope that it will be useful, | ||
315 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
316 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
317 | 12 | * GNU General Public License for more details. | ||
318 | 13 | * | ||
319 | 14 | * You should have received a copy of the GNU General Public License | ||
320 | 15 | * along with this program; if not, write to the Free Software | ||
321 | 16 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. | ||
322 | 17 | */ | ||
323 | 18 | |||
324 | 19 | #ifndef _STELVIDEOMGR_HPP_ | ||
325 | 20 | #define _STELVIDEOMGR_HPP_ | ||
326 | 21 | |||
327 | 22 | #ifdef HAVE_QT_PHONON | ||
328 | 23 | #include <phonon/videoplayer.h> | ||
329 | 24 | #include <phonon/videowidget.h> | ||
330 | 25 | #include <phonon/mediaobject.h> | ||
331 | 26 | #endif | ||
332 | 27 | |||
333 | 28 | #include <QObject> | ||
334 | 29 | #include <QMap> | ||
335 | 30 | #include <QString> | ||
336 | 31 | #include <QGraphicsProxyWidget> | ||
337 | 32 | |||
338 | 33 | class StelVideoMgr : public QObject | ||
339 | 34 | { | ||
340 | 35 | Q_OBJECT | ||
341 | 36 | |||
342 | 37 | public: | ||
343 | 38 | StelVideoMgr(); | ||
344 | 39 | ~StelVideoMgr(); | ||
345 | 40 | |||
346 | 41 | public slots: | ||
347 | 42 | void loadVideo(const QString& filename, const QString& id, float x, float y, bool show, float alpha); | ||
348 | 43 | void playVideo(const QString& id); | ||
349 | 44 | void pauseVideo(const QString& id); | ||
350 | 45 | void stopVideo(const QString& id); | ||
351 | 46 | void dropVideo(const QString& id); | ||
352 | 47 | void seekVideo(const QString& id, qint64 ms); | ||
353 | 48 | void setVideoXY(const QString& id, float x, float y); | ||
354 | 49 | void setVideoAlpha(const QString& id, float alpha); | ||
355 | 50 | void resizeVideo(const QString& id, float w, float h); | ||
356 | 51 | void showVideo(const QString& id, bool show); | ||
357 | 52 | |||
358 | 53 | private: | ||
359 | 54 | #ifdef HAVE_QT_PHONON | ||
360 | 55 | typedef struct { | ||
361 | 56 | QWidget *widget; | ||
362 | 57 | Phonon::VideoPlayer *player; | ||
363 | 58 | QGraphicsProxyWidget *pWidget; | ||
364 | 59 | } VideoPlayer; | ||
365 | 60 | QMap<QString, VideoPlayer*> videoObjects; | ||
366 | 61 | #endif | ||
367 | 62 | |||
368 | 63 | }; | ||
369 | 64 | |||
370 | 65 | #endif // _STELVIDEOMGR_HPP_ | ||
371 | 0 | 66 | ||
372 | === modified file 'src/scripting/StelMainScriptAPI.cpp' | |||
373 | --- src/scripting/StelMainScriptAPI.cpp 2012-02-20 06:15:32 +0000 | |||
374 | +++ src/scripting/StelMainScriptAPI.cpp 2012-06-02 18:10:26 +0000 | |||
375 | @@ -33,6 +33,7 @@ | |||
376 | 33 | #include "StarMgr.hpp" | 33 | #include "StarMgr.hpp" |
377 | 34 | #include "StelApp.hpp" | 34 | #include "StelApp.hpp" |
378 | 35 | #include "StelAudioMgr.hpp" | 35 | #include "StelAudioMgr.hpp" |
379 | 36 | #include "StelVideoMgr.hpp" | ||
380 | 36 | #include "StelCore.hpp" | 37 | #include "StelCore.hpp" |
381 | 37 | #include "StelFileMgr.hpp" | 38 | #include "StelFileMgr.hpp" |
382 | 38 | #include "StelLocation.hpp" | 39 | #include "StelLocation.hpp" |
383 | @@ -76,6 +77,18 @@ | |||
384 | 76 | connect(this, SIGNAL(requestPauseSound(const QString&)), StelApp::getInstance().getStelAudioMgr(), SLOT(pauseSound(const QString&))); | 77 | connect(this, SIGNAL(requestPauseSound(const QString&)), StelApp::getInstance().getStelAudioMgr(), SLOT(pauseSound(const QString&))); |
385 | 77 | connect(this, SIGNAL(requestStopSound(const QString&)), StelApp::getInstance().getStelAudioMgr(), SLOT(stopSound(const QString&))); | 78 | connect(this, SIGNAL(requestStopSound(const QString&)), StelApp::getInstance().getStelAudioMgr(), SLOT(stopSound(const QString&))); |
386 | 78 | connect(this, SIGNAL(requestDropSound(const QString&)), StelApp::getInstance().getStelAudioMgr(), SLOT(dropSound(const QString&))); | 79 | connect(this, SIGNAL(requestDropSound(const QString&)), StelApp::getInstance().getStelAudioMgr(), SLOT(dropSound(const QString&))); |
387 | 80 | |||
388 | 81 | connect(this, SIGNAL(requestLoadVideo(const QString&, const QString&, float, float, bool, float)), StelApp::getInstance().getStelVideoMgr(), SLOT(loadVideo(const QString&, const QString&, float, float, bool, float))); | ||
389 | 82 | connect(this, SIGNAL(requestPlayVideo(const QString&)), StelApp::getInstance().getStelVideoMgr(), SLOT(playVideo(const QString&))); | ||
390 | 83 | connect(this, SIGNAL(requestPauseVideo(const QString&)), StelApp::getInstance().getStelVideoMgr(), SLOT(pauseVideo(const QString&))); | ||
391 | 84 | connect(this, SIGNAL(requestStopVideo(const QString&)), StelApp::getInstance().getStelVideoMgr(), SLOT(stopVideo(const QString&))); | ||
392 | 85 | connect(this, SIGNAL(requestDropVideo(const QString&)), StelApp::getInstance().getStelVideoMgr(), SLOT(dropVideo(const QString&))); | ||
393 | 86 | connect(this, SIGNAL(requestSeekVideo(const QString&, qint64)), StelApp::getInstance().getStelVideoMgr(), SLOT(seekVideo(const QString&, qint64))); | ||
394 | 87 | connect(this, SIGNAL(requestSetVideoXY(const QString&, float, float)), StelApp::getInstance().getStelVideoMgr(), SLOT(setVideoXY(const QString&, float, float))); | ||
395 | 88 | connect(this, SIGNAL(requestSetVideoAlpha(const QString&, float)), StelApp::getInstance().getStelVideoMgr(), SLOT(setVideoAlpha(const QString&, float))); | ||
396 | 89 | connect(this, SIGNAL(requestResizeVideo(const QString&, float, float)), StelApp::getInstance().getStelVideoMgr(), SLOT(resizeVideo(const QString&, float, float))); | ||
397 | 90 | connect(this, SIGNAL(requestShowVideo(const QString&, bool)), StelApp::getInstance().getStelVideoMgr(), SLOT(showVideo(const QString&, bool))); | ||
398 | 91 | |||
399 | 79 | connect(this, SIGNAL(requestExit()), this->parent(), SLOT(stopScript())); | 92 | connect(this, SIGNAL(requestExit()), this->parent(), SLOT(stopScript())); |
400 | 80 | connect(this, SIGNAL(requestSetNightMode(bool)), &StelApp::getInstance(), SLOT(setVisionModeNight(bool))); | 93 | connect(this, SIGNAL(requestSetNightMode(bool)), &StelApp::getInstance(), SLOT(setVisionModeNight(bool))); |
401 | 81 | connect(this, SIGNAL(requestSetProjectionMode(QString)), StelApp::getInstance().getCore(), SLOT(setCurrentProjectionTypeKey(QString))); | 94 | connect(this, SIGNAL(requestSetProjectionMode(QString)), StelApp::getInstance().getCore(), SLOT(setCurrentProjectionTypeKey(QString))); |
402 | @@ -385,6 +398,67 @@ | |||
403 | 385 | emit(requestDropSound(id)); | 398 | emit(requestDropSound(id)); |
404 | 386 | } | 399 | } |
405 | 387 | 400 | ||
406 | 401 | void StelMainScriptAPI::loadVideo(const QString& filename, const QString& id, float x, float y, bool show, float alpha) | ||
407 | 402 | { | ||
408 | 403 | QString path; | ||
409 | 404 | try | ||
410 | 405 | { | ||
411 | 406 | path = StelFileMgr::findFile("scripts/" + filename); | ||
412 | 407 | } | ||
413 | 408 | catch(std::runtime_error& e) | ||
414 | 409 | { | ||
415 | 410 | qWarning() << "cannot play video" << filename << ":" << e.what(); | ||
416 | 411 | return; | ||
417 | 412 | } | ||
418 | 413 | |||
419 | 414 | emit(requestLoadVideo(path, id, x, y, show, alpha)); | ||
420 | 415 | } | ||
421 | 416 | |||
422 | 417 | void StelMainScriptAPI::playVideo(const QString& id) | ||
423 | 418 | { | ||
424 | 419 | emit(requestPlayVideo(id)); | ||
425 | 420 | } | ||
426 | 421 | |||
427 | 422 | void StelMainScriptAPI::pauseVideo(const QString& id) | ||
428 | 423 | { | ||
429 | 424 | emit(requestPauseVideo(id)); | ||
430 | 425 | } | ||
431 | 426 | |||
432 | 427 | void StelMainScriptAPI::stopVideo(const QString& id) | ||
433 | 428 | { | ||
434 | 429 | emit(requestStopVideo(id)); | ||
435 | 430 | } | ||
436 | 431 | |||
437 | 432 | void StelMainScriptAPI::dropVideo(const QString& id) | ||
438 | 433 | { | ||
439 | 434 | emit(requestDropVideo(id)); | ||
440 | 435 | } | ||
441 | 436 | |||
442 | 437 | void StelMainScriptAPI::seekVideo(const QString& id, qint64 ms) | ||
443 | 438 | { | ||
444 | 439 | emit(requestSeekVideo(id, ms)); | ||
445 | 440 | } | ||
446 | 441 | |||
447 | 442 | void StelMainScriptAPI::setVideoXY(const QString& id, float x, float y) | ||
448 | 443 | { | ||
449 | 444 | emit(requestSetVideoXY(id, x, y)); | ||
450 | 445 | } | ||
451 | 446 | |||
452 | 447 | void StelMainScriptAPI::setVideoAlpha(const QString& id, float alpha) | ||
453 | 448 | { | ||
454 | 449 | emit(requestSetVideoAlpha(id, alpha)); | ||
455 | 450 | } | ||
456 | 451 | |||
457 | 452 | void StelMainScriptAPI::resizeVideo(const QString& id, float w, float h) | ||
458 | 453 | { | ||
459 | 454 | emit(requestResizeVideo(id, w, h)); | ||
460 | 455 | } | ||
461 | 456 | |||
462 | 457 | void StelMainScriptAPI::showVideo(const QString& id, bool show) | ||
463 | 458 | { | ||
464 | 459 | emit(requestShowVideo(id, show)); | ||
465 | 460 | } | ||
466 | 461 | |||
467 | 388 | int StelMainScriptAPI::getScreenWidth() | 462 | int StelMainScriptAPI::getScreenWidth() |
468 | 389 | { | 463 | { |
469 | 390 | return StelMainGraphicsView::getInstance().size().width(); | 464 | return StelMainGraphicsView::getInstance().size().width(); |
470 | 391 | 465 | ||
471 | === modified file 'src/scripting/StelMainScriptAPI.hpp' | |||
472 | --- src/scripting/StelMainScriptAPI.hpp 2012-01-11 10:50:37 +0000 | |||
473 | +++ src/scripting/StelMainScriptAPI.hpp 2012-06-02 18:10:26 +0000 | |||
474 | @@ -386,6 +386,63 @@ | |||
475 | 386 | //! @param id the identifier used when loadSound was called | 386 | //! @param id the identifier used when loadSound was called |
476 | 387 | void dropSound(const QString& id); | 387 | void dropSound(const QString& id); |
477 | 388 | 388 | ||
478 | 389 | //! Load a video from a file. | ||
479 | 390 | //! @param filename the name of the file to load. | ||
480 | 391 | //! @param id the identifier which will be used to refer to the video | ||
481 | 392 | //! when calling playVideo, pauseVideo, stopVideo and dropVideo. | ||
482 | 393 | //! @param x the x-coordinate for the video widget. | ||
483 | 394 | //! @param y the y-coordinate for the video widget. | ||
484 | 395 | //! @param show the visibility state for the video. | ||
485 | 396 | //! @param alpha the initial alpha value of the video. | ||
486 | 397 | void loadVideo(const QString& filename, const QString& id, float x, float y, bool show, float alpha); | ||
487 | 398 | |||
488 | 399 | //! Play a video which has previously been loaded with loadVideo | ||
489 | 400 | //! @param id the identifier used when loadVideo was called | ||
490 | 401 | void playVideo(const QString& id); | ||
491 | 402 | |||
492 | 403 | //! Pause a video which is playing. Subsequent playVideo calls will | ||
493 | 404 | //! resume playing from the position in the file when it was paused. | ||
494 | 405 | //! @param id the identifier used when loadVideo was called | ||
495 | 406 | void pauseVideo(const QString& id); | ||
496 | 407 | |||
497 | 408 | //! Stop a video from playing. This resets the position in the | ||
498 | 409 | //! video to the start so that subsequent playVideo calls will | ||
499 | 410 | //! start from the beginning. | ||
500 | 411 | //! @param id the identifier used when loadVideo was called | ||
501 | 412 | void stopVideo(const QString& id); | ||
502 | 413 | |||
503 | 414 | //! Drop a video from memory. You should do this before the end | ||
504 | 415 | //! of your script. | ||
505 | 416 | //! @param id the identifier used when loadVideo was called | ||
506 | 417 | void dropVideo(const QString& id); | ||
507 | 418 | |||
508 | 419 | //! Seeks a video to the requested time. | ||
509 | 420 | //! @param id the identifier used when loadVideo was called | ||
510 | 421 | //! @param ms the time in milliseconds from the start of the media. | ||
511 | 422 | void seekVideo(const QString& id, qint64 ms); | ||
512 | 423 | |||
513 | 424 | //! Sets the position of the video widget. | ||
514 | 425 | //! @param id the identifier used when loadVideo was called | ||
515 | 426 | //! @param x the new x-coordinate for the video. | ||
516 | 427 | //! @param y the new y-coordinate for the video. | ||
517 | 428 | void setVideoXY(const QString& id, float x, float y); | ||
518 | 429 | |||
519 | 430 | //! Set the alpha value of a video when visible. | ||
520 | 431 | //! @param id the identifier used when loadVideo was called | ||
521 | 432 | //! @param alpha the new alpha value to set. | ||
522 | 433 | void setVideoAlpha(const QString& id, float alpha); | ||
523 | 434 | |||
524 | 435 | //! Resize the video widget to the specified width, height. | ||
525 | 436 | //! @param id the identifier used when loadVideo was called | ||
526 | 437 | //! @param w the new width for the widget. | ||
527 | 438 | //! @param h the new height for the widget. | ||
528 | 439 | void resizeVideo(const QString& id, float w, float h); | ||
529 | 440 | |||
530 | 441 | //! Set the visibility state of a video. | ||
531 | 442 | //! @param id the identifier used when loadVideo was called | ||
532 | 443 | //! @param show the new visible state of the video. | ||
533 | 444 | void showVideo(const QString& id, bool show); | ||
534 | 445 | |||
535 | 389 | //! Get the screen width in pixels. | 446 | //! Get the screen width in pixels. |
536 | 390 | //! @return The screen width in pixels | 447 | //! @return The screen width in pixels |
537 | 391 | int getScreenWidth(); | 448 | int getScreenWidth(); |
538 | @@ -452,6 +509,17 @@ | |||
539 | 452 | void requestPauseSound(const QString& id); | 509 | void requestPauseSound(const QString& id); |
540 | 453 | void requestStopSound(const QString& id); | 510 | void requestStopSound(const QString& id); |
541 | 454 | void requestDropSound(const QString& id); | 511 | void requestDropSound(const QString& id); |
542 | 512 | void requestLoadVideo(const QString& filename, const QString& id, float x, float y, bool show, float alpha); | ||
543 | 513 | void requestPlayVideo(const QString& id); | ||
544 | 514 | void requestPauseVideo(const QString& id); | ||
545 | 515 | void requestStopVideo(const QString& id); | ||
546 | 516 | void requestDropVideo(const QString& id); | ||
547 | 517 | void requestSeekVideo(const QString& id, qint64 ms); | ||
548 | 518 | void requestSetVideoXY(const QString& id, float x, float y); | ||
549 | 519 | void requestSetVideoAlpha(const QString& id, float alpha); | ||
550 | 520 | void requestResizeVideo(const QString& id, float w, float h); | ||
551 | 521 | void requestShowVideo(const QString& id, bool show); | ||
552 | 522 | |||
553 | 455 | void requestSetNightMode(bool b); | 523 | void requestSetNightMode(bool b); |
554 | 456 | void requestSetProjectionMode(QString id); | 524 | void requestSetProjectionMode(QString id); |
555 | 457 | void requestSetSkyCulture(QString id); | 525 | void requestSetSkyCulture(QString id); |
I think we can merge this code