WidgetSpriteVideo Class
This class is used to create a virtual monitor that plays a video file. It can be synchrozied with playback of the ambient sound or the directional sound source.
You can replace the current video file with another one in run-time by using one of the following methods:
-
Delete the WidgetSpriteVideo node from the node hierarchy, delete the instance of the WidgetSpriteVideo and create a new instance of the WidgetSpriteVideo in the same place, but with the different path to the required video file.
Then, add the new instance to the node hierarchy.
The following example demonstrates implementation of the described method:There can be a small pause between deletion of the old widget and creation of a new one.
#include <core/unigine.h> /* */ Gui gui; WidgetSpriteVideo sprite_video; /* */ void create_video(string file) { // create an instance of the WidgetSpriteVideo to play a given video file sprite_video = new WidgetSpriteVideo(gui,file); // add the created node to the node hierarchy gui.addChild(sprite_video,GUI_ALIGN_OVERLAP); sprite_video.setLoop(1); sprite_video.play(); } /* */ void destroy_video() { // delete the node from the node hierarchy gui.removeChild(sprite_video); // delete the instance of the WidgetSpriteVideo delete sprite_video; sprite_video = NULL; } /* */ int init() { gui = engine.getGui(); create_video("samples/widgets/videos/unigine.ogv"); thread("update_scene"); return 1; } /* */ void update_scene() { while(true) { sleep(1); // delete the video destroy_video(); // create a new video create_video("samples/widgets/videos/winter.ogv"); } }
- Create a new instance of the WidgetSpriteVideo on the background and disable (and then delete) the old instance of the WidgetSpriteVideo.
The following samples demonstrate the usage of the WidgetSpriteVideo class:
WidgetSpriteVideo Class
This class inherits from WidgetSpriteMembers
WidgetSpriteVideo (Gui gui, string name, int mode = 1)
Constructor. Creates a new sprite that plays video.Arguments
- Gui gui - GUI, to which the new sprite will belong.
- string name - Path to a video file.
- int mode = 1 - YUV flag: 1 if convertion to RGB should be performed by the GPU, 0 - if by the CPU.
AmbientSource getAmbientSource ()
Returns the ambient sound source according to which video playback is synchronized.Return value
Ambient sound source.int getLoop ()
Returns a value indicating if the video is looped.Return value
Positive number if the video is looped; otherwise, 0.SoundSource getSoundSource ()
Returns the sound source according to which video playback is synchronized.Return value
Sound source.float getVideoTime ()
Returns the time of the currently played frame.Return value
Time in seconds.int getYUV ()
Returns a flag for YUV conversion.Return value
1 if convertion to RGB is performed by the GPU, 0 if it is converted by the CPU.int isPlaying ()
Returns a value indicating if the video is being played at the moment.Return value
1 if the video is being played; otherwise, 0.int isStopped ()
Returns a value indicating if the video is stopped at the moment.Return value
1 if the video is stopped; otherwise, 0.void play ()
Starts playing video.void setAmbientSource (AmbientSource source)
Synchronizes video playback to the ambient sound source playback.Arguments
- AmbientSource source - Ambient sound source according to which video playback will be synchronized.
void setLoop (int mode)
Sets a value indicating if the video should be looped.Arguments
- int mode - Positive number to loop the video, 0 to play it only once.
void setSoundSource (SoundSource source)
Synchronizes video playback to the sound source playback.Arguments
- SoundSource source - Sound source according to which video playback will be synchronized.
void setVideoTime (float time)
Rewinds or fast-forwards the video to a given time.Arguments
- float time - Time in seconds.
void setYUV (int mode)
Sets a flag for YUV conversion.Arguments
- int mode - Mode flag: 1 if convertion to RGB should be performed by the GPU, 0 if it is converted by the CPU.
void stop ()
Stops playing video. This function saves the playback position so that playing of the file can be resumed from the same point.Last update: 03.07.2017
Помогите сделать статью лучше
Была ли эта статья полезной?
(или выберите слово/фразу и нажмите Ctrl+Enter