1# MediaAssetManager 2 3 4## Overview 5 6Provides APIs for requesting media library assets. 7 8**Since**: 12 9 10 11## Summary 12 13 14### Files 15 16| Name| Description| 17| -------- | -------- | 18| [media_access_helper_capi.h](media__access__helper__capi_8h.md) | Defines the APIs for album management.| 19| [media_asset_base_capi.h](media__asset__base__capi_8h.md) | Defines the structs and enums of the media asset manager.| 20| [media_asset_capi.h](media__asset__capi_8h.md) | Defines the APIs related to media assets. | 21| [media_asset_change_request_capi.h](media__asset__change__request__capi_8h.md) | Defines the APIs related to media asset change requests. | 22| [media_asset_manager_capi.h](media__asset__manager__capi_8h.md) | Defines the functions of the media asset manager.| 23 24 25### Structs 26 27| Name| Description| 28| -------- | -------- | 29| struct [MediaLibrary_RequestId](_media_library___request_id.md) | Defines a request ID.| 30| struct [MediaLibrary_RequestOptions](_media_library___request_options.md) | Defines the options related to the media asset quality and delivery mode to set.| 31 32 33### Types 34 35| Name| Description| 36| -------- | -------- | 37| typedef struct [OH_MediaAssetManager](#oh_mediaassetmanager) [OH_MediaAssetManager](#oh_mediaassetmanager) | Defines a struct for the media asset manager.| 38| typedef struct [OH_MediaAssetChangeRequest](#oh_mediaassetchangerequest) [OH_MediaAssetChangeRequest](#oh_mediaassetchangerequest) | Defines a struct for a media asset change request.| 39| typedef struct [OH_MediaAsset](#oh_mediaasset) [OH_MediaAsset](#oh_mediaasset) | Defines a struct for a media asset.| 40| typedef struct [MediaLibrary_RequestId](_media_library___request_id.md) [MediaLibrary_RequestId](#medialibrary_requestid) | Defines a struct for a request ID. | 41| typedef enum [MediaLibrary_ErrorCode](#medialibrary_errorcode-1) [MediaLibrary_ErrorCode](#medialibrary_errorcode) | Defines an enum for error codes.| 42| typedef enum [MediaLibrary_DeliveryMode](#medialibrary_deliverymode-1) [MediaLibrary_DeliveryMode](#medialibrary_deliverymode) | Defines an enum for delivery modes of the requested media asset.| 43| typedef struct [MediaLibrary_RequestOptions](_media_library___request_options.md) [MediaLibrary_RequestOptions](#medialibrary_requestoptions) | Defines an enum for options related to the media asset quality and delivery mode to set.| 44| typedef enum [MediaLibrary_MediaType](#medialibrary_mediatype-1) [MediaLibrary_MediaType](#medialibrary_mediatype) | Defines an enum for media types.| 45| typedef enum [MediaLibrary_MediaSubType](#medialibrary_mediasubtype-1) [MediaLibrary_MediaSubType](#medialibrary_mediasubtype) | Defines an enum for media subtypes.| 46| typedef enum [MediaLibrary_ResourceType](#medialibrary_resourcetype-1) [MediaLibrary_ResourceType](#medialibrary_resourcetype) | Defines an enum for media library resource types.| 47| typedef enum [MediaLibrary_ImageFileType](#medialibrary_imagefiletype-1) [MediaLibrary_ImageFileType](#medialibrary_imagefiletype) | Defines an enum for image file types.| 48| typedef enum [MediaLibrary_MediaQuality](#medialibrary_mediaquality-1) [MediaLibrary_MediaQuality](#medialibrary_mediaquality) | Defines an enum for media resource quality.| 49| typedef enum [MediaLibrary_MediaContentType](#medialibrary_mediacontenttype-1) [MediaLibrary_MediaContentType](#medialibrary_mediacontenttype) | Defines an enum for media content types.| 50| typedef void(\* [OH_MediaLibrary_OnDataPrepared](#oh_medialibrary_ondataprepared)) (int32_t result, [MediaLibrary_RequestId](_media_library___request_id.md) requestId) | Defines a function pointer to the callback to be invoked when the requested media asset is ready. | 51| typedef void(\* [OH_MediaLibrary_OnImageDataPrepared](#oh_medialibrary_onimagedataprepared)) ([MediaLibrary_ErrorCode](#medialibrary_errorcode) result, [MediaLibrary_RequestId](_media_library___request_id.md) requestId, [MediaLibrary_MediaQuality](#medialibrary_mediaquality) mediaQuality, [MediaLibrary_MediaContentType](#medialibrary_mediacontenttype) type, OH_ImageSourceNative \*imageSourceNative) | Defines a function pointer to the callback to be invoked when the requested image is ready.| 52 53 54### Enums 55 56| Name| Description| 57| -------- | -------- | 58| [MediaLibrary_ErrorCode](#medialibrary_errorcode-1) {<br>MEDIA_LIBRARY_OK = 0,<br>MEDIA_LIBRARY_PERMISSION_DENIED = 201,<br>MEDIA_LIBRARY_PARAMETER_ERROR = 401,<br>MEDIA_LIBRARY_NO_SUCH_FILE = 23800101,<br>MEDIA_LIBRARY_INVALID_DISPLAY_NAME = 23800102,<br>MEDIA_LIBRARY_INVALID_ASSET_URI = 23800103,<br>MEDIA_LIBRARY_INVALID_PHOTO_KEY = 23800104,<br>MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED = 23800201,<br>MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR = 23800301<br>} | Enumerates the error codes.| 59| [MediaLibrary_DeliveryMode](#medialibrary_deliverymode-1) {<br>MEDIA_LIBRARY_FAST_MODE = 0,<br>MEDIA_LIBRARY_HIGH_QUALITY_MODE = 1,<br>MEDIA_LIBRARY_BALANCED_MODE = 2 } | Enumerates the delivery modes of the requested media asset.| 60| [MediaLibrary_MediaType](#medialibrary_mediatype-1) {<br>MEDIA_LIBRARY_IMAGE = 1,<br>MEDIA_LIBRARY_VIDEO = 2 } | Enumerates the media types.| 61| [MediaLibrary_MediaSubType](#medialibrary_mediasubtype-1) {<br>MEDIA_LIBRARY_DEFAULT = 0,<br>MEDIA_LIBRARY_MOVING_PHOTO = 3,<br>MEDIA_LIBRARY_BURST = 4 } | Enumerates the media subtypes.| 62| [MediaLibrary_ResourceType](#medialibrary_resourcetype-1) {<br>MEDIA_LIBRARY_IMAGE_RESOURCE = 1,<br>MEDIA_LIBRARY_VIDEO_RESOURCE = 2 } | Enumerates the media library resource types.| 63| [MediaLibrary_ImageFileType](#medialibrary_imagefiletype-1) {<br>MEDIA_LIBRARY_IMAGE_JPEG = 1 } | Enumerates the image file types.| 64| [MediaLibrary_MediaQuality](#medialibrary_mediaquality-1) {<br>MEDIA_LIBRARY_QUALITY_FAST = 1,<br>MEDIA_LIBRARY_QUALITY_FULL = 2 } | Enumerates the media resource quality.| 65| [MediaLibrary_MediaContentType](#medialibrary_mediacontenttype-1) {<br>MEDIA_LIBRARY_COMPRESSED = 1,<br>MEDIA_LIBRARY_PICTURE_OBJECT = 2 } | Enumerates the media content types.| 66 67 68### Functions 69 70| Name| Description| 71| -------- | -------- | 72| [MediaLibrary_ErrorCode](#medialibrary_errorcode) [OH_MediaAccessHelper_ApplyChanges](#oh_mediaaccesshelper_applychanges) ([OH_MediaAssetChangeRequest](#oh_mediaassetchangerequest) \*changeRequest) | Applies changes to an asset or album.| 73| [MediaLibrary_ErrorCode](#medialibrary_errorcode) [OH_MediaAsset_GetUri](#oh_mediaasset_geturi) ([OH_MediaAsset](#oh_mediaasset) \*mediaAsset, const char \*\*uri) | Obtains the URI of a media asset.| 74| [MediaLibrary_ErrorCode](#medialibrary_errorcode) [OH_MediaAsset_GetDisplayName](#oh_mediaasset_getdisplayname) ([OH_MediaAsset](#oh_mediaasset) \*mediaAsset, const char \*\*displayName) | Obtains the displayed name of a media asset.| 75| [MediaLibrary_ErrorCode](#medialibrary_errorcode) [OH_MediaAsset_GetSize](#oh_mediaasset_getsize) ([OH_MediaAsset](#oh_mediaasset) \*mediaAsset, uint32_t \*size) | Obtains the size of a media asset file.| 76| [MediaLibrary_ErrorCode](#medialibrary_errorcode) [OH_MediaAsset_GetDateModifiedMs](#oh_mediaasset_getdatemodifiedms) ([OH_MediaAsset](#oh_mediaasset) \*mediaAsset, uint32_t \*dateModifiedMs) | Obtains the media asset modification time, in ms.| 77| [MediaLibrary_ErrorCode](#medialibrary_errorcode) [OH_MediaAsset_GetWidth](#oh_mediaasset_getwidth) ([OH_MediaAsset](#oh_mediaasset) \*mediaAsset, uint32_t \*width) | Obtains the image width (in pixels) of a media asset.| 78| [MediaLibrary_ErrorCode](#medialibrary_errorcode) [OH_MediaAsset_GetHeight](#oh_mediaasset_getheight) ([OH_MediaAsset](#oh_mediaasset) \*mediaAsset, uint32_t \*height) | Obtains the image height (in pixels) of a media asset.| 79| [MediaLibrary_ErrorCode](#medialibrary_errorcode) [OH_MediaAsset_GetOrientation](#oh_mediaasset_getorientation) ([OH_MediaAsset](#oh_mediaasset) \*mediaAsset, uint32_t \*orientation) | Obtains the orientation of a media asset, in degrees.| 80| [MediaLibrary_ErrorCode](#medialibrary_errorcode) [OH_MediaAsset_Release](#oh_mediaasset_release) ([OH_MediaAsset](#oh_mediaasset) \*mediaAsset) | Releases a media asset.| 81| [OH_MediaAssetChangeRequest](#oh_mediaassetchangerequest) \* [OH_MediaAssetChangeRequest_Create](#oh_mediaassetchangerequest_create) ([OH_MediaAsset](#oh_mediaasset) \*mediaAsset) | Creates an [OH_MediaAssetChangeRequest](#oh_mediaassetchangerequest) instance.| 82| [MediaLibrary_ErrorCode](#medialibrary_errorcode) [OH_MediaAssetChangeRequest_AddResourceWithBuffer](#oh_mediaassetchangerequest_addresourcewithbuffer) ([OH_MediaAssetChangeRequest](#oh_mediaassetchangerequest) \*changeRequest, [MediaLibrary_ResourceType](#medialibrary_resourcetype) resourceType, uint8_t \*buffer, uint32_t length) | Adds a resource using **ArrayBuffer** data.| 83| [MediaLibrary_ErrorCode](#medialibrary_errorcode) [OH_MediaAssetChangeRequest_SaveCameraPhoto](#oh_mediaassetchangerequest_savecameraphoto) ([OH_MediaAssetChangeRequest](#oh_mediaassetchangerequest) \*changeRequest, [MediaLibrary_ImageFileType](#medialibrary_imagefiletype) imageFileType) | Saves the photo taken by the camera.| 84| [MediaLibrary_ErrorCode](#medialibrary_errorcode) [OH_MediaAssetChangeRequest_DiscardCameraPhoto](#oh_mediaassetchangerequest_discardcameraphoto) ([OH_MediaAssetChangeRequest](#oh_mediaassetchangerequest) \*changeRequest) | Discards the photo taken by the camera.| 85| [MediaLibrary_ErrorCode](#medialibrary_errorcode) [OH_MediaAssetChangeRequest_Release](#oh_mediaassetchangerequest_release) ([OH_MediaAssetChangeRequest](#oh_mediaassetchangerequest) \*changeRequest) | Releases an [OH_MediaAssetChangeRequest](#oh_mediaassetchangerequest) instance.| 86| [OH_MediaAssetManager](#oh_mediaassetmanager) \* [OH_MediaAssetManager_Create](#oh_mediaassetmanager_create) (void) | Creates a **MediaAssetManager** instance.| 87| [MediaLibrary_RequestId](_media_library___request_id.md) [OH_MediaAssetManager_RequestImageForPath](#oh_mediaassetmanager_requestimageforpath) ([OH_MediaAssetManager](#oh_mediaassetmanager) \*manager, const char \*uri, [MediaLibrary_RequestOptions](_media_library___request_options.md) requestOptions, const char \*destPath, [OH_MediaLibrary_OnDataPrepared](#oh_medialibrary_ondataprepared) callback) | Requests an image in the specified directory.| 88| [MediaLibrary_RequestId](_media_library___request_id.md) [OH_MediaAssetManager_RequestVideoForPath](#oh_mediaassetmanager_requestvideoforpath) ([OH_MediaAssetManager](#oh_mediaassetmanager) \*manager, const char \*uri, [MediaLibrary_RequestOptions](_media_library___request_options.md) requestOptions, const char \*destPath, [OH_MediaLibrary_OnDataPrepared](#oh_medialibrary_ondataprepared) callback) | Requests a video in the specified directory.| 89| bool [OH_MediaAssetManager_CancelRequest](#oh_mediaassetmanager_cancelrequest) ([OH_MediaAssetManager](#oh_mediaassetmanager) \*manager, const [MediaLibrary_RequestId](_media_library___request_id.md) requestId) | Cancels a request based on the request ID.| 90| [MediaLibrary_ErrorCode](#medialibrary_errorcode) [OH_MediaAssetManager_RequestImage](#oh_mediaassetmanager_requestimage) ([OH_MediaAssetManager](#oh_mediaassetmanager) \*manager, [OH_MediaAsset](#oh_mediaasset) \*mediaAsset, [MediaLibrary_RequestOptions](_media_library___request_options.md) requestOptions, [MediaLibrary_RequestId](_media_library___request_id.md) \*requestId, [OH_MediaLibrary_OnImageDataPrepared](#oh_medialibrary_onimagedataprepared) callback) | Requests an image.| 91 92 93## Type Description 94 95 96### MediaLibrary_DeliveryMode 97 98``` 99typedef enum MediaLibrary_DeliveryMode MediaLibrary_DeliveryMode 100``` 101 102**Description** 103 104Defines an enum for delivery modes of the requested media asset. 105 106The delivery modes include the following: 107 108- **MEDIA_LIBRARY_FAST_MODE**: deliver the media asset available without considering its quality. 109 110- **MEDIA_LIBRARY_HIGH_QUALITY_MODE**: deliver a media asset with high quality. If there is no high-quality asset available, trigger the process for creating a high-quality asset. Then, return the high-quality asset that is successfully created. 111 112- **MEDIA_LIBRARY_BALANCED_MODE**: return the high-quality asset if there is any. Otherwise, return a low-quality asset first and trigger the process for creating a high-quality asset. Then, return the high-quality asset that is successfully created. 113 114**Since**: 12 115 116 117### MediaLibrary_ErrorCode 118 119``` 120typedef enum MediaLibrary_ErrorCode MediaLibrary_ErrorCode 121``` 122 123**Description** 124 125Defines an enum for error codes. 126 127**Since**: 12 128 129 130### MediaLibrary_ImageFileType 131 132``` 133typedef enum MediaLibrary_ImageFileType MediaLibrary_ImageFileType 134``` 135 136**Description** 137 138Defines an enum for image file types. 139 140**Since**: 12 141 142 143### MediaLibrary_MediaContentType 144 145``` 146typedef enum MediaLibrary_MediaContentType MediaLibrary_MediaContentType 147``` 148 149**Description** 150 151Defines an enum for media content types. 152 153**Since**: 12 154 155 156### MediaLibrary_MediaQuality 157 158``` 159typedef enum MediaLibrary_MediaQuality MediaLibrary_MediaQuality 160``` 161 162**Description** 163 164Defines an enum for media resource quality, which 165 166varies with the specified delivery mode for the requested media asset. 167 168- **MEDIA_LIBRARY_FAST_MODE**: deliver the media asset available without considering its quality. 169 170- **MEDIA_LIBRARY_HIGH_QUALITY_MODE**: deliver a media asset with high quality. If there is no high-quality asset available, trigger the process for creating a high-quality asset. Then, return the high-quality asset that is successfully created. 171 172- **MEDIA_LIBRARY_BALANCED_MODE**: return the high-quality asset if there is any. Otherwise, return a low-quality asset first and trigger the process for creating a high-quality asset. Then, return the high-quality asset that is successfully created. 173 174**Since**: 12 175 176 177### MediaLibrary_MediaSubType 178 179``` 180typedef enum MediaLibrary_MediaSubType MediaLibrary_MediaSubType 181``` 182 183**Description** 184 185Define an enum for media subtypes. 186 187**Since**: 12 188 189 190### MediaLibrary_MediaType 191 192``` 193typedef enum MediaLibrary_MediaType MediaLibrary_MediaType 194``` 195 196**Description** 197 198Define an enum for media types. 199 200**Since**: 12 201 202 203### MediaLibrary_RequestId 204 205``` 206typedef struct MediaLibrary_RequestId MediaLibrary_RequestId 207``` 208 209**Description** 210 211Defines a request ID. 212 213A value of this type is returned when a media asset is requested. The request ID can be used to cancel a request. If a request fails, an all-zero value, for example, **00000000-0000-0000-0000-000000000000** is returned. 214 215**Since**: 12 216 217 218### MediaLibrary_RequestOptions 219 220``` 221typedef struct MediaLibrary_RequestOptions MediaLibrary_RequestOptions 222``` 223 224**Description** 225 226Defines how media assets are requested and processed. 227 228You can use this struct to set options related to the media asset quality, delivery mode, and more. 229 230**Since**: 12 231 232 233### MediaLibrary_ResourceType 234 235``` 236typedef enum MediaLibrary_ResourceType MediaLibrary_ResourceType 237``` 238 239**Description** 240 241Define an enum for media library resource types. 242 243**Since**: 12 244 245 246### OH_MediaAsset 247 248``` 249typedef struct OH_MediaAsset OH_MediaAsset 250``` 251 252**Description** 253 254Defines a struct for a media asset. 255 256This struct provides the capability of encapsulating media file attributes. 257 258**Since**: 12 259 260 261### OH_MediaAssetChangeRequest 262 263``` 264typedef struct OH_MediaAssetChangeRequest OH_MediaAssetChangeRequest 265``` 266 267**Description** 268 269Defines a struct for a media asset change request. 270 271This struct provides the capability of handling media asset change requests. 272 273**Since**: 12 274 275 276### OH_MediaAssetManager 277 278``` 279typedef struct OH_MediaAssetManager OH_MediaAssetManager 280``` 281 282**Description** 283 284Defines a struct for the media asset manager. 285 286You can use this struct to create a media asset manager instance. If the creation fails, a null pointer is returned. 287 288**Since**: 12 289 290 291### OH_MediaLibrary_OnDataPrepared 292 293``` 294typedef void (*OH_MediaLibrary_OnDataPrepared)(int32_t result, MediaLibrary_RequestId requestId) 295``` 296 297**Description** 298 299Defines a function pointer to the callback to be invoked when the requested media asset is ready. 300 301**Since**: 12 302 303**Parameters** 304 305| Name| Description| 306| -------- | -------- | 307| result | Processing result of the requested asset.| 308| requestId | Request ID.| 309 310 311### OH_MediaLibrary_OnImageDataPrepared 312 313``` 314typedef void (*OH_MediaLibrary_OnImageDataPrepared)(MediaLibrary_ErrorCode result, MediaLibrary_RequestId requestId, MediaLibrary_MediaQuality mediaQuality, MediaLibrary_MediaContentType type, OH_ImageSourceNative* imageSourceNative) 315``` 316 317**Description** 318 319Defines a function pointer to the callback to be invoked when the requested image is ready. 320 321This callback is called when the requested image source is ready. 322 323**Since**: 12 324 325**Parameters** 326 327| Name| Description| 328| -------- | -------- | 329| result | [MediaLibrary_ErrorCode](#medialibrary_errorcode-1).| 330| requestId | [MediaLibrary_RequestId](_media_library___request_id.md).| 331| mediaQuality | [MediaLibrary_MediaQuality](#medialibrary_mediaquality-1).| 332| type | [MediaLibrary_MediaContentType](#medialibrary_mediacontenttype-1).| 333| imageSourceNative | [OH_ImageSourceNative](../apis-image-kit/_image___native_module.md#oh_imagesourcenative) obtained when the requested image source is ready.| 334 335 336## Enum Description 337 338 339### MediaLibrary_DeliveryMode 340 341``` 342enum MediaLibrary_DeliveryMode 343``` 344 345**Description** 346 347Enumerates the delivery modes of the requested media asset. 348 349The delivery modes include the following: 350 351- **MEDIA_LIBRARY_FAST_MODE**: deliver the media asset available without considering its quality. 352 353- **MEDIA_LIBRARY_HIGH_QUALITY_MODE**: deliver a media asset with high quality. If there is no high-quality asset available, trigger the process for creating a high-quality asset. Then, return the high-quality asset that is successfully created. 354 355- **MEDIA_LIBRARY_BALANCED_MODE**: return the high-quality asset if there is any. Otherwise, return a low-quality asset first and trigger the process for creating a high-quality asset. Then, return the high-quality asset that is successfully created. 356 357**Since**: 12 358 359| Value| Description| 360| -------- | -------- | 361| MEDIA_LIBRARY_FAST_MODE | Fast mode.| 362| MEDIA_LIBRARY_HIGH_QUALITY_MODE | High-quality mode.| 363| MEDIA_LIBRARY_BALANCED_MODE | Balance mode.| 364 365 366### MediaLibrary_ErrorCode 367 368``` 369enum MediaLibrary_ErrorCode 370``` 371 372**Description** 373 374Enumerates the error codes. 375 376**Since**: 12 377 378| Value| Description| 379| -------- | -------- | 380| MEDIA_LIBRARY_OK | The operation is successful. | 381| MEDIA_LIBRARY_PERMISSION_DENIED | The permission is denied. | 382| MEDIA_LIBRARY_PARAMETER_ERROR | Mandatory parameter is not specified, the parameter type is incorrect, or parameter verification failed. | 383| MEDIA_LIBRARY_NO_SUCH_FILE | The file does not exist.| 384| MEDIA_LIBRARY_INVALID_DISPLAY_NAME | The name displayed is incorrect. | 385| MEDIA_LIBRARY_INVALID_ASSET_URI | The asset URI is invalid. | 386| MEDIA_LIBRARY_INVALID_PHOTO_KEY | **PhotoKey** is invalid. | 387| MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED | The operation is not supported. | 388| MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR | An internal system error is detected. Possible causes include the following:<br>1. Database corrupted.<br>2. File system error.<br>3. IPC request timed out. | 389 390 391### MediaLibrary_ImageFileType 392 393``` 394enum MediaLibrary_ImageFileType 395``` 396 397**Description** 398 399Enumerates the image file types. 400 401**Since**: 12 402 403| Value| Description| 404| -------- | -------- | 405| MEDIA_LIBRARY_IMAGE_JPEG | JPEG.| 406 407 408### MediaLibrary_MediaContentType 409 410``` 411enum MediaLibrary_MediaContentType 412``` 413 414**Description** 415 416Enumerates the media content types. 417 418**Since**: 12 419 420| Value| Description| 421| -------- | -------- | 422| MEDIA_LIBRARY_COMPRESSED | Compressed media content.| 423| MEDIA_LIBRARY_PICTURE_OBJECT | Image object.| 424 425 426### MediaLibrary_MediaQuality 427 428``` 429enum MediaLibrary_MediaQuality 430``` 431 432**Description** 433 434Enumerates the media resource quality, which varies with the specified delivery mode for the requested media asset. 435 436- **MEDIA_LIBRARY_FAST_MODE**: deliver the media asset available without considering its quality. 437 438- **MEDIA_LIBRARY_HIGH_QUALITY_MODE**: deliver a media asset with high quality. If there is no high-quality asset available, trigger the process for creating a high-quality asset. Then, return the high-quality asset that is successfully created. 439 440- **MEDIA_LIBRARY_BALANCED_MODE**: return the high-quality asset if there is any. Otherwise, return a low-quality asset first and trigger the process for creating a high-quality asset. Then, return the high-quality asset that is successfully created. 441 442**Since**: 12 443 444| Value| Description| 445| -------- | -------- | 446| MEDIA_LIBRARY_QUALITY_FAST | Media asset available without considering its quality.| 447| MEDIA_LIBRARY_QUALITY_FULL | High-quality media asset.| 448 449 450### MediaLibrary_MediaSubType 451 452``` 453enum MediaLibrary_MediaSubType 454``` 455 456**Description** 457 458Enumerates the media subtypes. 459 460**Since**: 12 461 462| Value| Description| 463| -------- | -------- | 464| MEDIA_LIBRARY_DEFAULT | Photo (default type).| 465| MEDIA_LIBRARY_MOVING_PHOTO | Moving photo.| 466| MEDIA_LIBRARY_BURST | Burst photo.| 467 468 469### MediaLibrary_MediaType 470 471``` 472enum MediaLibrary_MediaType 473``` 474 475**Description** 476 477Enumerates the media types. 478 479**Since**: 12 480 481| Value| Description| 482| -------- | -------- | 483| MEDIA_LIBRARY_IMAGE | Image.| 484| MEDIA_LIBRARY_VIDEO | Video.| 485 486 487### MediaLibrary_ResourceType 488 489``` 490enum MediaLibrary_ResourceType 491``` 492 493**Description** 494 495Enumerates the media library resource types. 496 497**Since**: 12 498 499| Value| Description| 500| -------- | -------- | 501| MEDIA_LIBRARY_IMAGE_RESOURCE | Image resource.| 502| MEDIA_LIBRARY_VIDEO_RESOURCE | Video resource.| 503 504 505## Function Description 506 507 508### OH_MediaAccessHelper_ApplyChanges() 509 510``` 511MediaLibrary_ErrorCode OH_MediaAccessHelper_ApplyChanges(OH_MediaAssetChangeRequest* changeRequest) 512``` 513 514**Description** 515 516Applies changes to an asset or album. 517 518**Since**: 12 519 520**Parameters** 521 522| Name| Description| 523| -------- | -------- | 524| changeRequest | Pointer to the [OH_MediaAssetChangeRequest](#oh_mediaassetchangerequest) instance. | 525 526**Required permissions** 527 528ohos.permission.WRITE_IMAGEVIDEO 529 530**Returns** 531 532[MediaLibrary_ErrorCode](#medialibrary_errorcode-1): 533 534- **MEDIA_LIBRARY_OK**: The operation is successful. 535 536- **MEDIA_LIBRARY_PARAMETER_ERROR**: Incorrect parameters. 537 Possible causes: 538 1. There is mandatory parameter that is not specified. 539 540 2. The parameter type is incorrect. 541 542 3. The parameter verification failed. 543 544- **MEDIA_LIBRARY_PERMISSION_DENIED**: The permission is denied. 545 546- **MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR**: An internal system error occurred. 547 548 549### OH_MediaAsset_GetDateModifiedMs() 550 551``` 552MediaLibrary_ErrorCode OH_MediaAsset_GetDateModifiedMs(OH_MediaAsset* mediaAsset, uint32_t* dateModifiedMs) 553``` 554 555**Description** 556 557Obtains the media asset modification time, in ms. 558 559**Since**: 12 560 561**Parameters** 562 563| Name| Description| 564| -------- | -------- | 565| mediaAsset | Pointer to the [OH_MediaAsset](#oh_mediaasset) instance.| 566| dateModifiedMs | Pointer to the asset modification time obtained, in ms. | 567 568**Returns** 569 570[MediaLibrary_ErrorCode](#medialibrary_errorcode-1): 571 572- **MEDIA_LIBRARY_OK**: The operation is successful. 573 574- **MEDIA_LIBRARY_PARAMETER_ERROR**: Incorrect parameters. 575 Possible causes: 576 1. There is mandatory parameter that is not specified. 577 578 2. The parameter type is incorrect. 579 580 3. The parameter verification failed. 581 582- **MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR**: An internal system error occurred. 583 584 585### OH_MediaAsset_GetDisplayName() 586 587``` 588MediaLibrary_ErrorCode OH_MediaAsset_GetDisplayName(OH_MediaAsset* mediaAsset, const char** displayName) 589``` 590 591**Description** 592 593Obtains the displayed name of a media asset. 594 595**Since**: 12 596 597**Parameters** 598 599| Name| Description| 600| -------- | -------- | 601| mediaAsset | Pointer to the [OH_MediaAsset](#oh_mediaasset) instance.| 602| displayName | Pointer to the displayed name obtained.| 603 604**Returns** 605 606[MediaLibrary_ErrorCode](#medialibrary_errorcode-1): 607- **MEDIA_LIBRARY_OK**: The operation is successful. 608 609- **MEDIA_LIBRARY_PARAMETER_ERROR**: Incorrect parameters. 610 Possible causes: 611 612 1. There is mandatory parameter that is not specified. 613 2. The parameter type is incorrect. 614 3. The parameter verification failed. 615 616- **MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR**: An internal system error occurred. 617 618 619### OH_MediaAsset_GetHeight() 620 621``` 622MediaLibrary_ErrorCode OH_MediaAsset_GetHeight(OH_MediaAsset* mediaAsset, uint32_t* height) 623``` 624 625**Description** 626 627Obtains the image height (in pixels) of a media asset. 628 629**Since**: 12 630 631**Parameters** 632 633| Name| Description| 634| -------- | -------- | 635| mediaAsset | Pointer to the [OH_MediaAsset](#oh_mediaasset) instance.| 636| height | Pointer to the image height of the media resource, in pixels.| 637 638**Returns** 639 640[MediaLibrary_ErrorCode](#medialibrary_errorcode-1): 641- **MEDIA_LIBRARY_OK**: The operation is successful. 642 643- **MEDIA_LIBRARY_PARAMETER_ERROR**: Incorrect parameters. 644 Possible causes: 645 646 1. There is mandatory parameter that is not specified. 647 2. The parameter type is incorrect. 648 3. The parameter verification failed. 649 650- **MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR**: An internal system error occurred. 651 652 653### OH_MediaAsset_GetOrientation() 654 655``` 656MediaLibrary_ErrorCode OH_MediaAsset_GetOrientation(OH_MediaAsset* mediaAsset, uint32_t* orientation) 657``` 658 659**Description** 660 661Obtains the orientation of a media asset, in degrees. 662 663**Since**: 12 664 665**Parameters** 666 667| Name| Description| 668| -------- | -------- | 669| mediaAsset | Pointer to the [OH_MediaAsset](#oh_mediaasset) instance.| 670| orientation | Pointer to the orientation of the image obtained, in degrees.| 671 672**Returns** 673 674[MediaLibrary_ErrorCode](#medialibrary_errorcode-1): 675- **MEDIA_LIBRARY_OK**: The operation is successful. 676 677- **MEDIA_LIBRARY_PARAMETER_ERROR**: Incorrect parameters. 678 Possible causes: 679 680 1. There is mandatory parameter that is not specified. 681 2. The parameter type is incorrect. 682 3. The parameter verification failed. 683 684- **MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR**: An internal system error occurred. 685 686 687### OH_MediaAsset_GetSize() 688 689``` 690MediaLibrary_ErrorCode OH_MediaAsset_GetSize(OH_MediaAsset* mediaAsset, uint32_t* size) 691``` 692 693**Description** 694 695Obtains the size of a media asset file. 696 697**Since**: 12 698 699**Parameters** 700 701| Name| Description| 702| -------- | -------- | 703| mediaAsset | Pointer to the [OH_MediaAsset](#oh_mediaasset) instance.| 704| size | Pointer to the file size obtained, in bytes.| 705 706**Returns** 707 708[MediaLibrary_ErrorCode](#medialibrary_errorcode-1): 709 710- **MEDIA_LIBRARY_OK**: The operation is successful. 711 712- **MEDIA_LIBRARY_PARAMETER_ERROR**: Incorrect parameters. 713 Possible causes: 714 715 1. There is mandatory parameter that is not specified. 716 2. The parameter type is incorrect. 717 3. The parameter verification failed. 718 719- **MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR**: An internal system error occurred. 720 721 722### OH_MediaAsset_GetUri() 723 724``` 725MediaLibrary_ErrorCode OH_MediaAsset_GetUri(OH_MediaAsset* mediaAsset, const char** uri) 726``` 727 728**Description** 729 730Obtains the URI of a media asset. 731 732**Since**: 12 733 734**Parameters** 735 736| Name| Description| 737| -------- | -------- | 738| mediaAsset | Pointer to the [OH_MediaAsset](#oh_mediaasset) instance.| 739| uri | Pointer to the URI obtained.| 740 741**Returns** 742 743[MediaLibrary_ErrorCode](#medialibrary_errorcode-1): 744 745- **MEDIA_LIBRARY_OK**: The operation is successful. 746 747- **MEDIA_LIBRARY_PARAMETER_ERROR**: Incorrect parameters. 748 Possible causes: 749 750 1. There is mandatory parameter that is not specified. 751 2. The parameter type is incorrect. 752 3. The parameter verification failed. 753 754- **MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR**: An internal system error occurred. 755 756 757### OH_MediaAsset_GetWidth() 758 759``` 760MediaLibrary_ErrorCode OH_MediaAsset_GetWidth(OH_MediaAsset* mediaAsset, uint32_t* width) 761``` 762 763**Description** 764 765Obtains the image width (in pixels) of a media asset. 766 767**Since**: 12 768 769**Parameters** 770 771| Name| Description| 772| -------- | -------- | 773| mediaAsset | Pointer to the [OH_MediaAsset](#oh_mediaasset) instance.| 774| width | Pointer to the image width obtained, in pixels.| 775 776**Returns** 777 778[MediaLibrary_ErrorCode](#medialibrary_errorcode-1): 779 780- **MEDIA_LIBRARY_OK**: The operation is successful. 781 782- **MEDIA_LIBRARY_PARAMETER_ERROR**: Incorrect parameters. 783 Possible causes: 784 785 1. There is mandatory parameter that is not specified. 786 2. The parameter type is incorrect. 787 3. The parameter verification failed. 788 789- **MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR**: An internal system error occurred. 790 791 792### OH_MediaAsset_Release() 793 794``` 795MediaLibrary_ErrorCode OH_MediaAsset_Release(OH_MediaAsset* mediaAsset) 796``` 797 798**Description** 799 800Releases a media asset. 801 802**Since**: 12 803 804**Parameters** 805 806| Name| Description| 807| -------- | -------- | 808| mediaAsset | Pointer to the [OH_MediaAsset](#oh_mediaasset) instance to release. | 809 810**Returns** 811 812[MediaLibrary_ErrorCode](#medialibrary_errorcode-1): 813 814- **MEDIA_LIBRARY_OK**: The operation is successful. 815 816- **MEDIA_LIBRARY_PARAMETER_ERROR**: Incorrect parameters. 817 Possible causes: 818 819 1. There is mandatory parameter that is not specified. 820 2. The parameter type is incorrect. 821 3. The parameter verification failed. 822 823 824### OH_MediaAssetChangeRequest_AddResourceWithBuffer() 825 826``` 827MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_AddResourceWithBuffer(OH_MediaAssetChangeRequest* changeRequest, MediaLibrary_ResourceType resourceType, uint8_t* buffer, uint32_t length) 828``` 829 830**Description** 831 832Adds a resource using **ArrayBuffer** data. 833 834**Since**: 12 835 836**Parameters** 837 838| Name| Description| 839| -------- | -------- | 840| changeRequest | Pointer to the [OH_MediaAssetChangeRequest](#oh_mediaassetchangerequest) instance.| 841| resourceType | [MediaLibrary_ResourceType](#medialibrary_resourcetype) of the resource to add.| 842| buffer | Pointe to the data buffer.| 843| length | Length of the data buffer.| 844 845**Returns** 846 847[MediaLibrary_ErrorCode](#medialibrary_errorcode-1): 848 849- **MEDIA_LIBRARY_OK**: The operation is successful. 850 851- **MEDIA_LIBRARY_PARAMETER_ERROR**: Incorrect parameters. 852 Possible causes: 853 854 1. There is mandatory parameter that is not specified. 855 2. The parameter type is incorrect. 856 3. The parameter verification failed. 857 858- **MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR**: An internal system error occurred. 859 860- **MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED**: This operation is not supported. 861 862 863### OH_MediaAssetChangeRequest_Create() 864 865``` 866OH_MediaAssetChangeRequest* OH_MediaAssetChangeRequest_Create(OH_MediaAsset* mediaAsset) 867``` 868 869**Description** 870 871Creates an [OH_MediaAssetChangeRequest](#oh_mediaassetchangerequest) instance. 872 873**Since**: 12 874 875**Parameters** 876 877| Name| Description| 878| -------- | -------- | 879| mediaAsset | Pointer to the [OH_MediaAsset](#oh_mediaasset) instance.| 880 881**Returns** 882 883[MediaLibrary_ErrorCode](#medialibrary_errorcode-1): 884 885- **MEDIA_LIBRARY_OK**: The operation is successful. 886 887- **MEDIA_LIBRARY_PARAMETER_ERROR**: Incorrect parameters. 888 Possible causes: 889 890 1. There is mandatory parameter that is not specified. 891 2. The parameter type is incorrect. 892 3. The parameter verification failed. 893 894- **MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR**: An internal system error occurred. 895 896 897### OH_MediaAssetChangeRequest_DiscardCameraPhoto() 898 899``` 900MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_DiscardCameraPhoto(OH_MediaAssetChangeRequest* changeRequest) 901``` 902 903**Description** 904 905Discards the photo taken by the camera. 906 907**Since**: 12 908 909**Parameters** 910 911| Name| Description| 912| -------- | -------- | 913| changeRequest | Pointer to the [OH_MediaAssetChangeRequest](#oh_mediaassetchangerequest) instance.| 914 915**Returns** 916 917[MediaLibrary_ErrorCode](#medialibrary_errorcode-1): 918 919- **MEDIA_LIBRARY_OK**: The operation is successful. 920 921- **MEDIA_LIBRARY_PARAMETER_ERROR**: Incorrect parameters. 922 Possible causes: 923 924 1. There is mandatory parameter that is not specified. 925 2. The parameter type is incorrect. 926 3. The parameter verification failed. 927 928- **MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR**: An internal system error occurred. 929 930- **MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED**: This operation is not supported. 931 932 933### OH_MediaAssetChangeRequest_Release() 934 935``` 936MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_Release(OH_MediaAssetChangeRequest* changeRequest) 937``` 938 939**Description** 940 941Releases an [OH_MediaAssetChangeRequest](#oh_mediaassetchangerequest) instance. 942 943**Since**: 12 944 945**Parameters** 946 947| Name| Description| 948| -------- | -------- | 949| changeRequest | Pointer to the [OH_MediaAssetChangeRequest](#oh_mediaassetchangerequest) instance to release.| 950 951**Returns** 952 953[MediaLibrary_ErrorCode](#medialibrary_errorcode-1): 954 955- **MEDIA_LIBRARY_OK**: The operation is successful. 956 957- **MEDIA_LIBRARY_PARAMETER_ERROR**: Incorrect parameters. 958 Possible causes: 959 960 1. There is mandatory parameter that is not specified. 961 2. The parameter type is incorrect. 962 3. The parameter verification failed. 963 964 965### OH_MediaAssetChangeRequest_SaveCameraPhoto() 966 967``` 968MediaLibrary_ErrorCode OH_MediaAssetChangeRequest_SaveCameraPhoto(OH_MediaAssetChangeRequest* changeRequest, MediaLibrary_ImageFileType imageFileType) 969``` 970 971**Description** 972 973Saves the photo taken by the camera. 974 975**Since**: 12 976 977**Parameters** 978 979| Name| Description| 980| -------- | -------- | 981| changeRequest | Pointer to the [OH_MediaAssetChangeRequest](#oh_mediaassetchangerequest) instance.| 982| imageFileType | [MediaLibrary_ImageFileType](#medialibrary_imagefiletype) of the photo to save.| 983 984**Returns** 985 986[MediaLibrary_ErrorCode](#medialibrary_errorcode-1): 987 988- **MEDIA_LIBRARY_OK**: The operation is successful. 989 990- **MEDIA_LIBRARY_PARAMETER_ERROR**: Incorrect parameters. 991 Possible causes: 992 993 1. There is mandatory parameter that is not specified. 994 2. The parameter type is incorrect. 995 3. The parameter verification failed. 996 997- **MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR**: An internal system error occurred. 998 999- **MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED**: This operation is not supported. 1000 1001 1002### OH_MediaAssetManager_CancelRequest() 1003 1004``` 1005bool OH_MediaAssetManager_CancelRequest (OH_MediaAssetManager *manager, const MediaLibrary_RequestId requestId) 1006``` 1007 1008**Description** 1009 1010Cancels a request based on the request ID. 1011 1012**Since**: 12 1013 1014**Parameters** 1015 1016| Name| Description| 1017| -------- | -------- | 1018| manager | Pointer to the **OH_MediaAssetManager** instance.| 1019| requestId | ID of the request to cancel.| 1020 1021**Required permissions** 1022 1023ohos.permission.READ_IMAGEVIDEO 1024 1025**Returns** 1026 1027Returns **true** if the request is successfully canceled; returns **false** otherwise. 1028 1029 1030### OH_MediaAssetManager_Create() 1031 1032``` 1033OH_MediaAssetManager* OH_MediaAssetManager_Create (void ) 1034``` 1035 1036**Description** 1037 1038Creates a **MediaAssetManager** instance. 1039 1040**Since**: 12 1041 1042**Returns** 1043 1044Returns the pointer to the **MediaAssetManager** instance created. 1045 1046 1047### OH_MediaAssetManager_RequestImage() 1048 1049``` 1050MediaLibrary_ErrorCode OH_MediaAssetManager_RequestImage(OH_MediaAssetManager* manager, OH_MediaAsset* mediaAsset, MediaLibrary_RequestOptions requestOptions, MediaLibrary_RequestId* requestId, OH_MediaLibrary_OnImageDataPrepared callback) 1051``` 1052 1053**Description** 1054 1055Requests an image. 1056 1057**Since**: 12 1058 1059**Parameters** 1060 1061| Name| Description| 1062| -------- | -------- | 1063| manager | Pointer to the [OH_MediaAssetManager](#oh_mediaassetmanager) instance.| 1064| mediaAsset | Pointer to the [OH_MediaAsset](#oh_mediaasset) instance to be requested.| 1065| requestOptions | [MediaLibrary_RequestOptions](_media_library___request_options.md).| 1066| requestId | Pointe to the [MediaLibrary_RequestId](_media_library___request_id.md) obtained.| 1067| callback | Callback [OH_MediaLibrary_OnImageDataPrepared](#oh_medialibrary_onimagedataprepared) to be invoked when the requested image source is ready.| 1068 1069**Required permissions** 1070 1071ohos.permission.READ_IMAGEVIDEO 1072 1073**Returns** 1074 1075[MediaLibrary_ErrorCode](#medialibrary_errorcode-1): 1076 1077- **MEDIA_LIBRARY_OK**: The operation is successful. 1078 1079- **MEDIA_LIBRARY_PARAMETER_ERROR**: Incorrect parameters. 1080 Possible causes: 1081 1082 1. There is mandatory parameter that is not specified. 1083 2. The parameter type is incorrect. 1084 3. The parameter verification failed. 1085 1086- **MEDIA_LIBRARY_OPERATION_NOT_SUPPORTED**: This operation is not supported. 1087 1088- **MEDIA_LIBRARY_PERMISSION_DENIED**: The permission is denied. 1089 1090- **MEDIA_LIBRARY_INTERNAL_SYSTEM_ERROR**: An internal system error occurred. 1091 1092 1093### OH_MediaAssetManager_RequestImageForPath() 1094 1095``` 1096MediaLibrary_RequestId OH_MediaAssetManager_RequestImageForPath (OH_MediaAssetManager *manager, const char *uri, MediaLibrary_RequestOptions requestOptions, const char *destPath, OH_MediaLibrary_OnDataPrepared callback) 1097``` 1098 1099**Description** 1100 1101Requests an image in the specified directory. 1102 1103**Since**: 12 1104 1105**Parameters** 1106 1107| Name| Description| 1108| -------- | -------- | 1109| manager | Pointer to the **OH_MediaAssetManager** instance.| 1110| uri | Pointer to the URI of the requested image asset.| 1111| requestOptions | Options related to the image asset quality and delivery mode.| 1112| destPath | Pointer to the destination directory of the requested image asset.| 1113| callback | Callback to be invoked when the requested image asset is ready.| 1114 1115**Required permissions** 1116 1117ohos.permission.READ_IMAGEVIDEO 1118 1119**Returns** 1120 1121Request ID. 1122 1123 1124### OH_MediaAssetManager_RequestVideoForPath() 1125 1126``` 1127MediaLibrary_RequestId OH_MediaAssetManager_RequestVideoForPath (OH_MediaAssetManager *manager, const char *uri, MediaLibrary_RequestOptions requestOptions, const char *destPath, OH_MediaLibrary_OnDataPrepared callback) 1128``` 1129 1130**Description** 1131 1132Requests a video asset in the specified directory. 1133 1134**Since**: 12 1135 1136**Parameters** 1137 1138| Name| Description| 1139| -------- | -------- | 1140| manager | Pointer to the **OH_MediaAssetManager** instance.| 1141| uri | Pointer to the URI of the requested video asset.| 1142| requestOptions | Options related to the video asset quality and delivery mode.| 1143| destPath | Pointer to the destination directory of the requested video asset.| 1144| callback | Callback to be invoked when the requested video asset is ready.| 1145 1146**Required permissions** 1147 1148ohos.permission.READ_IMAGEVIDEO 1149 1150**Returns** 1151 1152Request ID. 1153