All Classes Namespaces Functions Variables Enumerations Properties Pages
soundplayer.h
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2012-2020 Matthew Chiawen Chang
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; version 2 of the License.
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
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 */
16 
17 #ifndef SOUNDPLAYER_H
18 #define SOUNDPLAYER_H
19 
20 #include <memory>
21 #include <QObject>
22 #include <QBuffer>
23 #include "pencilerror.h"
24 #include "keyframe.h"
25 
26 class SoundClip;
27 class QMediaPlayer;
28 
30 {
31  Q_OBJECT
32 public:
33  SoundPlayer();
34  ~SoundPlayer() override;
35 
36  void init(SoundClip*);
37  void onKeyFrameDestroy(KeyFrame*) override;
38  bool isValid();
39 
40  void play();
41  void pause();
42  void stop();
43 
44  int64_t duration();
45  SoundClip* clip() { return mSoundClip; }
46 
47  void setMediaPlayerPosition(qint64 pos);
48 
49 signals:
50  void corruptedSoundFile(SoundClip*);
51  void durationChanged(SoundPlayer*, int64_t duration);
52 
53 private:
54  void makeConnections();
55 
56  SoundClip* mSoundClip = nullptr;
57  QMediaPlayer* mMediaPlayer = nullptr;
58  QBuffer mBuffer;
59 };
60 
61 #endif // SOUNDPLAYER_H
Q_OBJECTQ_OBJECT