NAP
videoplayer.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Local Includes
8 #include "videofile.h"
9 #include "video.h"
10 
11 // External Includes
12 #include <nap/device.h>
13 #include <nap/resourceptr.h>
14 #include <nap/numeric.h>
15 #include <texture.h>
16 
17 namespace nap
18 {
19  // Forward Declares
20  class VideoService;
21 
58  class NAPAPI VideoPlayer : public Device
59  {
60  RTTI_ENABLE(Device)
61  friend class VideoService;
62  public:
63 
64  // Constructor
65  VideoPlayer(VideoService& service);
66 
70  const VideoFile& getFile() const;
71 
75  const Video& getVideo() const;
76 
80  Video& getVideo();
81 
85  int getIndex() const { return mCurrentVideoIndex; }
86 
90  int getCount() const { return static_cast<int>(mVideos.size()); }
91 
112  bool selectVideo(int index, utility::ErrorState& error);
113 
119  void play(double startTime = 0.0, bool clearTextures = true);
120 
124  void stopPlayback() { getVideo().stop(true); }
125 
130  bool isPlaying() const { return getVideo().isPlaying(); }
131 
136  void loop(bool value);
137 
141  bool isLooping() const { return mLoop; }
142 
147  void setSpeed(float speed);
148 
152  float getSpeed() const { return mSpeed; }
153 
158  void seek(double seconds) { getVideo().seek(seconds); }
159 
163  double getCurrentTime() const { return getVideo().getCurrentTime(); }
164 
168  double getDuration() const { return getVideo().getDuration(); }
169 
173  int getWidth() const { return getVideo().getWidth(); }
174 
178  int getHeight() const { return getVideo().getHeight(); }
179 
183  bool hasAudio() const { return getVideo().hasAudio(); }
184 
190  virtual bool start(utility::ErrorState& errorState) override;
191 
195  virtual void stop() override;
196 
200  bool hasSelection() const { return mCurrentVideo != nullptr; }
201 
208  Texture2D& getYTexture();
209 
216  Texture2D& getUTexture();
217 
224  Texture2D& getVTexture();
225 
226  std::vector<nap::ResourcePtr<VideoFile>> mVideoFiles;
227  nap::uint mVideoIndex = 0;
228  bool mLoop = false;
229  float mSpeed = 1.0f;
230 
235 
236  private:
240  void update(double deltaTime);
241 
245  void clearTextures();
246 
247  int mCurrentVideoIndex = 0;
248  nap::Video* mCurrentVideo = nullptr;
249  bool mTexturesCreated = false;
250  std::vector<std::unique_ptr<nap::Video>> mVideos;
251  std::unique_ptr<Texture2D> mYTexture;
252  std::unique_ptr<Texture2D> mUTexture;
253  std::unique_ptr<Texture2D> mVTexture;
254  VideoService& mService;
255  };
256 
257  // Object creator used for constructing the the OSC receiver
259 }
nap::uint
unsigned int uint
Definition: numeric.h:23
nap::VideoService
Definition: videoservice.h:19
nap::VideoPlayer::hasSelection
bool hasSelection() const
Definition: videoplayer.h:200
nap::VideoPlayer::getHeight
int getHeight() const
Definition: videoplayer.h:178
nap::VideoPlayer::getWidth
int getWidth() const
Definition: videoplayer.h:173
nap::VideoFile
Definition: videofile.h:17
nap::VideoPlayer::hasAudio
bool hasAudio() const
Definition: videoplayer.h:183
nap::VideoPlayer::VideoChanged
nap::Signal< nap::VideoPlayer & > VideoChanged
Definition: videoplayer.h:234
nap::rtti::ObjectCreator
Definition: factory.h:49
nap::Video
Definition: video.h:399
nap::utility::ErrorState
Definition: errorstate.h:19
nap::VideoPlayer::getCurrentTime
double getCurrentTime() const
Definition: videoplayer.h:163
nap::Texture2D
Definition: texture.h:128
nap::Signal< nap::VideoPlayer & >
nap::VideoPlayer::getSpeed
float getSpeed() const
Definition: videoplayer.h:152
nap::VideoPlayer::mVideoFiles
std::vector< nap::ResourcePtr< VideoFile > > mVideoFiles
Property: 'Files' All video file links.
Definition: videoplayer.h:226
nap::VideoPlayer::isLooping
bool isLooping() const
Definition: videoplayer.h:141
nap::VideoPlayer::seek
void seek(double seconds)
Definition: videoplayer.h:158
nap::VideoPlayer
Definition: videoplayer.h:58
nap::VideoPlayer::isPlaying
bool isPlaying() const
Definition: videoplayer.h:130
nap
Definition: templateapp.h:17
nap::VideoPlayer::stopPlayback
void stopPlayback()
Definition: videoplayer.h:124
nap::VideoPlayer::getDuration
double getDuration() const
Definition: videoplayer.h:168
nap::VideoPlayer::getCount
int getCount() const
Definition: videoplayer.h:90
nap::Device
Definition: device.h:20