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 
118  void play(double startTime = 0.0);
119 
123  void stopPlayback() { getVideo().stop(true); }
124 
129  bool isPlaying() const { return getVideo().isPlaying(); }
130 
135  void loop(bool value);
136 
140  bool isLooping() const { return mLoop; }
141 
146  void setSpeed(float speed);
147 
151  float getSpeed() const { return mSpeed; }
152 
157  void seek(double seconds) { getVideo().seek(seconds); }
158 
162  double getCurrentTime() const { return getVideo().getCurrentTime(); }
163 
167  double getDuration() const { return getVideo().getDuration(); }
168 
172  int getWidth() const { return getVideo().getWidth(); }
173 
177  int getHeight() const { return getVideo().getHeight(); }
178 
182  bool hasAudio() const { return getVideo().hasAudio(); }
183 
189  virtual bool start(utility::ErrorState& errorState) override;
190 
194  virtual void stop() override;
195 
199  bool hasSelection() const { return mCurrentVideo != nullptr; }
200 
207  Texture2D& getYTexture();
208 
215  Texture2D& getUTexture();
216 
223  Texture2D& getVTexture();
224 
225  std::vector<nap::ResourcePtr<VideoFile>> mVideoFiles;
226  nap::uint mVideoIndex = 0;
227  bool mLoop = false;
228  float mSpeed = 1.0f;
229 
234 
235  private:
239  void update(double deltaTime);
240 
244  void clearTextures();
245 
246  int mCurrentVideoIndex = 0;
247  nap::Video* mCurrentVideo = nullptr;
248  bool mTexturesCreated = false;
249  std::vector<std::unique_ptr<nap::Video>> mVideos;
250  std::unique_ptr<Texture2D> mYTexture;
251  std::unique_ptr<Texture2D> mUTexture;
252  std::unique_ptr<Texture2D> mVTexture;
253  VideoService& mService;
254  };
255 
256  // Object creator used for constructing the the OSC receiver
258 }
nap::uint
unsigned int uint
Definition: numeric.h:23
nap::VideoService
Definition: videoservice.h:19
nap::VideoPlayer::hasSelection
bool hasSelection() const
Definition: videoplayer.h:199
nap::VideoPlayer::getHeight
int getHeight() const
Definition: videoplayer.h:177
nap::VideoPlayer::getWidth
int getWidth() const
Definition: videoplayer.h:172
nap::VideoFile
Definition: videofile.h:17
nap::VideoPlayer::hasAudio
bool hasAudio() const
Definition: videoplayer.h:182
nap::VideoPlayer::VideoChanged
nap::Signal< nap::VideoPlayer & > VideoChanged
Definition: videoplayer.h:233
nap::rtti::ObjectCreator
Definition: factory.h:49
nap::Video
Definition: video.h:400
nap::utility::ErrorState
Definition: errorstate.h:19
nap::VideoPlayer::getCurrentTime
double getCurrentTime() const
Definition: videoplayer.h:162
nap::Texture2D
Definition: texture.h:128
nap::Signal< nap::VideoPlayer & >
nap::VideoPlayer::getSpeed
float getSpeed() const
Definition: videoplayer.h:151
nap::VideoPlayer::mVideoFiles
std::vector< nap::ResourcePtr< VideoFile > > mVideoFiles
Property: 'Files' All video file links.
Definition: videoplayer.h:225
nap::VideoPlayer::isLooping
bool isLooping() const
Definition: videoplayer.h:140
nap::VideoPlayer::seek
void seek(double seconds)
Definition: videoplayer.h:157
nap::VideoPlayer
Definition: videoplayer.h:58
nap::VideoPlayer::isPlaying
bool isPlaying() const
Definition: videoplayer.h:129
nap
Definition: templateapp.h:17
nap::VideoPlayer::stopPlayback
void stopPlayback()
Definition: videoplayer.h:123
nap::VideoPlayer::getDuration
double getDuration() const
Definition: videoplayer.h:167
nap::VideoPlayer::getCount
int getCount() const
Definition: videoplayer.h:90
nap::Device
Definition: device.h:20