Getting Started with EasyAR
Header:#include "easyar/player.hpp"


VideoPlayer is the class for video playback.

EasyAR supports normal videos, transparent videos and streaming videos. The video contents will be rendered into a texture passed into the player through setRenderTexture.

Public Types

enumStatus{kVideoError, kVideoReady, kVideoCompleted}
enumVideoType{kVideoTypeNormal, kVideoTypeTransparentSideBySide, kVideoTypeTransparentTopAndBottom}

Public Functions

voidsetRenderTexture(int texture)
voidsetVideoType(VideoType videoType)
voidopen(const char* path, StorageType storageType, VideoPlayerCallBack* callback = 0)
boolseek(int position)
boolsetVolume(float volume)

enum VideoPlayer::Status

kVideoError-1Status to indicate something wrong happen in video open or play.
kVideoReady0Status to show video finished open and is ready for play.
kVideoCompleted1Status to indicate video finished play and reached the end.

enum VideoPlayer::VideoType

kVideoTypeNormal0Normal video.
kVideoTypeTransparentSideBySide1Transparent video, left half is the RGB channel and right half is alpha channel.
kVideoTypeTransparentTopAndBottom2Transparent video, top half is the RGB channel and bottom half is alpha channel.


Creates a VideoPlayer object.

virtual ~VideoPlayer()

Destroys the VideoPlayer object.

void setRenderTexture(int texture)

Pass the texture to display video into player. It should be set before open.

void setVideoType(VideoType videoType)

Sets the video type. The type will default to normal video if not set manually. It should be called before open.

void open(const char* path, StorageType storageType, VideoPlayerCallBack* callback = 0)

Opens a video from path.

path can be a local video file (path/to/video.mp4) or url (http://www.../.../video.mp4). storageType indicates the type of path. See StorageType for more descriptions of StorageType.

This method is an async method. Open may take some time to finish. If you want to know the open result or the play status while playing, you have to provide a non-null callback. The callback will be called from a different thread. You can check if the open finished successfully and start play after a successful one.

void close()

Closes the video.

bool play()

Starts or continues to play video.

bool stop()

Stops the video playback.

bool pause()

Pauses the video playback.

void updateFrame()

Updates texture data. This should be called in the renderer thread.

int duration()

Returns the video duration. Use after a successful open.

int currentPosition()

Returns the current position of video. Use after a successful open.

bool seek(int position)

Seek to play to position. Use after a successful open.

Vec2I size()

Returns the video size. Use after a successful open.

float volume()

Returns current volume. Use after a successful open.

bool setVolume(float volume)

Sets volume of the video. Use after a successful open.