Skip to content

VideoResourceDecoder

final class VideoResourceDecoder
Implements: IResourceDecoder, IResourcePlayback
Package: dev.joid.lib.resource.decoder.impl · Module: core · Source: VideoResourceDecoder.java

Plays a video file with FFmpeg, its frames into a texture and its sound through the audio bridge.

VideoResourceFormat picks it for MP4, Matroska and AVI files. The first decode waits for the FFmpeg natives (VideoNatives); a video that is not a plain file, inside a jar, a stream or a URL, is copied into the video area of the cache folder first. Frames are decoded ahead on a thread of their own and shown at the time of the JOID clock; the sound plays when an audio bridge is registered, otherwise the video plays silent, without a warning; an audio bridge that cannot create the source prints one warning and the video plays silent. Get it from Resource.getPlayback and cast it to set the sound; each fork of the same file plays on its own.

ReturnsSignatureSummary
VideoResourceDecodercreate(File file) factoryCreates a decoder of the video file.
VideoResourceDecodercreate(Asset asset) factoryCreates a decoder of the video asset.

PropertyTypeDefaultSummary
loopbooleanfalseIf true, the video starts again at the end.
autoplaybooleantrueIf true, the video starts once its first frame is uploaded.
volumefloat1FThe volume of the sound, on 1; 0F mutes it.
audioGroupObjectnullThe group of the audio source, which the audio bridge can use to set the volume of every sound of a group at once; null for none.
referenceDistancefloat5FWith a location, the distance from the listener under which the sound plays at full volume.
maxDistancefloat50FWith a location, the distance from the listener at which the sound fades out completely; in between, the volume falls as (1 − t)², t going from 0 to 1 between the two distances.

ReturnsSignatureSummary
booleanisSettled()If true, the frame shown is the one the current time asks for, so that a capture of the screen is stable.
booleanisPaused()If true, the video is paused.
booleanisPlaying()If true, the video is running and not paused.
doublegetProgress()Returns the frame shown on 1 of the frame count.
doublegetCurrentTime()Returns the time of the frame shown, in seconds.
AssetgetAsset()Returns the video file.
intgetDisplayedFrameIndex()Returns the index of the frame shown.
intgetVideoWidth()Returns the width of the video, in pixels, 0 before the decode.
intgetVideoHeight()Returns the height of the video, in pixels, 0 before the decode.
intgetTotalFrames()Returns the number of frames of the video.
doublegetDuration()Returns the length of the video, in seconds.
doublegetFrameRate()Returns the frame rate of the video, 30 when the file does not give one.
PointgetLocation()Returns the position of the sound, or null for a sound that does not depend on the listener.
ReturnsSignatureSummary
voidprepare(ResourceData resource)Gives the data two placeholder textures until the first frame is uploaded.
voiddecode(ResourceData resource)Waits for the natives, opens the video, reads its size, rate and length and decodes its first frame.
voidupload(ResourceData resource)Uploads the first frame and starts the playback when autoplay is true or play() was called before the end of the decode.
voidclear(ResourceData resource)Releases the decoder, the sound and the textures.
VideoResourceDecoderfork()Returns a decoder of the same file that plays on its own.
thisplay() fluentStarts the video from the start, or from the time of a seek made while stopped, or resumes it after pause().
thisstop() fluentStops the video and its sound; the next play() starts from the start.
thispause() fluentPauses the video and its sound on the current frame.
thisseek(double seconds) fluentMoves the video to seconds from the start; on a stopped video, it pauses there, and play() resumes from there.
thislocation(float x, float y, float z) fluentPlaces the sound at x, y, z, so that its volume depends on the distance to the listener given by VideoAudioPlayer.audioListenerPosition.
voidrelease()Stops the decoding thread and frees the FFmpeg decoder and the sound; the next play() opens the file again.
Inherited from IResourceDecoder (1)

isMipmappable

Inherited from IResourcePlayback (1)

restart

VideoResourceDecoder create(File file) factory

Creates a decoder of the video file.

VideoResourceDecoder create(Asset asset) factory

Creates a decoder of the video asset.

  • this loop(boolean loop) fluent
  • boolean isLoop()

Default: false

If true, the video starts again at the end.

  • this autoplay(boolean autoplay) fluent
  • boolean isAutoplay()

Default: true

If true, the video starts once its first frame is uploaded.

  • this volume(float volume) fluent
  • float getVolume()

Default: 1F

The volume of the sound, on 1; 0F mutes it.

  • this audioGroup(Object audioGroup) fluent
  • Object getAudioGroup()

Default: null

The group of the audio source, which the audio bridge can use to set the volume of every sound of a group at once; null for none.

  • this referenceDistance(float distance) fluent
  • float getReferenceDistance()

Default: 5F

With a location, the distance from the listener under which the sound plays at full volume.

  • this maxDistance(float distance) fluent
  • float getMaxDistance()

Default: 50F

With a location, the distance from the listener at which the sound fades out completely; in between, the volume falls as (1 − t)², t going from 0 to 1 between the two distances.

boolean isSettled()

If true, the frame shown is the one the current time asks for, so that a capture of the screen is stable.

boolean isPaused()

If true, the video is paused.

boolean isPlaying()

If true, the video is running and not paused.

double getProgress()

Returns the frame shown on 1 of the frame count.

double getCurrentTime()

Returns the time of the frame shown, in seconds.

Asset getAsset()

Returns the video file.

int getDisplayedFrameIndex()

Returns the index of the frame shown.

int getVideoWidth()

Returns the width of the video, in pixels, 0 before the decode.

int getVideoHeight()

Returns the height of the video, in pixels, 0 before the decode.

int getTotalFrames()

Returns the number of frames of the video.

double getDuration()

Returns the length of the video, in seconds.

double getFrameRate()

Returns the frame rate of the video, 30 when the file does not give one.

Point getLocation()

Returns the position of the sound, or null for a sound that does not depend on the listener.

void prepare(ResourceData resource)

Gives the data two placeholder textures until the first frame is uploaded.

void decode(ResourceData resource)

Throws:

  • UncheckedIOException: The video … cannot be read
  • IllegalStateException: The video … cannot be decoded

Waits for the natives, opens the video, reads its size, rate and length and decodes its first frame. Throws the exception of the natives when they cannot be installed, UncheckedIOException when the video cannot be read or copied, and IllegalStateException when it cannot be decoded.

void upload(ResourceData resource)

Uploads the first frame and starts the playback when autoplay is true or play() was called before the end of the decode.

void clear(ResourceData resource)

Releases the decoder, the sound and the textures.

VideoResourceDecoder fork()

Returns a decoder of the same file that plays on its own.

this play() fluent

Starts the video from the start, or from the time of a seek made while stopped, or resumes it after pause(). Called before the decode ends, it starts the video once the first frame is uploaded.

this stop() fluent

Stops the video and its sound; the next play() starts from the start.

this pause() fluent

Pauses the video and its sound on the current frame.

this seek(double seconds) fluent

Moves the video to seconds from the start; on a stopped video, it pauses there, and play() resumes from there.

this location(float x, float y, float z) fluent

Places the sound at x, y, z, so that its volume depends on the distance to the listener given by VideoAudioPlayer.audioListenerPosition.

void release()

Stops the decoding thread and frees the FFmpeg decoder and the sound; the next play() opens the file again.


fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses

Report a problem with this page