openharmony 鸿蒙 arkts-apis-media-VideoPlayer

2026-08-25 浏览 (1)

Deprecated Interface (VideoPlayer, deprecated)

VideoPlayer is a class for video playback management. It provides APIs to manage and play videos. Before calling any API in VideoPlayer, you must use createVideoPlayer() to create a VideoPlayer instance.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer instead.

Modules to Import

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

Properties

System capability: SystemCapability.Multimedia.Media.VideoPlayer

NameTypeRead-OnlyOptionalDescription
url8+stringNoNoVideo URL. The video formats MP4, MPEG-TS, and MKV are supported.
Example of supported URLs:
1. FD: fd://xx

2. HTTP: http://xx
3. HTTPS: https://xx
4. HLS: http://xx or https://xx
5. File type: file://xx
NOTE
WebM is no longer supported since API version 11.
fdSrc9+AVFileDescriptorNoNoDescription of a video file. This property is required when video assets of an application are continuously stored in a file.
Example:
Assume that a music file that stores continuous music assets consists of the following:
Video 1 (address offset: 0, byte length: 100)
Video 2 (address offset: 101; byte length: 50)
Video 3 (address offset: 151, byte length: 150)
1. To play video 1: AVFileDescriptor { fd = resource handle; offset = 0; length = 100; }
2. To play video 2: AVFileDescriptor { fd = resource handle; offset = 101; length = 50; }
3. To play video 3: AVFileDescriptor { fd = resource handle; offset = 151; length = 150; }
To play an independent video file, use src=fd://xx.
loop8+booleanNoNoWhether to loop video playback. true to loop, false otherwise.
videoScaleType9+VideoScaleTypeNoYesVideo scale type. The default value is VIDEO_SCALE_TYPE_FIT.
audioInterruptMode9+audio.InterruptModeNoYesAudio interruption mode.
currentTime8+numberYesNoCurrent video playback position, in ms.
duration8+numberYesNoVideo duration, in ms. The value -1 indicates the live mode.
state8+VideoPlayStateYesNoVideo playback state.
width8+numberYesNoVideo width, in px.
height8+numberYesNoVideo height, in px.

setDisplaySurface(deprecated)

setDisplaySurface(surfaceId: string, callback: AsyncCallback<void>): void

Sets a surface ID. This API uses an asynchronous callback to return the result.

NOTE

  • SetDisplaySurface must be called between the URL setting and the calling of prepare. A surface must be set for video streams without audio. Otherwise, the calling of prepare fails.

  • This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.surfaceId instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
surfaceIdstringYesSurface ID, which is obtained from the XComponent. For details about how to obtain it, see XComponent.
callbackAsyncCallback<void>YesCallback used to return the result. If the setting is successful, err is undefined. Otherwise, err is an error object.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let surfaceId: string = '';
videoPlayer.setDisplaySurface(surfaceId, (err: BusinessError) => {
  if (err) {
    console.error('Failed to set DisplaySurface!');
  } else {
    console.info('Succeeded in setting DisplaySurface!');
  }
});

setDisplaySurface(deprecated)

setDisplaySurface(surfaceId: string): Promise<void>

Sets a surface ID. This API uses a promise to return the result.

NOTE

  • SetDisplaySurface must be called between the URL setting and the calling of prepare. A surface must be set for video streams without audio. Otherwise, the calling of prepare fails.

  • This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.surfaceId instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
surfaceIdstringYesSurface ID, which is obtained from the XComponent. For details about how to obtain it, see XComponent.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let surfaceId: string = '';
videoPlayer.setDisplaySurface(surfaceId).then(() => {
  console.info('Succeeded in setting DisplaySurface');
}).catch((error: BusinessError) => {
  console.error(`video catchCallback, error:${error}`);
});

prepare(deprecated)

prepare(callback: AsyncCallback<void>): void

Prepares for video playback. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.prepare instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<void>YesCallback used to return the result. If the operation is successful, err is undefined; otherwise, err is an error object.

Example

import { BusinessError } from '@kit.BasicServicesKit';

videoPlayer.prepare((err: BusinessError) => {
  if (err) {
    console.error('Failed to prepare!');
  } else {
    console.info('Succeeded in preparing!');
  }
});

prepare(deprecated)

prepare(): Promise<void>

Prepares for video playback. This API uses a promise to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.prepare instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Return value

TypeDescription
Promise<void>Promise that returns no value.

Example

import { BusinessError } from '@kit.BasicServicesKit';

videoPlayer.prepare().then(() => {
  console.info('Succeeded in preparing');
}).catch((error: BusinessError) => {
  console.error(`video catchCallback, error:${error}`);
});

play(deprecated)

play(callback: AsyncCallback<void>): void

Starts video playback. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.play instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<void>YesCallback used to return the result. If the operation is successful, err is undefined; otherwise, err is an error object.

Example

import { BusinessError } from '@kit.BasicServicesKit';

videoPlayer.play((err: BusinessError) => {
  if (err) {
    console.error('Failed to play!');
  } else {
    console.info('Succeeded in playing!');
  }
});

play(deprecated)

play(): Promise<void>

Starts video playback. This API uses a promise to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.play instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Return value

TypeDescription
Promise<void>Promise that returns no value.

Example

import { BusinessError } from '@kit.BasicServicesKit';

videoPlayer.play().then(() => {
  console.info('Succeeded in playing');
}).catch((error: BusinessError) => {
  console.error(`video catchCallback, error:${error}`);
});

pause(deprecated)

pause(callback: AsyncCallback<void>): void

Pauses video playback. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.pause instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<void>YesCallback used to return the result. If the operation is successful, err is undefined; otherwise, err is an error object.

Example

import { BusinessError } from '@kit.BasicServicesKit';

videoPlayer.pause((err: BusinessError) => {
  if (err) {
    console.error('Failed to pause!');
  } else {
    console.info('Succeeded in pausing!');
  }
});

pause(deprecated)

pause(): Promise<void>

Pauses video playback. This API uses a promise to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.pause instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Return value

TypeDescription
Promise<void>Promise that returns no value.

Example

import { BusinessError } from '@kit.BasicServicesKit';

videoPlayer.pause().then(() => {
  console.info('Succeeded in pausing');
}).catch((error: BusinessError) => {
  console.error(`video catchCallback, error:${error}`);
});

stop(deprecated)

stop(callback: AsyncCallback<void>): void

Stops video playback. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.stop instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<void>YesCallback used to return the result. If the operation is successful, err is undefined; otherwise, err is an error object.

Example

import { BusinessError } from '@kit.BasicServicesKit';

videoPlayer.stop((err: BusinessError) => {
  if (err) {
    console.error('Failed to stop!');
  } else {
    console.info('Succeeded in stopping!');
  }
});

stop(deprecated)

stop(): Promise<void>

Stops video playback. This API uses a promise to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.stop instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Return value

TypeDescription
Promise<void>Promise that returns no value.

Example

import { BusinessError } from '@kit.BasicServicesKit';

videoPlayer.stop().then(() => {
  console.info('Succeeded in stopping');
}).catch((error: BusinessError) => {
  console.error(`video catchCallback, error:${error}`);
});

reset(deprecated)

reset(callback: AsyncCallback<void>): void

Resets video playback. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.reset instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<void>YesCallback used to return the result. If the operation is successful, err is undefined; otherwise, err is an error object.

Example

import { BusinessError } from '@kit.BasicServicesKit';

videoPlayer.reset((err: BusinessError) => {
  if (err) {
    console.error('Failed to reset!');
  } else {
    console.info('Succeeded in resetting!');
  }
});

reset(deprecated)

reset(): Promise<void>

Resets video playback. This API uses a promise to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.reset instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Return value

TypeDescription
Promise<void>Promise that returns no value.

Example

import { BusinessError } from '@kit.BasicServicesKit';

videoPlayer.reset().then(() => {
  console.info('Succeeded in resetting');
}).catch((error: BusinessError) => {
  console.error(`video catchCallback, error:${error}`);
});

seek(deprecated)

seek(timeMs: number, callback: AsyncCallback<number>): void

Seeks to the specified playback position. The previous key frame at the specified position is played. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.seek instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
timeMsnumberYesPosition to seek to, in ms. The value range is [0, duration].
callbackAsyncCallback<number>YesCallback used to return the result. If the operation is successful, err is undefined and data is the new playback position; otherwise, err is an error object.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let videoPlayer: media.VideoPlayer;
media.createVideoPlayer((error: BusinessError, video: media.VideoPlayer) => {
  if (video != null) {
    videoPlayer = video;
    console.info('Succeeded in creating VideoPlayer');
  } else {
    console.error(`Failed to create VideoPlayer, error:${error}`);
  }
});

let seekTime: number = 5000;
videoPlayer.seek(seekTime, (err: BusinessError, result: number) => {
  if (err) {
    console.error('Failed to do seek!');
  } else {
    console.info('Succeeded in doing seek!');
  }
});

seek(deprecated)

seek(timeMs: number, mode:SeekMode, callback: AsyncCallback<number>): void

Seeks to the specified playback position. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.seek instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
timeMsnumberYesPosition to seek to, in ms. The value range is [0, duration].
modeSeekModeYesSeek mode.
callbackAsyncCallback<number>YesCallback used to return the result. If the operation is successful, err is undefined and data is the new playback position; otherwise, err is an error object.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let videoPlayer: media.VideoPlayer|null = null;
media.createVideoPlayer((error: BusinessError, video: media.VideoPlayer) => {
  if (video != null) {
    videoPlayer = video;
    console.info('Succeeded in creating VideoPlayer');
  } else {
    console.error(`Failed to create VideoPlayer, error:${error}`);
  }
});
let seekTime: number = 5000;
if (videoPlayer) {
  (videoPlayer as media.VideoPlayer).seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC, (err: BusinessError, result: number) => {
    if (err) {
      console.error('Failed to do seek!');
    } else {
      console.info('Succeeded in doing seek!');
    }
  });
}

seek(deprecated)

seek(timeMs: number, mode?:SeekMode): Promise<number>

Seeks to the specified playback position. If mode is not specified, the previous key frame at the specified position is played. This API uses a promise to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.seek instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
timeMsnumberYesPosition to seek to, in ms. The value range is [0, duration].
modeSeekModeNoSeek mode based on the video I frame. The default value is SEEK_PREV_SYNC.

Return value

TypeDescription
Promise<number>Promise used to return the playback position, in ms.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let videoPlayer: media.VideoPlayer|null = null;
media.createVideoPlayer((error: BusinessError, video: media.VideoPlayer) => {
  if (video != null) {
    videoPlayer = video;
    console.info('Succeeded in creating VideoPlayer');
  } else {
    console.error(`Failed to create VideoPlayer, error:${error}`);
  }
});
let seekTime: number = 5000;
if (videoPlayer) {
  (videoPlayer as media.VideoPlayer).seek(seekTime).then((seekDoneTime: number) => { // seekDoneTime indicates the position after the seek operation is complete.
    console.info('Succeeded in doing seek');
  }).catch((error: BusinessError) => {
    console.error(`video catchCallback, error:${error}`);
  });

  (videoPlayer as media.VideoPlayer).seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC).then((seekDoneTime: number) => {
    console.info('Succeeded in doing seek');
  }).catch((error: BusinessError) => {
    console.error(`video catchCallback, error:${error}`);
  });
}

setVolume(deprecated)

setVolume(vol: number, callback: AsyncCallback<void>): void

Sets the volume. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.setVolume instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
volnumberYesRelative volume. The value ranges from 0.00 to 1.00. The value 1.00 indicates the maximum volume (100%).
callbackAsyncCallback<void>YesCallback used to return the result. If the setting is successful, err is undefined. Otherwise, err is an error object.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let vol: number = 0.5;
videoPlayer.setVolume(vol, (err: BusinessError) => {
  if (err) {
    console.error('Failed to set Volume!');
  } else {
    console.info('Succeeded in setting Volume!');
  }
});

setVolume(deprecated)

setVolume(vol: number): Promise<void>

Sets the volume. This API uses a promise to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.setVolume instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
volnumberYesRelative volume. The value ranges from 0.00 to 1.00. The value 1.00 indicates the maximum volume (100%).

Return value

TypeDescription
Promise<void>Promise that returns no value.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let vol: number = 0.5;
videoPlayer.setVolume(vol).then(() => {
  console.info('Succeeded in setting Volume');
}).catch((error: BusinessError) => {
  console.error(`video catchCallback, error:${error}`);
});

release(deprecated)

release(callback: AsyncCallback<void>): void

Releases the video playback resources. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.release instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<void>YesCallback used to return the result. If the operation is successful, err is undefined; otherwise, err is an error object.

Example

import { BusinessError } from '@kit.BasicServicesKit';

videoPlayer.release((err: BusinessError) => {
  if (err) {
    console.error('Failed to release!');
  } else {
    console.info('Succeeded in releasing!');
  }
});

release(deprecated)

release(): Promise<void>

Releases the video playback resources. This API uses a promise to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.release instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Return value

TypeDescription
Promise<void>Promise that returns no value.

Example

import { BusinessError } from '@kit.BasicServicesKit';

videoPlayer.release().then(() => {
  console.info('Succeeded in releasing');
}).catch((error: BusinessError) => {
  console.error(`video catchCallback, error:${error}`);
});

getTrackDescription(deprecated)

getTrackDescription(callback: AsyncCallback<Array<MediaDescription>>): void

Obtains the video track information. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.getTrackDescription instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<Array<MediaDescription>>YesCallback used to return the result. If the operation is successful, err is undefined and data is the MediaDescription array obtained; otherwise, err is an error object.

Example

import { BusinessError } from '@kit.BasicServicesKit';

videoPlayer.getTrackDescription((error: BusinessError, arrList: Array<media.MediaDescription>) => {
  if ((arrList) != null) {
    console.info('Succeeded in getting TrackDescription');
  } else {
    console.error(`Failed to get TrackDescription, error:${error}`);
  }
});

getTrackDescription(deprecated)

getTrackDescription(): Promise<Array<MediaDescription>>

Obtains the video track information. This API uses a promise to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.getTrackDescription instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Return value

TypeDescription
Promise<Array<MediaDescription>>Promise used to return the MediaDescription array that holds the video track information.

Example

import { BusinessError } from '@kit.BasicServicesKit';

videoPlayer.getTrackDescription().then((arrList: Array<media.MediaDescription>) => {
  if (arrList != null) {
    console.info('Succeeded in getting TrackDescription');
  } else {
    console.error('Failed to get TrackDescription');
  }
}).catch((error: BusinessError) => {
  console.error(`video catchCallback, error:${error}`);
});

setSpeed(deprecated)

setSpeed(speed: number, callback: AsyncCallback<number>): void

Sets the playback speed. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.setSpeed instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
speednumberYesVideo playback speed. For details, see PlaybackSpeed.
callbackAsyncCallback<number>YesCallback used to return the result. If the operation is successful, err is undefined and data is the playback speed; otherwise, err is an error object.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let videoPlayer: media.VideoPlayer|null = null;
media.createVideoPlayer((error: BusinessError, video: media.VideoPlayer) => {
  if (video != null) {
    videoPlayer = video;
    console.info('Succeeded in creating VideoPlayer');
  } else {
    console.error(`Failed to create VideoPlayer, error:${error}`);
  }
});
let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X;
if (videoPlayer) {
  (videoPlayer as media.VideoPlayer).setSpeed(speed, (err: BusinessError, result: number) => {
    if (err) {
      console.error('Failed to set Speed!');
    } else {
      console.info('Succeeded in setting Speed!');
    }
  });
}

setSpeed(deprecated)

setSpeed(speed: number): Promise<number>

Sets the playback speed. This API uses a promise to return the result.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.setSpeed instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
speednumberYesVideo playback speed. For details, see PlaybackSpeed.

Return value

TypeDescription
Promise<number>Promise used to return the playback speed. For details, see PlaybackSpeed.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let videoPlayer: media.VideoPlayer|null = null;
media.createVideoPlayer((error: BusinessError, video: media.VideoPlayer) => {
  if (video != null) {
    videoPlayer = video;
    console.info('Succeeded in creating VideoPlayer');
  } else {
    console.error(`Failed to create VideoPlayer, error:${error}`);
  }
});
let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X;
if (videoPlayer) {
  (videoPlayer as media.VideoPlayer).setSpeed(speed).then((result: number) => {
    console.info('Succeeded in setting Speed');
  }).catch((error: BusinessError) => {
    console.error(`Failed to set Speed, error:${error}`);// todo:: error.
  });
}

on('playbackCompleted')(deprecated)

on(type: 'playbackCompleted', callback: Callback<void>): void

Subscribes to the video playback completion event.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.on('stateChange') instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
typestringYesEvent type, which is 'playbackCompleted' in this case.
callbackCallback<void>YesCallback invoked when the event is triggered.

Example

videoPlayer.on('playbackCompleted', () => {
  console.info('playbackCompleted called!');
});

on('bufferingUpdate')(deprecated)

on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: number) => void): void

Subscribes to the video buffering update event. This API works only under online playback.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.on('bufferingUpdate') instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
typestringYesEvent type, which is 'bufferingUpdate' in this case.
callbackfunctionYesCallback invoked when the event is triggered.
The value of BufferingInfoType is fixed at 0.

Example

videoPlayer.on('bufferingUpdate', (infoType: media.BufferingInfoType, value: number) => {
  console.info('video bufferingInfo type: ' + infoType);
  console.info('video bufferingInfo value: ' + value);
});

on('startRenderFrame')(deprecated)

on(type: 'startRenderFrame', callback: Callback<void>): void

Subscribes to the frame rendering start event.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.on('startRenderFrame') instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
typestringYesEvent type, which is 'startRenderFrame' in this case.
callbackCallback<void>YesCallback invoked when the event is triggered.

Example

videoPlayer.on('startRenderFrame', () => {
  console.info('startRenderFrame called!');
});

on('videoSizeChanged')(deprecated)

on(type: 'videoSizeChanged', callback: (width: number, height: number) => void): void

Subscribes to the video width and height change event.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.on('videoSizeChange') instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
typestringYesEvent type, which is 'videoSizeChanged' in this case.
callbackfunctionYesCallback invoked when the event is triggered. width indicates the video width, and height indicates the video height.

Example

videoPlayer.on('videoSizeChanged', (width: number, height: number) => {
  console.info('video width is: ' + width);
  console.info('video height is: ' + height);
});

on('audioInterrupt')(deprecated)

on(type: 'audioInterrupt', callback: (info: audio.InterruptEvent) => void): void

Subscribes to the audio interruption event. For details, see audio.InterruptEvent.

NOTE

This API is supported since API version 9 and deprecated since API version 9. You are advised to use AVPlayer.on('audioInterrupt') instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
typestringYesEvent type, which is 'audioInterrupt' in this case.
callbackfunctionYesCallback invoked when the event is triggered.

Example

import { audio } from '@kit.AudioKit';

videoPlayer.on('audioInterrupt', (info: audio.InterruptEvent) => {
  console.info('audioInterrupt called,and InterruptEvent info is:' + info);
});

on('error')(deprecated)

on(type: 'error', callback: ErrorCallback): void

Subscribes to video playback error events. After an error event is reported, you must handle the event and exit the playback.

NOTE

This API is supported since API version 8 and deprecated since API version 9. You are advised to use AVPlayer.on('error') instead.

System capability: SystemCapability.Multimedia.Media.VideoPlayer

Parameters

NameTypeMandatoryDescription
typestringYesEvent type, which is 'error' in this case.
This event is triggered when an error occurs during video playback.
callbackErrorCallbackYesCallback invoked when the event is triggered.

Example

import { BusinessError } from '@kit.BasicServicesKit';

videoPlayer.on('error', (error: BusinessError) => {  // Set the 'error' event callback.
  console.error(`video error called, error: ${error}`);
});
videoPlayer.url = 'fd://error';  // Set an incorrect URL to trigger the 'error' event.

你可能感兴趣的鸿蒙文章

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/tiIjJlvQ