# Deprecated Interface (VideoPlayer, deprecated)
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer](arkts-apis-media-AVPlayer.md) instead.
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()](arkts-apis-media-f.md#mediacreatevideoplayerdeprecated) to create a VideoPlayer instance.
## Modules to Import
```ts
import { media } from '@kit.MediaKit';
```
## Properties
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
| Name | Type | Read-Only| Optional| Description |
| ------------------------------- | ------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
| url8+ | string | No | No | Video 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+ | [AVFileDescriptor](arkts-apis-media-i.md#avfiledescriptor9) | No | No | Description 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+ | boolean | No | No | Whether to loop video playback. **true** to loop, **false** otherwise. |
| videoScaleType9+ | [VideoScaleType](arkts-apis-media-e.md#videoscaletype9) | No | Yes | Video scale type. The default value is **VIDEO_SCALE_TYPE_FIT**. |
| audioInterruptMode9+ | [audio.InterruptMode](../apis-audio-kit/arkts-apis-audio-e.md#interruptmode9) | No | Yes | Audio interruption mode. |
| currentTime8+ | number | Yes | No | Current video playback position, in ms. |
| duration8+ | number | Yes | No | Video duration, in ms. The value **-1** indicates the live mode. |
| state8+ | [VideoPlayState](arkts-apis-media-t.md#videoplaystatedeprecated) | Yes | No | Video playback state. |
| width8+ | number | Yes | No | Video width, in px. |
| height8+ | number | Yes | No | Video height, in px. |
## setDisplaySurface(deprecated)
setDisplaySurface(surfaceId: string, callback: AsyncCallback\): 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.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.surfaceId](arkts-apis-media-AVPlayer.md#properties) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | -------------------- | ---- | ------------------------- |
| surfaceId | string | Yes | Surface ID, which is obtained from the **XComponent**. For details about how to obtain it, see [XComponent](../../reference/apis-arkui/arkui-ts/ts-basic-components-xcomponent.md). |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example**
```ts
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\
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.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.surfaceId](arkts-apis-media-AVPlayer.md#properties) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | --------- |
| surfaceId | string | Yes | Surface ID, which is obtained from the **XComponent**. For details about how to obtain it, see [XComponent](../../reference/apis-arkui/arkui-ts/ts-basic-components-xcomponent.md).|
**Return value**
| Type | Description |
| -------------- | ------------------------------ |
| Promise\ | Promise that returns no value.|
**Example**
```ts
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
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](arkts-apis-media-AVPlayer.md#prepare9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
**Example**
```ts
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\
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](arkts-apis-media-AVPlayer.md#prepare9-1) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Return value**
| Type | Description |
| -------------- | ----------------------------- |
| Promise\ | Promise that returns no value.|
**Example**
```ts
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
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](arkts-apis-media-AVPlayer.md#play9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
**Example**
```ts
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\
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](arkts-apis-media-AVPlayer.md#play9-1) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Return value**
| Type | Description |
| -------------- | ----------------------------- |
| Promise\ | Promise that returns no value.|
**Example**
```ts
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
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](arkts-apis-media-AVPlayer.md#pause9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
**Example**
```ts
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\
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](arkts-apis-media-AVPlayer.md#pause9-1) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Return value**
| Type | Description |
| -------------- | ----------------------------- |
| Promise\ | Promise that returns no value.|
**Example**
```ts
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
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](arkts-apis-media-AVPlayer.md#stop9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
**Example**
```ts
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\
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](arkts-apis-media-AVPlayer.md#stop9-1) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Return value**
| Type | Description |
| -------------- | ----------------------------- |
| Promise\ | Promise that returns no value.|
**Example**
```ts
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
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](arkts-apis-media-AVPlayer.md#reset9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
**Example**
```ts
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\
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](arkts-apis-media-AVPlayer.md#reset9-1) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Return value**
| Type | Description |
| -------------- | ----------------------------- |
| Promise\ | Promise that returns no value.|
**Example**
```ts
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\): 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](arkts-apis-media-AVPlayer.md#seek9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
| timeMs | number | Yes | Position to seek to, in ms. The value range is [0, duration].|
| callback | AsyncCallback\ | Yes | Callback 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**
```ts
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\): 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](arkts-apis-media-AVPlayer.md#seek9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
| timeMs | number | Yes | Position to seek to, in ms. The value range is [0, duration].|
| mode | [SeekMode](arkts-apis-media-e.md#seekmode8) | Yes | Seek mode. |
| callback | AsyncCallback\ | Yes | Callback 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**
```ts
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\
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](arkts-apis-media-AVPlayer.md#seek9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ---------------------- | ---- | ------------------------------------------------------------ |
| timeMs | number | Yes | Position to seek to, in ms. The value range is [0, duration].|
| mode | [SeekMode](arkts-apis-media-e.md#seekmode8) | No | Seek mode based on the video I frame. The default value is **SEEK_PREV_SYNC**. |
**Return value**
| Type | Description |
| ---------------- | ------------------------------------------- |
| Promise\| Promise used to return the playback position, in ms.|
**Example**
```ts
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
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](arkts-apis-media-AVPlayer.md#setvolume9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| vol | number | Yes | Relative volume. The value ranges from 0.00 to 1.00. The value **1.00** indicates the maximum volume (100%).|
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example**
```ts
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\
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](arkts-apis-media-AVPlayer.md#setvolume9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| vol | number | Yes | Relative volume. The value ranges from 0.00 to 1.00. The value **1.00** indicates the maximum volume (100%).|
**Return value**
| Type | Description |
| -------------- | ------------------------- |
| Promise\ | Promise that returns no value.|
**Example**
```ts
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
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](arkts-apis-media-AVPlayer.md#release9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
**Example**
```ts
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\
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](arkts-apis-media-AVPlayer.md#release9-1) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Return value**
| Type | Description |
| -------------- | ----------------------------- |
| Promise\ | Promise that returns no value.|
**Example**
```ts
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\>): 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](arkts-apis-media-AVPlayer.md#gettrackdescription9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ |
| callback | AsyncCallback\> | Yes | Callback 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**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
videoPlayer.getTrackDescription((error: BusinessError, arrList: Array) => {
if ((arrList) != null) {
console.info('Succeeded in getting TrackDescription');
} else {
console.error(`Failed to get TrackDescription, error:${error}`);
}
});
```
## getTrackDescription(deprecated)
getTrackDescription(): Promise\>
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](arkts-apis-media-AVPlayer.md#gettrackdescription9-1) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Return value**
| Type | Description |
| ------------------------------------------------------ | ----------------------------------------------- |
| Promise> | Promise used to return the MediaDescription array that holds the video track information.|
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
videoPlayer.getTrackDescription().then((arrList: Array) => {
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\): 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](arkts-apis-media-AVPlayer.md#setspeed9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ---------------------------------------------------------- |
| speed | number | Yes | Video playback speed. For details, see [PlaybackSpeed](arkts-apis-media-e.md#playbackspeed8).|
| callback | AsyncCallback\ | Yes | Callback 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**
```ts
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\
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](arkts-apis-media-AVPlayer.md#setspeed9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------------------------------------------------- |
| speed | number | Yes | Video playback speed. For details, see [PlaybackSpeed](arkts-apis-media-e.md#playbackspeed8).|
**Return value**
| Type | Description |
| ---------------- | ------------------------------------------------------------ |
| Promise\| Promise used to return the playback speed. For details, see [PlaybackSpeed](arkts-apis-media-e.md#playbackspeed8).|
**Example**
```ts
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
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')](arkts-apis-media-AVPlayer.md#onstatechange9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ----------------------------------------------------------- |
| type | string | Yes | Event type, which is **'playbackCompleted'** in this case.|
| callback | Callback\ | Yes | Callback invoked when the event is triggered. |
**Example**
```ts
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')](arkts-apis-media-AVPlayer.md#onbufferingupdate9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Event type, which is **'bufferingUpdate'** in this case. |
| callback | function | Yes | Callback invoked when the event is triggered.
The value of [BufferingInfoType](arkts-apis-media-e.md#bufferinginfotype8) is fixed at **0**.|
**Example**
```ts
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
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')](arkts-apis-media-AVPlayer.md#onstartrenderframe9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Event type, which is **'startRenderFrame'** in this case.|
| callback | Callback\ | Yes | Callback invoked when the event is triggered. |
**Example**
```ts
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')](arkts-apis-media-AVPlayer.md#onvideosizechange9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Event type, which is **'videoSizeChanged'** in this case.|
| callback | function | Yes | Callback invoked when the event is triggered. **width** indicates the video width, and **height** indicates the video height. |
**Example**
```ts
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](../apis-audio-kit/arkts-apis-audio-i.md#interruptevent9).
> **NOTE**
>
> This API is supported since API version 9 and deprecated since API version 9. You are advised to use [AVPlayer.on('audioInterrupt')](arkts-apis-media-AVPlayer.md#onaudiointerrupt9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- |
| type | string | Yes | Event type, which is **'audioInterrupt'** in this case.|
| callback | function | Yes | Callback invoked when the event is triggered. |
**Example**
```ts
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')](arkts-apis-media-AVPlayer.md#onerror9) instead.
**System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Event type, which is **'error'** in this case.
This event is triggered when an error occurs during video playback.|
| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback invoked when the event is triggered. |
**Example**
```ts
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.
```