1# Interfaces (Others) 2<!--Kit: Media Kit--> 3<!--Subsystem: Multimedia--> 4<!--Owner: @wang-haizhou6--> 5<!--Designer: @HmQQQ--> 6<!--Tester: @xchaosioda--> 7<!--Adviser: @zengyawen--> 8 9> **NOTE** 10> 11> 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. 12 13## AVFileDescriptor<sup>9+</sup> 14 15Describes an audio and video file asset. It is used to specify a particular asset for playback based on its offset and length within a file. 16 17**Atomic service API**: This API can be used in atomic services since API version 11. 18 19**System capability**: SystemCapability.Multimedia.Media.Core 20 21| Name | Type | Mandatory| Description | 22| ------ | ------ | ---- | ------------------------------------------------------------ | 23| fd | number | Yes | Resource handle, which is obtained by calling [resourceManager.getRawFd](../apis-localization-kit/js-apis-resource-manager.md#getrawfd9) or [fs.open](../apis-core-file-kit/js-apis-file-fs.md#fsopen). | 24| offset | number | No | Resource offset, which needs to be entered based on the preset asset information. The default value is **0**. An invalid value causes a failure to parse audio and video assets.| 25| length | number | No | Resource length, which needs to be entered based on the preset asset information. The default value is the remaining bytes from the offset in the file. An invalid value causes a failure to parse audio and video assets.| 26 27## AVDataSrcDescriptor<sup>10+</sup> 28 29Defines the descriptor of an audio and video file, which is used in DataSource playback mode.<br>Use scenario: An application can create a playback instance and start playback before it finishes downloading the audio and video resources. 30 31**Atomic service API**: This API can be used in atomic services since API version 11. 32 33**System capability**: SystemCapability.Multimedia.Media.AVPlayer 34 35| Name | Type | Mandatory| Description | 36| ------ | ------ | ---- | ------------------------------------------------------------ | 37| fileSize | number | Yes | Size of the file to play, in bytes. The value **-1** indicates that the size is unknown. If **fileSize** is set to **-1**, the playback mode is similar to the live mode. In this mode, the **seek** and **setSpeed** operations cannot be performed, and the **loop** property cannot be set, indicating that loop playback is unavailable.| 38| callback | (buffer: ArrayBuffer, length: number, pos?: number) => number | Yes | Callback used to fill in data.<br>- Function: callback: (buffer: ArrayBuffer, length: number, pos?:number) => number;<br>- **buffer**: memory to be filled. The value is of the ArrayBuffer type. This parameter is mandatory.<br>- **length**: maximum length of the memory to be filled. The value is of the number type. This parameter is mandatory.<br>- **pos**: position of the data to be filled in the file. The value is of the number type. This parameter is optional. When **fileSize** is set to **-1**, this parameter cannot be used.<br>- Return value: length of the data filled, which is of the number type. If **-1** is returned, the end of stream is reached. If **-2** is returned, an unrecoverable error occurs.| 39 40## SubtitleInfo<sup>12+</sup> 41 42Describes the external subtitle information. When a subtitle update event is subscribed to, the information about the external subtitle is returned through a callback. 43 44**Atomic service API**: This API can be used in atomic services since API version 12. 45 46**System capability**: SystemCapability.Multimedia.Media.Core 47 48| Name | Type | Mandatory| Description | 49| ------ | ------ | ---- | ------------------------------------------------------------ | 50| text | string | No | Text information of the subtitle.| 51| startTime | number | No | Start time for displaying the subtitle, in milliseconds.| 52| duration | number | No| Duration for displaying the subtitle, in milliseconds.| 53 54## SeiMessage<sup>18+</sup> 55 56Describes the information of an SEI message. 57 58**Atomic service API**: This API can be used in atomic services since API version 18. 59 60**System capability**: SystemCapability.Multimedia.Media.Core 61 62| Name | Type | Read-Only| Optional | Description | 63| ------ | ------ | ---- | ---- | ------------------------------------------------------------ | 64| payloadType | number | No | No | Payload type of the SEI message.| 65| payload | ArrayBuffer | No | No | Payload data of the SEI message.| 66 67## MediaDescription<sup>8+</sup> 68 69Defines media information in key-value mode. 70 71**Atomic service API**: This API can be used in atomic services since API version 11. 72 73**System capability**: SystemCapability.Multimedia.Media.Core 74 75| Name | Type | Mandatory| Description | 76| ------------- | ------ | ---- | ------------------------------------------------------------ | 77| [key: string] | Object | Yes | For details about the key range supported and the object type and range of each key, see [MediaDescriptionKey](arkts-apis-media-e.md#mediadescriptionkey8).| 78 79**Example** 80 81```ts 82import { BusinessError } from '@kit.BasicServicesKit'; 83import { media } from '@kit.MediaKit'; 84 85function printfItemDescription(obj: media.MediaDescription, key: string) { 86 let property: Object = obj[key]; 87 console.info('audio key is ' + key); // Specify a key. For details about the keys, see MediaDescriptionKey. 88 console.info('audio value is ' + property); // Obtain the value of the key. The value can be any type. For details about the types, see MediaDescriptionKey. 89} 90 91let avPlayer: media.AVPlayer | undefined = undefined; 92media.createAVPlayer((err: BusinessError, player: media.AVPlayer) => { 93 if(player != null) { 94 avPlayer = player; 95 console.info(`Succeeded in creating AVPlayer`); 96 avPlayer.getTrackDescription((error: BusinessError, arrList: Array<media.MediaDescription>) => { 97 if (arrList != null) { 98 for (let i = 0; i < arrList.length; i++) { 99 printfItemDescription(arrList[i], media.MediaDescriptionKey.MD_KEY_TRACK_TYPE); // Print the MD_KEY_TRACK_TYPE value of each track. 100 } 101 } else { 102 console.error(`Failed to get TrackDescription, error:${error}`); 103 } 104 }); 105 } else { 106 console.error(`Failed to create AVPlayer, error message:${err.message}`); 107 } 108}); 109``` 110 111## PlaybackInfo<sup>12+</sup> 112 113Defines the playback information in key-value pairs. 114 115**System capability**: SystemCapability.Multimedia.Media.Core 116 117| Name | Type | Mandatory| Description | 118| ------------- | ------ | ---- | ------------------------------------------------------------ | 119| [key: string]| Object | Yes | For details about the key range supported and the object type and range of each key, see [PlaybackInfoKey](arkts-apis-media-e.md#playbackinfokey12).| 120 121## AVRecorderConfig<sup>9+</sup> 122 123Describes the audio and video recording parameters. 124 125The **audioSourceType** and **videoSourceType** parameters are used to distinguish audio-only recording, video-only recording, and audio and video recording. For audio-only recording, set only **audioSourceType**. For video-only recording, set only **videoSourceType**. For audio and video recording, set both **audioSourceType** and **videoSourceType**. 126 127**System capability**: SystemCapability.Multimedia.Media.AVRecorder 128 129| Name | Type | Mandatory| Description | 130| --------------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | 131| audioSourceType | [AudioSourceType](arkts-apis-media-e.md#audiosourcetype9) | No | Type of the audio source to record. This parameter is mandatory for audio recording.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 132| videoSourceType | [VideoSourceType](arkts-apis-media-e.md#videosourcetype9) | No | Type of the video source to record. This parameter is mandatory for video recording. | 133| profile | [AVRecorderProfile](#avrecorderprofile9) | Yes | Recording profile. This parameter is mandatory.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 134| url | string | Yes | Recording output URL: fd://xx (fd number).<br><br>This parameter is mandatory.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 135|fileGenerationMode<sup>12+</sup> | [FileGenerationMode](arkts-apis-media-e.md#filegenerationmode12) | No | Mode for creating the file, which is used together with [on('photoAssetAvailable')](arkts-apis-media-AVRecorder.md#onphotoassetavailable12).| 136| rotation<sup>(deprecated)</sup> | number | No | Rotation angle of the recorded video. The value can be 0 (default), 90, 180, or 270 for MP4 videos.<br>This API is supported since API version 6 and deprecated since API version 12. You are advised to use **[AVMetadata](#avmetadata11).videoOrientation** instead. If both parameters are set, **[AVMetadata](#avmetadata11).videoOrientation** is used. | 137| location<sup>(deprecated)</sup> | [Location](#location) | No | Geographical location of the recorded video. By default, the geographical location information is not recorded.<br>This API is supported since API version 6 and deprecated since API version 12. You are advised to use **[AVMetadata](#avmetadata11).location** instead. If both parameters are set, **[AVMetadata](#avmetadata11).location** is used.| 138| metadata<sup>12+</sup> | [AVMetadata](#avmetadata11) | No | Metadata. For details, see [AVMetadata](#avmetadata11). | 139| maxDuration<sup>18+</sup> | number | No | Maximum recording duration, in seconds. The value range is [1, 2^31-1]. If an invalid value is provided, it is reset to the maximum allowed duration. Once the recording reaches the specified duration, it stops automatically and notifies via the stateChange callback that the recording has stopped: [AVRecorderState](arkts-apis-media-t.md#avrecorderstate9) = 'stopped', [StateChangeReason](arkts-apis-media-e.md#statechangereason9) = BACKGROUND.| 140 141## AVRecorderProfile<sup>9+</sup> 142 143Describes the audio and video recording profile. 144 145**System capability**: SystemCapability.Multimedia.Media.AVRecorder 146 147| Name | Type | Mandatory| Description | 148| ---------------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | 149| audioBitrate | number | No | Audio encoding bit rate. This parameter is mandatory for audio recording.<br>Supported bit rate ranges:<br>- Range [32000 - 500000] for the AAC encoding format.<br>- Range [64000] for the G.711 μ-law encoding format.<br>- Range [8000, 16000, 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000] for the MP3 encoding format.<br>When the MP3 encoding format is used, the mapping between the sample rate and bit rate is as follows:<br>- When the sample rate is lower than 16 kHZ, the bit rate range is [8000 - 64000].<br>- When the sample rate ranges from 16 kHz to 32 kHz, the bit rate range is [8000 - 160000].<br>- When the sample rate is greater than 32 kHz, the bit rate range is [32000 - 320000].<br>- Range [4750, 5150, 5900, 6700, 7400, 7950, 10200, 12200] for the AMR-NB encoding format.<br>- Range [6600, 8850, 12650, 14250, 15850, 18250, 19850, 23050, 23850] for the AMR-WB encoding format.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 150| audioChannels | number | No | Audio channel count. This parameter is mandatory for audio recording.<br>- Range [1 - 8] for the AAC encoding format.<br>- Range [1] for the G.711 μ-law encoding format.<br>- Range [1 - 2] for the MP3 encoding format.<br>- Range [1] for the AMR-NB and AMR-WB encoding formats.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 151| audioCodec | [CodecMimeType](arkts-apis-media-e.md#codecmimetype8) | No | Audio encoding format. This parameter is mandatory for audio recording. Currently, AUDIO_AAC, AUDIO_MP3, AUDIO_G711MU, AUDIO_AMR_NB, and AUDIO_AMR_WB are supported.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 152| audioSampleRate | number | No | Audio sample rate. This parameter is mandatory for audio recording.<br>Supported sample rate ranges:<br>- Range [8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000] for the AAC encoding format.<br>- Range [8000] for the G.711 μ-law encoding format.<br>- Range [8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000] for the MP3 encoding format.<br>- Range [8000] for the AMR-NB encoding format.<br>- Range [16000] for the AMR-WB encoding format.<br>Variable bit rate. The bit rate is for reference only.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 153| fileFormat | [ContainerFormatType](arkts-apis-media-e.md#containerformattype8) | Yes | Container format of a file. This parameter is mandatory. Currently, the MP4, M4A, MP3, WAV, AMR, and AAC container formats are supported. The default container format for AAC audio is ADTS frame format. The AUDIO_MP3 encoding format is not supported within the MP4 container format.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 154| videoBitrate | number | No | Video encoding bit rate. This parameter is mandatory for video recording. The value range is [10000 - 100000000]. | 155| videoCodec | [CodecMimeType](arkts-apis-media-e.md#codecmimetype8) | No | Video encoding format. This parameter is mandatory for video recording. Currently, **VIDEO_AVC** and **VIDEO_HEVC** are supported.| 156| videoFrameWidth | number | No | Width of a video frame. This parameter is mandatory for video recording. The value range is [176 - 4096]. | 157| videoFrameHeight | number | No | Height of a video frame. This parameter is mandatory for video recording. The value range is [144 - 4096]. | 158| videoFrameRate | number | No | Video frame rate. This parameter is mandatory for video recording. The recommended value range is [1 - 60]. | 159| isHdr<sup>11+</sup> | boolean | No | HDR encoding. This parameter is optional for video recording. The default value is **false**, and there is no requirement on the encoding format. When **isHdr** is set to **true**, the encoding format must be **video/hevc**.| 160| enableTemporalScale<sup>12+</sup> | boolean | No | Whether temporal layered encoding is supported. This parameter is optional for video recording. The default value is **false**. If this parameter is set to **true**, some frames in the video output streams can be skipped without being encoded.| 161| enableBFrame<sup>20+</sup> | boolean | No | Whether B-frame encoding is enabled for video recording. **true** if enabled (valid only when the video encoding format is H.265 and the device hardware supports B-frame encoding), **false** otherwise.<br>This parameter is optional in video recording scenarios. The default value is **false**.| 162 163### Audio Parameters 164 165The following table lists the audio parameters. For details about each parameter, see the field description below. 166 167|Encoding Format|Container Format|Sample Rate|Bit Rate|Audio Channel Count| 168|----|----|----|----|----| 169|AUDIO_AAC|MP4, M4A|[8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000]|[32000-500000]|[1-8]| 170|AUDIO_MP3|MP3|[8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000]|<br>- When the sample rate is lower than 16000, the bit rate range is [8000, 16000, 32000, 40000, 48000, 56000, 64000].<br>- When the sample rate ranges from 16000 to 32000, the bit rate range is [8000, 16000, 32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000].<br>- When the sample rate is greater than 32000, the bit rate range is [32000, 40000, 48000, 56000, 64000, 80000, 96000, 112000, 128000, 160000, 192000, 224000, 256000, 320000].|[1-2]| 171|AUDIO_G711MU|WAV|[8000]|[64000]|[1]| 172|AUDIO_AMR_NB<sup>18+</sup> |AMR|[8000]|[4750, 5150, 5900, 6700, 7400, 7950, 10200, 12200]|[1]| 173|AUDIO_AMR_WB<sup>18+</sup> |AMR|[16000]|[6600, 8850, 12650, 14250, 15850, 18250, 19850, 23050, 23850]|[1]| 174 175 176## Location 177 178Describes the geographical location of the recorded video. 179 180**System capability**: SystemCapability.Multimedia.Media.Core 181 182| Name | Type | Mandatory| Description | 183| --------- | ------ | ---- | ---------------- | 184| latitude | number | Yes | Latitude of the geographical location. The value range is [-90, 90].| 185| longitude | number | Yes | Longitude of the geographical location. The value range is [-180, 180].| 186 187## EncoderInfo<sup>11+</sup> 188 189Describes the information about an encoder. 190 191**System capability**: SystemCapability.Multimedia.Media.AVRecorder 192 193| Name | Type | Readable| Writable| Description | 194| ---------- | -------------------------------- | ---- | ---- | ------------------------------------------------------------ | 195| mimeType | [CodecMimeType](arkts-apis-media-e.md#codecmimetype8) | Yes | No | MIME type of the encoder. | 196| type | string | Yes | No | Encoder type. The value **audio** means an audio encoder, and **video** means a video encoder. | 197| bitRate | [Range](#range11) | Yes | No | Bit rate range of the encoder, with the minimum and maximum bit rates specified. | 198| frameRate | [Range](#range11) | Yes | No | Video frame rate range, with the minimum and maximum frame rates specified. This parameter is available only for video encoders. | 199| width | [Range](#range11) | Yes | No | Video frame width range, with the minimum and maximum widths specified. This parameter is available only for video encoders. | 200| height | [Range](#range11) | Yes | No | Video frame height range, with the minimum and maximum heights specified. This parameter is available only for video encoders. | 201| channels | [Range](#range11) | Yes | No | Audio channel count for the audio capturer, with the minimum and maximum numbers of audio channels specified. This parameter is available only for audio encoders. | 202| sampleRate | Array\<number> | Yes | No | Audio sample rate, including all available audio sample rates. The value depends on the encoder type, and this parameter is available only for audio encoders.| 203 204## Range<sup>11+</sup> 205 206Describes a range. 207 208**System capability**: SystemCapability.Multimedia.Media.AVRecorder 209 210| Name| Type | Readable| Writable| Description | 211| ---- | ------ | ---- | ---- | ------------ | 212| min | number | Yes | No | Minimum value.| 213| max | number | Yes | No | Maximum value.| 214 215## AVTranscoderConfig<sup>12+</sup> 216 217Describes the video transcoding parameters. 218 219**System capability**: SystemCapability.Multimedia.Media.AVTranscoder 220 221| Name | Type | Read-Only| Optional| Description | 222| --------------- | ---------------------------------------- |---- | ---- | ------------------------------------------------------------ | 223| audioBitrate | number | No| Yes| Bit rate of the output audio, in bit/s. The value range is [1 - 500000]. The default value is 48 kbit/s.| 224| audioCodec | [CodecMimeType](arkts-apis-media-e.md#codecmimetype8) | No| Yes | Encoding format of the output audio. Currently, only AAC is supported. The default value is **AAC**. | 225| fileFormat | [ContainerFormatType](arkts-apis-media-e.md#containerformattype8) | No| No | Container format of the output video file. Currently, only MP4 is supported.| 226| videoBitrate | number | No| Yes | Bit rate of the output video, in bit/s. The default bit rate depends on the resolution of the output video. The default bit rate is 1 Mbit/s for the resolution in the range [240p, 480P], 2 Mbit/s for the range (480P, 720P], 4 Mbit/s for the range (720P, 1080P], and 8 Mbit/s for 1080p or higher.| 227| videoCodec | [CodecMimeType](arkts-apis-media-e.md#codecmimetype8) | No| Yes | Encoding format of the output video. Currently, only AVC and HEVC are supported. If the source video is in HEVC format, the default value is **HEVC**. Otherwise, the default value is **AVC**.| 228| videoFrameWidth | number | No| Yes | Width of the output video frame, in px. The value range is [240 - 3840]. The default value is the width of the source video frame.| 229| videoFrameHeight | number | No| Yes | Height of the output video frame, in px. The value range is [240 - 2160]. The default value is the height of the source video frame.| 230| enableBFrame<sup>20+</sup> | boolean | No| Yes | Whether B-frame encoding is enabled for transcoding. **true** if enabled, **false** otherwise.<br>For details about the restrictions on B-frame video encoding, see [Constraints in B-Frame Video Encoding](../../media/avcodec/video-encoding-b-frame.md#constraints). If the current environment does not meet these constraints, B-frames will be skipped, and encoding will proceed as if B-frame video encoding were not enabled.| 231 232 233## AVMetadata<sup>11+</sup> 234 235Defines the audio and video metadata. Parameters that are not declared as read-only in [AVRecorderConfig](#avrecorderconfig9) can be used as input parameters for recording of [AVRecorder](arkts-apis-media-AVRecorder.md). 236 237**System capability**: SystemCapability.Multimedia.Media.AVMetadataExtractor 238 239| Name | Type | Mandatory| Description | 240| ------ | ------ | ---- | ------------------------------------------------------------ | 241| album | string | No | Title of the album. This parameter is read-only in the current version. | 242| albumArtist | string | No | Artist of the album. This parameter is read-only in the current version.| 243| artist | string | No | Artist of the media asset. This parameter is read-only in the current version.| 244| author | string | No | Author of the media asset. This parameter is read-only in the current version.| 245| dateTime | string | No | Time when the media asset is created. This parameter is read-only in the current version.| 246| dateTimeFormat | string | No | Time when the media asset is created. The value is in the YYYY-MM-DD HH:mm:ss format. This parameter is read-only in the current version.| 247| composer | string | No | Composer of the media asset. This parameter is read-only in the current version.| 248| duration | string | No | Duration of the media asset. This parameter is read-only in the current version.| 249| genre | string | No | Type or genre of the media asset.| 250| hasAudio | string | No | Whether the media asset contains audio. This parameter is read-only in the current version.| 251| hasVideo | string | No | Whether the media asset contains a video. This parameter is read-only in the current version.| 252| mimeType | string | No | MIME type of the media asset. This parameter is read-only in the current version.| 253| trackCount | string | No | Number of tracks of the media asset. This parameter is read-only in the current version.| 254| sampleRate | string | No | Audio sample rate, in Hz. This parameter is read-only in the current version.| 255| title | string | No | Title of the media asset. This parameter is read-only in the current version. This parameter is read-only in the current version.| 256| videoHeight | string | No | Video height, in px. This parameter is read-only in the current version.| 257| videoWidth | string | No | Video width, in px. This parameter is read-only in the current version.| 258| videoOrientation | string | No | Video rotation direction, in degrees.| 259| hdrType<sup>12+</sup> | [HdrType](arkts-apis-media-e.md#hdrtype12) | No | HDR type of the media asset. This parameter is read-only in the current version.| 260| location<sup>12+</sup> | [Location](#location) | No| Geographical location of the media asset.| 261| customInfo<sup>12+</sup> | Record<string, string> | No| Custom key-value mappings obtained from **moov.meta.list**.| 262| tracks<sup>20+</sup> | Array\<[MediaDescription](#mediadescription8)> | No| Track information of the media asset. This parameter is read-only in the current version.| 263 264### Description of MediaDescriptionKey supported by AVMetadata.tracks 265 266The following table lists the values of [MediaDescriptionKey](arkts-apis-media-e.md#mediadescriptionkey8) supported by AVMetadata.tracks. 267 268| Name | Value | Applicable Track Type | 269| -------- | --------------------|------------------------ | 270| MD_KEY_TRACK_INDEX | 'track_index' | All| 271| MD_KEY_TRACK_TYPE | 'track_type' | All| 272| MD_KEY_CODEC_MIME | 'codec_mime' | Audio and video| 273| MD_KEY_WIDTH | 'width' | Video| 274| MD_KEY_HEIGHT | 'height' | Video| 275| MD_KEY_FRAME_RATE | 'frame_rate' | Video| 276| MD_KEY_AUD_CHANNEL_COUNT | 'channel_count' | Audio| 277| MD_KEY_AUD_SAMPLE_RATE | 'sample_rate' | Audio| 278| MD_KEY_HDR_TYPE | 'hdr_type' | Video| 279 280## PixelMapParams<sup>12+</sup> 281 282Defines the format parameters of the video thumbnail to be obtained. 283 284**System capability**: SystemCapability.Multimedia.Media.AVImageGenerator 285 286| Name | Type | Readable| Writable| Description | 287|--------|--------|------|------|---------------------------------------------------------------------------------| 288| width | number | Yes | Yes | Width of the thumbnail. The value must be greater than 0 and less than or equal to the width of the original video. Otherwise, the returned thumbnail will not be scaled.| 289| height | number | Yes | Yes | Height of the thumbnail. The value must be greater than 0 and less than or equal to the height of the original video. Otherwise, the returned thumbnail will not be scaled.| 290 291## OutputSize<sup>20+</sup> 292 293Describes the output size of the video thumbnail fetched. 294 295**System capability**: SystemCapability.Multimedia.Media.AVImageGenerator 296 297| Name | Type | Read-Only| Optional| Description | 298| ------ | ------ | ---- | ---- | ------------------------------------------------------------ | 299| width | number | No | Yes | Width of the thumbnail.<br>- If this parameter is set to a value less than 0, the width will be the original video width.<br>- If the value is **0** or is not assigned, the scaling ratio is the same as the height ratio.<br>- If neither width nor height is assigned, the output is the width and height of the original video frame.| 300| height | number | No | Yes | Height of the thumbnail.<br>- If this parameter is set to a value less than 0, the height will be the original video height.<br>- If the value is **0** or is not assigned, the scaling ratio is the same as the width ratio.<br>- If neither width nor height is assigned, the output is the width and height of the original video frame.| 301 302## MediaStream<sup>19+</sup> 303 304Defines the media stream data information. 305 306**Atomic service API**: This API can be used in atomic services since API version 19. 307 308**System capability**: SystemCapability.Multimedia.Media.Core 309 310| Name | Type | Read-Only| Optional| Description | 311| ------- | ------ | ---- | ---- | ------------------------------------------------------------ | 312| url | string | No | No | URL of the media resource. Only HTTP and HTTPS are supported. | 313| width | number | No | No | Video width of the media resource. If the video width is unknown, set it to **0**. In this case, [PlaybackStrategy](#playbackstrategy12) cannot be used for optimal matching.| 314| height | number | No | No | Video height of the media resource. If the video width is unknown, set it to **0**. In this case, [PlaybackStrategy](#playbackstrategy12) cannot be used for optimal matching.| 315| bitrate | number | No | No | Bit rate of media resources, in bit/s. | 316 317## MediaSourceLoader<sup>18+</sup> 318 319Defines a media data loader, which needs to be implemented by applications. 320 321**Atomic service API**: This API can be used in atomic services since API version 18. 322 323**System capability**: SystemCapability.Multimedia.Media.Core 324 325| Name | Type | Mandatory| Description | 326| -------- | -------- | ---- | -------------------- | 327| open | [SourceOpenCallback](arkts-apis-media-t.md#sourceopencallback18) | Yes | Callback function implemented by applications to handle resource open requests.| 328| read | [SourceReadCallback](arkts-apis-media-t.md#sourcereadcallback18) | Yes | Callback function implemented by applications to handle resource read requests.| 329| close | [SourceCloseCallback](arkts-apis-media-t.md#sourceclosecallback18) | Yes | Callback function implemented by applications to handle resource close requests.| 330 331**Example** 332 333```ts 334import HashMap from '@ohos.util.HashMap'; 335 336let headers: Record<string, string> = {"User-Agent" : "User-Agent-Value"}; 337let mediaSource : media.MediaSource = media.createMediaSourceWithUrl("http://xxx", headers); 338let uuid: number = 1; 339let requests: HashMap<number, media.MediaSourceLoadingRequest> = new HashMap(); 340let mediaSourceLoader: media.MediaSourceLoader = { 341 open: (request: media.MediaSourceLoadingRequest) => { 342 console.log(`Opening resource: ${request.url}`); 343 // Open the resource and return a unique handle, ensuring the mapping between the UUID and request. 344 uuid += 1; 345 requests.set(uuid, request); 346 return uuid; 347 }, 348 read: (uuid: number, requestedOffset: number, requestedLength: number) => { 349 console.log(`Reading resource with handle ${uuid}, offset: ${requestedOffset}, length: ${requestedLength}`); 350 // Check whether the UUID is valid and store the read request. Avoid blocking the request while pushing data and header information. 351 }, 352 close: (uuid: number) => { 353 console.log(`Closing resource with handle ${uuid}`); 354 // Clear resources related to the current UUID. 355 requests.remove(uuid); 356 } 357}; 358 359mediaSource.setMediaResourceLoaderDelegate(mediaSourceLoader); 360let playStrategy : media.PlaybackStrategy = { 361 preferredBufferDuration: 20, 362}; 363 364async function setupPlayer() { 365 let player = await media.createAVPlayer(); 366 player.setMediaSource(mediaSource, playStrategy); 367} 368``` 369 370## PlaybackStrategy<sup>12+</sup> 371 372Describes the playback strategy. 373 374**System capability**: SystemCapability.Multimedia.Media.Core 375 376| Name | Type | Mandatory| Description | 377| -------- | -------- | ---- | -------------------- | 378| preferredWidth| number | No | Preferred width, in px. The value is an integer greater than 0, for example, 1080.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 379| preferredHeight | number | No | Preferred height, in px. The value is an integer greater than 0, for example, 1920.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 380| preferredBufferDuration | number | No | Preferred buffer duration, in seconds. The value ranges from 1 to 20.<br>For details, see [Minimizing Stuttering in Online Video Playback](https://developer.huawei.com/consumer/en/doc/best-practices/bpta-online-video-playback-lags-practice).<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 381| preferredHdr | boolean | No | Whether HDR is preferred. **true** if preferred, **false** otherwise. The default value is **false**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 382| enableSuperResolution<sup>18+</sup> | boolean | No | Whether to enable super resolution. **true** to enable, **false** otherwise. The default value is **false**.<br>If super resolution is disabled, super resolution APIs cannot be called. If super resolution is enabled, the default target resolution is 1920 x 1080, in px.<br>**Atomic service API**: This API can be used in atomic services since API version 18.| 383| showFirstFrameOnPrepare<sup>17+</sup> | boolean | No | Whether to show the first frame after **prepare** is called. **true** to show, **false** otherwise. The default value is **false**.<br>**Atomic service API**: This API can be used in atomic services since API version 17.| 384| mutedMediaType | [MediaType](arkts-apis-media-e.md#mediatype8) | No| Type of the media to mute.<br>From API version 12 to 19, only **MediaType.MEDIA_TYPE_AUD** can be set. Starting from API version 20, **MediaType.MEDIA_TYPE_VID** is added.| 385| preferredAudioLanguage<sup>13+</sup> | string | No| Preferred audio track language. Set this parameter based on service requirements in DASH scenarios. In non-DASH scenarios, this parameter is not supported, and you are advised to retain the default value.<br>**Atomic service API**: This API can be used in atomic services since API version 13.| 386| preferredSubtitleLanguage<sup>13+</sup> | string | No| Preferred subtitle language. Set this parameter based on service requirements in DASH scenarios. In non-DASH scenarios, this parameter is not supported, and you are advised to retain the default value.<br>**Atomic service API**: This API can be used in atomic services since API version 13.| 387| preferredBufferDurationForPlaying<sup>18+</sup> | number | No| Preferred buffer duration for playback. The playback starts once the buffering time exceeds this value. The value ranges from 0 to 20, in seconds.<br>**Atomic service API**: This API can be used in atomic services since API version 18.| 388| thresholdForAutoQuickPlay<sup>18+</sup> | number | No| Thread for starting smart frame catching, in seconds. The value must be greater than or equal to 2s and greater than **preferredBufferDurationForPlaying**. The default value is 5s.<br>You can use the playback strategy to maintain the real-time quality of live streams by adjusting the smart frame-catch threshold. For FLV live streams, you can set this parameter based on service requirements. This parameter is not supported for non-FLV live streams yet. Fluctuations in network conditions can cause the player to build up a lot of data over time. The player periodically checks the gap between the current playback time and the timestamp of the latest frame in the cache. If this gap is too big, the player starts catching up at 1.2x speed. The [speedDone](arkts-apis-media-AVPlayer.md#onspeeddone9) event is invoked with a value of 100, indicating that smart frame catching has started successfully. Once the gap falls below **preferredBufferDurationForPlaying**, the player stops catching up and resumes the normal playback speed.<br>**Atomic service API**: This API can be used in atomic services since API version 18.| 389| keepDecodingOnMute<sup>20+</sup> | boolean | No| Whether the decoder continues to run when the video media is muted, which helps in quickly opening the media. Currently, this feature is available only for videos. The default value is **false**, indicating that the decoder stops running when the media is muted, reducing power consumption.<br>**Atomic service API**: This API can be used in atomic services since API version 20.| 390 391## AVScreenCaptureStrategy<sup>20+</sup> 392 393Describes the screen capture strategy. 394 395**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture 396 397| Name | Type | Read-Only| Optional| Description | 398| --------------------- | ------- | --- | --- | -------------------- | 399| keepCaptureDuringCall | boolean | No| Yes | Whether to keep screen capture during a cellular call.| 400| enableBFrame | boolean | No| Yes| Whether to enable B-frame encoding for screen capture. **true** to enable, **false** otherwise. The default value is **false**.<br>For details about the restrictions on B-frame video encoding, see [Constraints in B-Frame Video Encoding](../../media/avcodec/video-encoding-b-frame.md#constraints). If the current environment does not meet the restrictions, B-frames will be skipped during screen capture, and no error will be returned.| 401 402## AVScreenCaptureRecordConfig<sup>12+</sup> 403 404Defines the screen capture parameters. 405 406**System capability**: SystemCapability.Multimedia.Media.AVScreenCapture 407 408| Name | Type | Mandatory| Description | 409| ----------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 410| fd | number | Yes | FD of the file output. | 411| frameWidth | number | No | Video width, in px. The default value varies according to the display in use.| 412| frameHeight | number | No | Video height, in px. The default value varies according to the display in use.| 413| videoBitrate | number | No | Video bit rate. The default value is **10000000**. | 414| audioSampleRate | number | No | Audio sample rate. This value is used for both internal capture and external capture (using microphones). Only **48000** (default value) and **16000** are supported.| 415| audioChannelCount | number | No | Audio channel count. This value is used for both internal capture and external capture (using microphones). Only **1** and **2** (default) are supported.| 416| audioBitrate | number | No | Audio bit rate. This value is used for both internal capture and external capture (using microphones). The default value is **96000**.| 417| preset | [AVScreenCaptureRecordPreset](arkts-apis-media-e.md#avscreencapturerecordpreset12) | No | Encoding and container format used. The default value is **SCREEN_RECORD_PRESET_H264_AAC_MP4**.| 418| displayId<sup>15+</sup> | number | No | ID of the display used for screen capture. By default, the main screen is captured.| 419| fillMode<sup>18+</sup> | [AVScreenCaptureFillMode](arkts-apis-media-e.md#avscreencapturefillmode18)| No | Video fill mode during screen capture.| 420| strategy<sup>20+</sup> | [AVScreenCaptureStrategy](#avscreencapturestrategy20)| No | Screen capture strategy.| 421 422## AudioRecorderConfig<sup>(deprecated)</sup> 423 424> **NOTE** 425> 426> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [AVRecorderConfig](#avrecorderconfig9) instead. 427 428Describes audio recording configurations. 429 430**System capability**: SystemCapability.Multimedia.Media.AudioRecorder 431 432| Name | Type | Mandatory| Description | 433| ----------------------------------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | 434| audioEncoder | [AudioEncoder](arkts-apis-media-e.md#audioencoderdeprecated) | No | Audio encoding format. The default value is **AAC_LC**.<br>Note: This parameter is supported since API version 6 and deprecated since API version 8. You are advised to use **audioEncoderMime** instead.| 435| audioEncodeBitRate | number | No | Audio encoding bit rate. The default value is **48000**.<br>Note: This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use **audioBitrate** in [AVRecorderProfile](#avrecorderprofile9) instead.| 436| audioSampleRate | number | No | Audio sample rate. The default value is **48000**.<br>Variable bit rate. The bit rate is for reference only.<br>Note: This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use **audioSampleRate** in [AVRecorderProfile](#avrecorderprofile9) instead.| 437| numberOfChannels | number | No | Audio channel count. The default value is **2**.<br>Note: This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use **audioChannels** in [AVRecorderProfile](#avrecorderprofile9) instead.| 438| format | [AudioOutputFormat](arkts-apis-media-e.md#audiooutputformatdeprecated) | No | Audio output format. The default value is **MPEG_4**.<br>Note: This parameter is supported since API version 6 and deprecated since API version 8. You are advised to use **fileFormat** instead.| 439| location | [Location](#location) | No | Geographical location of the recorded audio.<br>Note: This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use **location** in [AVMetadata](#avmetadata11) instead.| 440| uri | string | Yes | Audio output URI. Supported: fd://xx (fd number)<br> <br>The file must be created by the caller and granted with proper permissions.<br>Note: This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use **url** in [AVRecorderConfig](#avrecorderconfig9) instead.| 441| audioEncoderMime<sup>8+</sup> | [CodecMimeType](arkts-apis-media-e.md#codecmimetype8) | No | Container encoding format.<br>Note: This parameter is supported since API version 8 and deprecated since API version 9. You are advised to use **audioCodec** in [AVRecorderProfile](#avrecorderprofile9) instead.| 442| fileFormat<sup>8+</sup> | [ContainerFormatType](arkts-apis-media-e.md#containerformattype8) | No | Audio encoding format.<br>Note: This parameter is supported since API version 8 and deprecated since API version 9. You are advised to use **fileFormat** in [AVRecorderProfile](#avrecorderprofile9) instead.| 443