openharmony 鸿蒙 arkts-apis-media-MediaSourceLoadingRequest

2026-08-25 浏览 (1)

Interface (MediaSourceLoadingRequest)

The MediaSourceLoadingRequest class defines a loading request object. Applications use this object to obtain the location of the requested resource and to interact with the player for data exchange.

NOTE

  • The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
  • The initial APIs of this interface are supported since API version 18.

Modules to Import

import { media } from '@kit.MediaKit';

Properties

Atomic service API: This API can be used in atomic services since API version 18.

System capability: SystemCapability.Multimedia.Media.Core

NameTypeRead-OnlyOptionalDescription
urlstringNoNoResource URL, which is the path to the resource that the application needs to open.
headerRecord<string, string>NoYesHTTP request header. If the header exists, the application should set the header information in the HTTP request when downloading data.

respondData18+

respondData(uuid: number, offset: number, buffer: ArrayBuffer): number

Sends data to the player.

Atomic service API: This API can be used in atomic services since API version 18.

System capability: SystemCapability.Multimedia.Media.Core

Parameters

NameTypeMandatoryDescription
uuidnumberYesID for the resource handle. The source is SourceOpenCallback.
offsetnumberYesOffset of the current media data relative to the start of the resource. The value cannot be less than 0.
bufferArrayBufferYesMedia data sent to the player.
Note: Do not transmit irrelevant data, as it can affect normal data parsing and playback.

Return value

TypeDescription
numberNumber of bytes received by the server.
- A return value less than 0 indicates failure.
- A return value of -2 indicates that the player no longer needs the current data, and the client should stop the current read process.
- A return value of -3 indicates that the player's buffer is full, and the client should wait for the next read.

Example

import { HashMap } from '@kit.ArkTS';
let requests: HashMap<number, media.MediaSourceLoadingRequest> = new HashMap();
let uuid = 1;

let request = requests.get(uuid);
let offset = 0; // Offset of the current media data relative to the start of the resource.
let buf = new ArrayBuffer(0); // Data defined by the application and pushed to the player.
let num = request?.respondData(uuid, offset, buf);

respondHeader18+

respondHeader(uuid: number, header?: Record<string, string>, redirectUrl?: string): void

Sends response header information to the player. This API must be called before the first call to respondData.

Atomic service API: This API can be used in atomic services since API version 18.

System capability: SystemCapability.Multimedia.Media.Core

Parameters

NameTypeMandatoryDescription
uuidnumberYesID for the resource handle. The source is SourceOpenCallback.
headerRecord<string, string>NoHeader information in the HTTP response. The application can intersect the header fields with the fields supported by the underlying layer for parsing or directly pass in all corresponding header information.
- The following fields need to be parsed by the underlying player: Transfer-Encoding, Location, Content-Type, Content-Range, Content-Encode, Accept-Ranges, and content-length.
redirectUrlstringNoRedirect URL in the HTTP response.

Example

import { HashMap } from '@kit.ArkTS';
let requests: HashMap<number, media.MediaSourceLoadingRequest> = new HashMap();
let uuid = 1;

// The application fills this in as needed.
let header:Record<string, string> = {
  'Transfer-Encoding':'xxx',
  'Location' : 'xxx',
  'Content-Type' : 'xxx',
  'Content-Range' : 'xxx',
  'Content-Encode' : 'xxx',
  'Accept-Ranges' : 'xxx',
  'content-length' : 'xxx'
};
let request = requests.get(uuid);
request?.respondHeader(uuid, header);

finishLoading18+

finishLoading(uuid: number, state: LoadingRequestError): void

Notifies the player of the current request status. After pushing all the data for a single resource, the application should send the LOADING_ERROR_SUCCESS state to notify the player that the resource push is complete.

Atomic service API: This API can be used in atomic services since API version 18.

System capability: SystemCapability.Multimedia.Media.Core

Parameters

NameTypeMandatoryDescription
uuidnumberYesID for the resource handle. The source is SourceOpenCallback.
stateLoadingRequestErrorYesRequest status.

Example

import { HashMap } from '@kit.ArkTS';

let requests: HashMap<number, media.MediaSourceLoadingRequest> = new HashMap();
let uuid = 1;

let request = requests.get(uuid);
let loadingError = media.LoadingRequestError.LOADING_ERROR_SUCCESS;
request?.finishLoading(uuid, loadingError);

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-avrecorder-oh-avrecorder-range

openharmony 鸿蒙 errorcode-media

openharmony 鸿蒙 capi-avplayer

openharmony 鸿蒙 capi-avplayer-base-h

openharmony 鸿蒙 capi-avimage-generator-h

openharmony 鸿蒙 capi-avscreencapture-oh-rect

openharmony 鸿蒙 capi-videoprocessing-videoprocessing-callback

openharmony 鸿蒙 capi-avsinkbase

openharmony 鸿蒙 capi-avmetadataextractor

openharmony 鸿蒙 capi-avscreencapture-oh-multidisplaycapability

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/b2xUoyIF