This page has been translated automatically.
Programming
Fundamentials
Setting Up Development Environment
UnigineScript
High-Level Systems
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Core Library
Containers
Engine Classes
Node-Related Classes
Rendering-Related Classes
Physics-Related Classes
Bounds-Related Classes
Controls-Related Classes
Pathfinding-Related Classes
Utility Classes
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

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.
    Notice
    There can be a small pause between deletion of the old widget and creation of a new one.
    The following example demonstrates implementation of the described method:
    Source code(UnigineScript)
    #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

Members


WidgetSpriteVideo (const Ptr<Gui> & gui, const char * name = 0, int mode = 1)

Constructor. Creates a new sprite that plays video.

Arguments

  • const Ptr<Gui> & gui - GUI, to which the new sprite will belong.
  • const char * name - Path to a video file.
  • int mode - YUV flag: 1 if convertion to RGB should be performed by the GPU, 0 - if by the CPU.

int getLoop ()

Returns a value indicating if the video is looped.

Return value

Positive number if the video is looped; otherwise, 0.

void setSoundSource (const Ptr<SoundSource> & source)

Synchronizes video playback to the sound source playback.

Arguments

  • const Ptr<SoundSource> & source - Sound source according to which video playback will be synchronized.

void stop ()

Stops playing video. This function saves the playback position so that playing of the file can be resumed from the same point.

Ptr<SoundSource> getSoundSource ()

Returns the sound source according to which video playback is synchronized.

Return value

Sound source.

Ptr<WidgetSpriteVideo> create (const Ptr<Widget> & widget)

Arguments

  • const Ptr<Widget> & widget

Return value

Ptr<AmbientSource> getAmbientSource ()

Returns the ambient sound source according to which video playback is synchronized.

Return value

Ambient sound source.

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 setVideoTime (float time)

Rewinds or fast-forwards the video to a given time.

Arguments

  • float time - 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.

float getVideoTime ()

Returns the time of the currently played frame.

Return value

Time in seconds.

void play ()

Starts playing video.

void setYUV (int yuv)

Sets a flag for YUV conversion.

Arguments

  • int yuv - Mode flag: 1 if convertion to RGB should be performed by the GPU, 0 if it is converted by the CPU.

void setAmbientSource (const Ptr<AmbientSource> & source)

Synchronizes video playback to the ambient sound source playback.

Arguments

  • const Ptr<AmbientSource> & source - Ambient sound source according to which video playback will be synchronized.

void setLoop (int loop)

Sets a value indicating if the video should be looped.

Arguments

  • int loop - Positive number to loop the video, 0 to play it only once.
Last update: 2017-07-03
Build: ()