Stellarium 0.15.0
1 /*
2  * Copyright (C) 2012 Sibi Antony (Phonon/QT4 implementation)
3  * Copyright (C) 2015 Georg Zotti (Reactivated with QT5 classes)
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
23 #include <QObject>
24 #include <QMap>
25 #include <QString>
26 #ifdef ENABLE_MEDIA
27 #include <QSize>
28 #include <QSizeF>
29 #include <QPoint>
30 #include <QPointF>
31 #include <QMediaContent>
32 #include <QMediaPlayer>
33 #include "StelFader.hpp"
34 #endif
35 #include "StelModule.hpp"
37 class QGraphicsVideoItem;
96 class StelVideoMgr : public StelModule
97 {
100 public:
101  StelVideoMgr();
102  ~StelVideoMgr();
104 public slots:
106  // Methods from StelModule: only update() needed.
107  virtual void init(){;} // Or do something?
111  virtual void update(double deltaTime);
119  void loadVideo(const QString& filename, const QString& id, const float x, const float y, const bool show, const float alpha);
121  void playVideo(const QString& id, const bool keepVisibleAtEnd=false);
136  void playVideoPopout(const QString& id, float fromX, float fromY, float atCenterX, float atCenterY, float finalSizeX, float finalSizeY, float popupDuration, bool frozenInTransition);
140  void pauseVideo(const QString& id);
143  void stopVideo(const QString& id);
146  void dropVideo(const QString& id);
150  void seekVideo(const QString& id, const qint64 ms, bool pause=false);
154  void setVideoXY(const QString& id, const float x, const float y, const bool relative=false);
160  void setVideoAlpha(const QString& id, const float alpha);
169  void resizeVideo(const QString& id, float w = -1.0f, float h = -1.0f);
174  void showVideo(const QString& id, const bool show);
178  qint64 getVideoDuration(const QString& id);
182  qint64 getVideoPosition(const QString& id);
185  QSize getVideoResolution(const QString& id);
187  int getVideoWidth(const QString& id);
189  int getVideoHeight(const QString& id);
193  void muteVideo(const QString& id, bool muteVideo=true);
195  void setVideoVolume(const QString& id, int newVolume);
197  int getVideoVolume(const QString& id);
202  bool isVideoPlaying(const QString& id);
204 #ifdef ENABLE_MEDIA
205 private slots:
206  // Slots to handle QMediaPlayer signals. Never call them yourself!
207  // Some of them are useful to understand media handling and to get to crucial information like native resolution and duration during loading of media.
208  // Most only give simple debug output...
209  void handleAudioAvailableChanged(bool available);
210  void handleBufferStatusChanged(int percentFilled);
211  void handleDurationChanged(qint64 duration);
212  void handleError(QMediaPlayer::Error error);
213  void handleMediaStatusChanged(QMediaPlayer::MediaStatus status);
214  void handleMutedChanged(bool muted);
215  //void handlePositionChanged(qint64 position); // periodically notify where in the video we are. Could be used to update scale bars, not needed.
216  void handleSeekableChanged(bool seekable);
217  void handleStateChanged(QMediaPlayer::State state);
218  void handleVideoAvailableChanged(bool videoAvailable);
219  void handleVolumeChanged(int volume);
221  // Slots to handle QMediaPlayer change signals inherited from QMediaObject:
222  void handleAvailabilityChanged(bool available);
223  void handleAvailabilityChanged(QMultimedia::AvailabilityStatus availability);
225  void handleMetaDataChanged();
226  // This signal is not triggered on Windows, we must work around using handleMetaDataChanged()
227  //void handleMetaDataChanged(const QString & key, const QVariant & value);
228 #endif
231 private:
232 #if 0
233  // Traces of old Qt4/Phonon:
234  typedef struct {
235  QWidget *widget;
236  Phonon::VideoPlayer *player;
237  QGraphicsProxyWidget *pWidget;
238  } VideoPlayer;
239  QMap<QString, VideoPlayer*> videoObjects;
240 #endif
241 #ifdef ENABLE_MEDIA
242  typedef struct {
243  //QVideoWidget *widget; // would be easiest, but only with QtQuick2...
244  QGraphicsVideoItem *videoItem;
245  QMediaPlayer *player;
246  qint64 duration;
247  QSize resolution;
248  bool keepVisible;
249  bool needResize;
250  bool simplePlay;
251  LinearFader fader;
252  QSizeF targetFrameSize;
253  QPointF popupOrigin;
254  QPointF popupTargetCenter;
255  int lastPos;
256  } VideoPlayer;
257  QMap<QString, VideoPlayer*> videoObjects;
258  bool verbose;
259 #endif
260 };
262 #endif // _STELVIDEOMGR_HPP_
bool isVideoPlaying(const QString &id)
returns whether video is currently playing.
void setVideoXY(const QString &id, const float x, const float y, const bool relative=false)
move upper left corner of video id to x, y.
A scriptable way to show videos embedded in the screen.
int getVideoHeight(const QString &id)
returns native height (in pixels) of loaded video, or -1 in case of trouble.
Implementation of StelFader which implements a linear transition.
Definition: StelFader.hpp:77
int getVideoVolume(const QString &id)
return currently set volume (0..100) of media player, or -1 in case of some error.
void dropVideo(const QString &id)
Unload video from memory.
qint64 getVideoDuration(const QString &id)
returns duration (in milliseconds) of loaded video.
void setVideoVolume(const QString &id, int newVolume)
set volume for video. Valid values are 0..100, values outside this range will be clamped.
void resizeVideo(const QString &id, float w=-1.0f, float h=-1.0f)
set video size to width w and height h.
void muteVideo(const QString &id, bool muteVideo=true)
set mute state of video player
void seekVideo(const QString &id, const qint64 ms, bool pause=false)
Seek a position in video id.
void playVideo(const QString &id, const bool keepVisibleAtEnd=false)
play video from current position. If keepLastFrame is true, video pauses at last frame.
int getVideoWidth(const QString &id)
returns native width (in pixels) of loaded video, or -1 in case of trouble.
qint64 getVideoPosition(const QString &id)
returns current position (in milliseconds) of loaded video.
void setVideoAlpha(const QString &id, const float alpha)
sets opacity
virtual void update(double deltaTime)
Update the module with respect to the time.
void stopVideo(const QString &id)
Stop playing, resets video and hides video output window.
void loadVideo(const QString &filename, const QString &id, const float x, const float y, const bool show, const float alpha)
load a video from filename, assign an id for it for later reference.
void playVideoPopout(const QString &id, float fromX, float fromY, float atCenterX, float atCenterY, float finalSizeX, float finalSizeY, float popupDuration, bool frozenInTransition)
Play a video which has previously been loaded with loadVideo() with a complex effect.
void pauseVideo(const QString &id)
Pause video, keep it visible on-screen.
QSize getVideoResolution(const QString &id)
returns resolution (in pixels) of loaded video. Returned value may be invalid before video has been f...
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
void showVideo(const QString &id, const bool show)
show or hide video player