onSeek

Callback triggered when seeking media resource data.

virtual int64_t onSeek(int64_t offset, int whence) = 0;

This callback is triggered when calling openWithMediaSource or open to open a custom media resource, and is used to request data from a specified position in the media resource.

Parameters

offset
Offset from the starting point to the target position, in bytes. This value can be positive or negative.
whence
Starting point, can be set to one of the following values:
  • 0: Start from the beginning of the data, the actual offset is offset.
  • 1: Start from the current position, the actual offset is the current position plus offset.
  • 2: Start from the end of the data, the actual offset is the total data length plus offset.
  • 65536: Do not perform seek, return the file size. Recommended for pure audio files such as MP3, WAV.

Return Values

  • When whence is 65536, returns the size of the media file.
  • When whence is 0, 1, or 2, returns the actual offset after seeking.
  • -1: Seek failed.