• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Types
2<!--Kit: AVSession Kit-->
3<!--Subsystem: Multimedia-->
4<!--Owner: @ccfriend; @liao_qian-->
5<!--SE: @ccfriend-->
6<!--TSE: @chenmingxi1_huawei-->
7
8> **NOTE**
9>
10> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
11
12## AVSessionType<sup>10+<sup>
13
14type AVSessionType = 'audio' | 'video' | 'voice_call' | 'video_call'
15
16Defines the session type supported by the session.
17
18You can use the strings listed in the following table.
19
20**Atomic service API**: This API can be used in atomic services since API version 12.
21
22**System capability**: SystemCapability.Multimedia.AVSession.Core
23
24| Type | Description|
25| -----  | ---- |
26| 'audio' | Audio session.|
27| 'video' | Video session.|
28| 'voice_call'<sup>11+<sup> | Voice call.|
29| 'video_call'<sup>12+<sup> | Video call.|
30
31## AVCastControlCommandType<sup>10+</sup>
32
33type AVCastControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' |
34  'seek' | 'setVolume' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite' | 'toggleMute'
35
36Defines the commands that can be sent by a cast controller.
37
38**Atomic service API**: This API can be used in atomic services since API version 12.
39
40**System capability**: SystemCapability.Multimedia.AVSession.AVCast
41
42| Type            | Description        |
43| ---------------- | ------------ |
44| 'play'           | Play the media. No parameter is required.|
45| 'pause'          | Pause the playback. No parameter is required.  |
46| 'stop'           | Stop the playback. No parameter is required.        |
47| 'playNext'       | Play the next media asset. No parameter is required.      |
48| 'playPrevious'   | Play the previous media asset. No parameter is required.      |
49| 'fastForward'    | Fast-forward. No parameter is required.      |
50| 'rewind'         | Rewind. No parameter is required.       |
51| 'seek'           | Seek to a playback position. The corresponding parameter is of the number type.|
52| 'setVolume'      | Set the volume. The corresponding parameter is of the number type. You can use [AVPlaybackState.maxVolume](arkts-apis-avsession-i.md#avplaybackstate10) to obtain the maximum system volume.    |
53| 'setSpeed'       | Set the playback speed. The corresponding parameter is [media.PlaybackSpeed](../apis-media-kit/arkts-apis-media-e.md#playbackspeed8).|
54| 'setLoopMode'    | Set the loop mode. The corresponding parameter is [LoopMode](arkts-apis-avsession-e.md#loopmode10).|
55| 'toggleFavorite' | Favorite the media asset. The corresponding parameter is [AVMetadata.assetId](arkts-apis-avsession-i.md#avmetadata10).   |
56| 'toggleMute'     | Set the muted status. No parameter is required.|
57
58## ExtraInfo<sup>18+</sup>
59
60type ExtraInfo = { [key: string]: Object; }
61
62Defines the custom media packet set by the provider.
63
64**System capability**: SystemCapability.Multimedia.AVSession.Core
65
66| Type                               | Description                         |
67| ----------------------------------- | ----------------------------- |
68| [key: string]: Object   | **key** specifies the remote distributed event type. Currently, the following event types are supported:<br>**'AUDIO_GET_VOLUME'**: obtains the volume of the remote device.<br>**'AUDIO_GET_AVAILABLE_DEVICES'**: obtains all remote devices that can be connected.<br>**'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO'**: obtains the actual remote audio device.<br>The provider returns the corresponding media packet object based on the event type.|
69
70## KeyRequestCallback<sup>12+</sup>
71
72type KeyRequestCallback = (assetId: string, requestData: Uint8Array) => void
73
74Defines the callback invoked for the media key request event.
75
76**Atomic service API**: This API can be used in atomic services since API version 12.
77
78**System capability**: SystemCapability.Multimedia.AVSession.AVCast
79
80**Parameters**
81
82| Name| Type  | Mandatory| Description                                     |
83| ------ | ------ | ---- | ----------------------------------------- |
84| assetId     | string  | Yes  | Media asset ID.|
85| requestData |  Uint8Array  | Yes  | Data carried in the media key request.                           |
86
87**Example**
88<!--code_no_check-->
89```ts
90let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
91  console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`);
92}
93```
94
95## AVControlCommandType<sup>10+</sup>
96
97type AVControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' |
98  'seek' | 'setSpeed' | 'setLoopMode' | 'setTargetLoopMode' | 'toggleFavorite' | 'playFromAssetId' | 'playWithAssetId' | 'answer' | 'hangUp' | 'toggleCallMute'
99
100Defines the commands that can be sent to a session.
101
102You can use the union of the strings listed in the following table.
103
104**Atomic service API**: This API can be used in atomic services since API version 12.
105
106**System capability**: SystemCapability.Multimedia.AVSession.Core
107
108| Type            | Description        |
109| ---------------- | ------------ |
110| 'play'           | Play the media. No parameter is required.|
111| 'pause'          | Pause the playback. No parameter is required.|
112| 'stop'           | Stop the playback. No parameter is required.|
113| 'playNext'       | Play the next media asset. No parameter is required.|
114| 'playPrevious'   | Play the previous media asset. No parameter is required.|
115| 'fastForward'    | Fast-forward. No parameter is required.|
116| 'rewind'         | Rewind. No parameter is required.|
117| 'seek'           | Seek to a playback position. The corresponding parameter is of the number type.|
118| 'setSpeed'       | Set the playback speed. The corresponding parameter is of the number type.|
119| 'setLoopMode'    | Set the loop mode. The corresponding parameter is [LoopMode](arkts-apis-avsession-e.md#loopmode10).|
120| 'setTargetLoopMode' <sup>18+</sup>   | Set the target loop mode. The recommended parameter is [LoopMode](arkts-apis-avsession-e.md#loopmode10).|
121| 'toggleFavorite' | Favorite the media asset. The corresponding parameter is [AVMetadata.assetId](arkts-apis-avsession-i.md#avmetadata10).    |
122| 'playFromAssetId'| Play the media asset with the specified asset ID.|
123| 'playWithAssetId' <sup>20+</sup>    | Play the media asset with the specified asset ID. The corresponding parameter is [AVMetadata.assetId](arkts-apis-avsession-i.md#avmetadata10).<br>The string length must be less than 40960 bytes.<br>|
124|'answer'          | Answer a call. No parameter is required.       |
125| 'hangUp'         | The call is disconnecting. No parameter is required.       |
126|'toggleCallMute'  | Set the mute status for a call. No parameter is required.|
127