Skip to content

VPlayer API

Matthew Ng edited this page Jul 24, 2014 · 6 revisions

Contains

VPlayerView

The VPlayerView is a View object that you can attach to layouts. It has extra commands to control video such as pause, play and seek.

Static Constants

public static final int UNKNOWN_STREAM

Allow the player to pick the first available stream (video, audio and/or subtitle).

public static final int NO_STREAM

Allow the player to not select a video, audio or subtitle stream from video.

Constructor

VPlayerView(Activity activity)

  • Param activity: the activity where you are placing this view

Setters

void setWindowFullscreen()

Makes the current activity fullscreen; removes the actionbar etc.

void clearWindowFullscreen()

Restores the activity's actionbar and goes out of fullscreen

####void setDataSource(String path, String fontPath, String encryptKey, int videoIndex, int audioIndex, int subtitleIndex)

  • Param path: path to the file or url to a video stream
  • Param fontPath: path to a font file (*.ttf); null not use subtitles
  • Param encryptKey: encryption key if the video has encryption, otherwise can set as null
  • Param videoIndex: the video index of the stream to use
  • Param audioIndex: the audio index of the stream to use
  • Param subtitleIndex: the subtitle index of the stream to use

Streams can specify numbers or static members UNKNOWN_STREAM / NO_STREAM.

Note: you can get the metadata of a video and set the stream after from MediaStreamInfo using the VPlayerListener -> onMediaSourceLoaded

void setDataSource(String path, String fontPath, String encryptionKey)

Simple method to just run a video with subtitles with encryption key. It will take the first available stream.

void setDataSource(String path, int videoIndex, int audioIndex)

Simple method to just run a video specifying the video and audio indexes.

void setDataSource(String path, String fontPath)

Simple method to just run a video with subtitles. It will take the first available stream.

void setDataSource(String path)

Simple method to just run a video with no encryption or subtitles. It will take the first available stream.

void setLoop(boolean shouldLoop)

  • Param shouldLoop: set if the video should play again when finished

void setVideoListener(VPlayerListener listener)

  • Param listener: set the event listener to receive video state events

View LifeCycle

void onPause()

Activity should call this function on its onPause() method.

void onResume()

Activity should call this function on its onResume() method.

void finish()

Activity should call this function on its finish() method. You can also use this in other places if not finish(), then it will close the video player and you cannot use it again.

Video Controls

These controls are usable as long as setDataSource is successful and before finish() is called, otherwise these methods are ignored.

void pause()

Pause the video

void seek(long position)

  • Param position: specify the position of playback in seconds

void play()

Play the current video

void stop()

Stops the player and resets the position back to the beginning of the video

Getters

int getVideoWidth()

  • Return: gets the video width once video is loaded (wait for onMediaSourceLoaded event)

int getVideoHeight()

  • Return: gets the video height once video is loaded (wait for onMediaSourceLoaded event)

boolean isPlaying()

  • Return: sees if the video is currently playing

VPlayerListener

This is an abstract class used to get events from VPlayerView.

public void onMediaPause(NotPlayingException err)

  • Param err: an error when pausing

This event happens when pausing is successful

public void onMediaResume(NotPlayingException result)

  • Param result: an error when resuming

This event happens when resuming is successful

public void onMediaSeeked(NotPlayingException result)

  • Param result: an error when seeking

This event happens when seeking is successful

public void onMediaSourceLoaded(VPlayerException err, MediaStreamInfo[] streams)

  • Param err: an error when opening network stream or file and playback will not happen
  • Param streams: returns all the streams (video, audio and subtitle) contained in current video

public void onMediaStop()

Stop has occured

public void onMediaUpdateTime(long currentTime, long totalDuration, boolean isFinished)

  • Param currentTime: current time of the playback
  • Param totalDuration: total number of seconds playing the video
  • Param isFinished: true when video is finished playback

This event occurs every second. You can detect when the video has finished and update a seekbar if you implement one.

Clone this wiki locally