1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { AsyncCallback, Callback } from './basic'; 17import Context from './app/context'; 18import image from './@ohos.multimedia.image'; 19 20/** 21 * @name mediaLibrary 22 * @since 6 23 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 24 * @import import media from '@ohos.multimedia.mediaLibrary' 25 */ 26declare namespace mediaLibrary { 27 /** 28 * Obtains a MediaLibrary instance. 29 * @since 6 30 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 31 * @import import mediaLibrary from '@ohos.multimedia.mediaLibrary' 32 * @FAModelOnly 33 * @return Returns a MediaLibrary instance if the operation is successful; returns null otherwise. 34 */ 35 function getMediaLibrary(): MediaLibrary; 36 /** 37 * Returns an instance of MediaLibrary 38 * @since 8 39 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 40 * @StageModelOnly 41 * @param context hap context information 42 * @return Instance of MediaLibrary 43 */ 44 function getMediaLibrary(context: Context): MediaLibrary; 45 46 /** 47 * Enumeration types for different kind of Media Files 48 * @since 8 49 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 50 */ 51 enum MediaType { 52 /** 53 * File media type 54 * @since 8 55 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 56 */ 57 FILE = 0, 58 /** 59 * Image media type 60 * @since 8 61 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 62 */ 63 IMAGE, 64 /** 65 * Video media type 66 * @since 8 67 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 68 */ 69 VIDEO, 70 /** 71 * Audio media type 72 * @since 8 73 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 74 */ 75 AUDIO 76 } 77 78 /** 79 * Describes media resource options. 80 * @since 6 81 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 82 * @import import mediaLibrary from '@ohos.multimedia.mediaLibrary' 83 */ 84 interface MediaAssetOption { 85 /** 86 * URI of the media source. 87 * @since 6 88 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 89 */ 90 src: string; 91 /** 92 * Multipurpose Internet Mail Extensions (MIME) type of the media. 93 * @since 6 94 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 95 */ 96 mimeType: string; 97 /** 98 * Relative path for storing media resources. 99 * @since 6 100 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 101 */ 102 relativePath?: string; 103 } 104 105 /** 106 * Describes media selection options. 107 * @since 6 108 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 109 * @import import mediaLibrary from '@ohos.multimedia.mediaLibrary' 110 */ 111 interface MediaSelectOption { 112 /** 113 * Media type, which can be image, video, or media (indicating both image and video). 114 * @since 6 115 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 116 */ 117 type: 'image' | 'video' | 'media'; 118 /** 119 * Maximum number of media items that can be selected 120 * @since 6 121 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 122 */ 123 count: number; 124 } 125 126 /** 127 * Provides methods to encapsulate file attributes. 128 * @since 8 129 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 130 * @import import mediaLibrary from '@ohos.multimedia.mediaLibrary' 131 */ 132 interface FileAsset { 133 /** 134 * File ID. 135 * @since 8 136 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 137 */ 138 readonly id: number; 139 /** 140 * URI of the file. 141 * @since 8 142 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 143 */ 144 readonly uri: string; 145 /** 146 * MIME type, for example, video/mp4, audio/mp4, or audio/amr-wb. 147 * @since 8 148 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 149 */ 150 readonly mimeType: string; 151 /** 152 * Media type, for example, IMAGE, VIDEO, FILE, AUDIO 153 * @since 8 154 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 155 */ 156 readonly mediaType: MediaType; 157 /** 158 * Display name (with a file name extension) of the file. 159 * @since 8 160 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 161 */ 162 displayName: string; 163 /** 164 * File name title (without the file name extension). 165 * @since 8 166 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 167 */ 168 title: string; 169 /** 170 * Relative Path of the file. 171 * @since 8 172 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 173 */ 174 relativePath: string; 175 /** 176 * Parent folder's file_id of the file. 177 * @since 8 178 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 179 */ 180 readonly parent: number; 181 /** 182 * Data size of the file. 183 * @since 8 184 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 185 */ 186 readonly size: number; 187 /** 188 * Date (timestamp) when the file was added. 189 * @since 8 190 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 191 */ 192 readonly dateAdded: number; 193 /** 194 * Date (timestamp) when the file was modified. 195 * @since 8 196 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 197 */ 198 readonly dateModified: number; 199 /** 200 * Date (timestamp) when the file was taken. 201 * @since 8 202 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 203 */ 204 readonly dateTaken: number; 205 /** 206 * Artist of the audio file. 207 * @since 8 208 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 209 */ 210 readonly artist: string; 211 /** 212 * audioAlbum of the audio file. 213 * @since 8 214 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 215 */ 216 readonly audioAlbum: string; 217 /** 218 * Display width of the file. This is valid only for videos and images. 219 * @since 8 220 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 221 */ 222 readonly width: number; 223 /** 224 * Display height of the file. This is valid only for videos and images. 225 * @since 8 226 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 227 */ 228 readonly height: number; 229 /** 230 * Rotation angle of the file, in degrees. 231 * The rotation angle can be 0, 90, 180, or 270 degrees. This is valid only for videos. 232 * @since 8 233 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 234 */ 235 orientation: number; 236 /** 237 * duration of the audio and video file. 238 * @since 8 239 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 240 */ 241 readonly duration: number; 242 /** 243 * ID of the album where the file is located. 244 * @since 8 245 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 246 */ 247 readonly albumId: number; 248 /** 249 * URI of the album where the file is located. 250 * @since 8 251 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 252 */ 253 readonly albumUri: string; 254 /** 255 * Name of the album where the file is located. 256 * @since 8 257 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 258 */ 259 readonly albumName: string; 260 261 /** 262 * If it is a directory where the file is located. 263 * @since 8 264 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 265 * @param callback Callback return the result of isDerectory. 266 */ 267 isDirectory(callback: AsyncCallback<boolean>): void; 268 /** 269 * If it is a directory where the file is located. 270 * @since 8 271 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 272 */ 273 isDirectory():Promise<boolean>; 274 /** 275 * Modify meta data where the file is located. 276 * @since 8 277 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 278 * @param callback no value will be returned. 279 * @systemapi 280 */ 281 commitModify(callback: AsyncCallback<void>): void; 282 /** 283 * Modify meta data where the file is located. 284 * @since 8 285 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 286 * @systemapi 287 */ 288 commitModify(): Promise<void>; 289 /** 290 * Open the file is located. 291 * @since 8 292 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 293 * @param mode mode for open, for example: rw, r, w. 294 * @param callback Callback return the fd of the file. 295 */ 296 open(mode: string, callback: AsyncCallback<number>): void; 297 /** 298 * Open the file is located. 299 * @since 8 300 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 301 * @param mode mode for open, for example: rw, r, w. 302 */ 303 open(mode: string): Promise<number>; 304 /** 305 * Close the file is located. 306 * @since 8 307 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 308 * @param fd fd of the file which had been opened 309 * @param callback no value will be returned. 310 */ 311 close(fd: number, callback: AsyncCallback<void>): void; 312 /** 313 * Close the file is located. 314 * @since 8 315 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 316 * @param fd fd of the file which had been opened 317 */ 318 close(fd: number): Promise<void>; 319 /** 320 * Get thumbnail of the file when the file is located. 321 * @since 8 322 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 323 * @param callback Callback used to return the thumbnail's pixelmap. 324 */ 325 getThumbnail(callback: AsyncCallback<image.PixelMap>): void; 326 /** 327 * Get thumbnail of the file when the file is located. 328 * @since 8 329 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 330 * @param size thumbnail's size 331 * @param callback Callback used to return the thumbnail's pixelmap. 332 */ 333 getThumbnail(size: Size, callback: AsyncCallback<image.PixelMap>): void; 334 /** 335 * Get thumbnail of the file when the file is located. 336 * @since 8 337 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 338 * @param size thumbnail's size 339 */ 340 getThumbnail(size?: Size): Promise<image.PixelMap>; 341 /** 342 * Set favorite for the file when the file is located. 343 * @since 8 344 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 345 * @param isFavorite ture is favorite file, false is not favorite file 346 * @param callback Callback used to return, No value is returned. 347 * @systemapi 348 */ 349 favorite(isFavorite: boolean, callback: AsyncCallback<void>): void; 350 /** 351 * Set favorite for the file when the file is located. 352 * @since 8 353 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 354 * @param isFavorite ture is favorite file, false is not favorite file 355 * @systemapi 356 */ 357 favorite(isFavorite: boolean): Promise<void>; 358 /** 359 * If the file is favorite when the file is located. 360 * @since 8 361 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 362 * @param callback Callback used to return true or false. 363 * @systemapi 364 */ 365 isFavorite(callback: AsyncCallback<boolean>): void; 366 /** 367 * If the file is favorite when the file is located. 368 * @since 8 369 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 370 * @systemapi 371 */ 372 isFavorite():Promise<boolean>; 373 /** 374 * Set trash for the file when the file is located. 375 * @since 8 376 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 377 * @param isTrash true is trashed file, false is not trashed file 378 * @param callback Callback used to return, No value is returned. 379 * @systemapi 380 */ 381 trash(isTrash: boolean, callback: AsyncCallback<void>): void; 382 /** 383 * Set trash for the file when the file is located. 384 * @since 8 385 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 386 * @param isTrash true is trashed file, false is not trashed file 387 * @systemapi 388 */ 389 trash(isTrash: boolean,): Promise<void>; 390 /** 391 * If the file is in trash when the file is located. 392 * @since 8 393 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 394 * @param callback Callback used to return true or false. 395 * @systemapi 396 */ 397 isTrash(callback: AsyncCallback<boolean>): void; 398 /** 399 * If the file is in trash when the file is located. 400 * @since 8 401 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 402 * @systemapi 403 */ 404 isTrash():Promise<boolean>; 405 } 406 407 /** 408 * Describes MediaFetchOptions's selection 409 * @since 8 410 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 411 */ 412 enum FileKey { 413 /** 414 * File ID 415 * @since 8 416 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 417 */ 418 ID = "file_id", 419 /** 420 * Relative Path 421 * @since 8 422 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 423 */ 424 RELATIVE_PATH = "relative_path", 425 /** 426 * File name 427 * @since 8 428 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 429 */ 430 DISPLAY_NAME = "display_name", 431 /** 432 * Parent folder file id 433 * @since 8 434 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 435 */ 436 PARENT = "parent", 437 /** 438 * Mime type of the file 439 * @since 8 440 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 441 */ 442 MIME_TYPE = "mime_type", 443 /** 444 * Media type of the file 445 * @since 8 446 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 447 */ 448 MEDIA_TYPE = "media_type", 449 /** 450 * Size of the file 451 * @since 8 452 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 453 */ 454 SIZE = "size", 455 /** 456 * Date of the file creation 457 * @since 8 458 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 459 */ 460 DATE_ADDED = "date_added", 461 /** 462 * Modify date of the file 463 * @since 8 464 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 465 */ 466 DATE_MODIFIED = "date_modified", 467 /** 468 * Date taken of the file 469 * @since 8 470 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 471 */ 472 DATE_TAKEN = "date_taken", 473 /** 474 * Title of the file 475 * @since 8 476 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 477 */ 478 TITLE = "title", 479 /** 480 * Artist of the audio file 481 * @since 8 482 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 483 */ 484 ARTIST = "artist", 485 /** 486 * Audio album of the audio file 487 * @since 8 488 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 489 */ 490 AUDIOALBUM = "audio_album", 491 /** 492 * Duration of the audio and video file 493 * @since 8 494 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 495 */ 496 DURATION = "duration", 497 /** 498 * Width of the image file 499 * @since 8 500 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 501 */ 502 WIDTH = "width", 503 /** 504 * Height of the image file 505 * @since 8 506 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 507 */ 508 HEIGHT = "height", 509 /** 510 * Orientation of the image file 511 * @since 8 512 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 513 */ 514 ORIENTATION = "orientation", 515 /** 516 * Album id of the file 517 * @since 8 518 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 519 */ 520 ALBUM_ID = "bucket_id", 521 /** 522 * Album name of the file 523 * @since 8 524 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 525 */ 526 ALBUM_NAME = "bucket_display_name", 527 } 528 529 /** 530 * Fetch parameters applicable on images, videos, audios, albums and other media 531 * @since 8 532 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 533 */ 534 interface MediaFetchOptions { 535 /** 536 * Fields to retrieve, for example, selections: "media_type =? OR media_type =?". 537 * @since 8 538 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 539 */ 540 selections: string; 541 /** 542 * Conditions for retrieval, for example, selectionArgs: [IMAGE, VIDEO]. 543 * @since 8 544 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 545 */ 546 selectionArgs: Array<string>; 547 /** 548 * Sorting criterion of the retrieval results, for example, order: "datetaken DESC,_display_name DESC, _id DESC". 549 * @since 8 550 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 551 */ 552 order?: string; 553 /** 554 * uri for retrieval 555 * @since 8 556 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 557 */ 558 uri?: string; 559 /** 560 * networkId for retrieval 561 * @since 8 562 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 563 */ 564 networkId?: string; 565 /** 566 * extendArgs for retrieval 567 * @since 8 568 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 569 */ 570 extendArgs?: string; 571 } 572 573 /** 574 * Implements file retrieval. 575 * @since 8 576 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 577 * @import import mediaLibrary from '@ohos.multimedia.mediaLibrary' 578 */ 579 interface FetchFileResult { 580 /** 581 * Obtains the total number of files in the file retrieval result. 582 * @since 8 583 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 584 * @return Total number of files. 585 */ 586 getCount(): number; 587 /** 588 * Checks whether the result set points to the last row. 589 * @since 8 590 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 591 * @return Whether the file is the last one. 592 * You need to check whether the file is the last one before calling getNextObject, 593 * which returns the next file only when True is returned for this method. 594 */ 595 isAfterLast(): boolean; 596 /** 597 * Releases the FetchFileResult instance and invalidates it. Other methods cannot be called. 598 * @since 8 599 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 600 */ 601 close(): void; 602 /** 603 * Obtains the first FileAsset in the file retrieval result. This method uses a callback to return the file. 604 * @since 8 605 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 606 * @param callback Callback used to return the file in the format of a FileAsset instance. 607 */ 608 getFirstObject(callback: AsyncCallback<FileAsset>): void; 609 /** 610 * Obtains the first FileAsset in the file retrieval result. This method uses a promise to return the file. 611 * @since 8 612 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 613 * @return A Promise instance used to return the file in the format of a FileAsset instance. 614 */ 615 getFirstObject(): Promise<FileAsset>; 616 /** 617 * Obtains the next FileAsset in the file retrieval result. 618 * This method uses a callback to return the file. 619 * Before calling this method, you must use isAfterLast() to check whether the result set points to the last row. 620 * This method returns the next file only when True is returned for isAfterLast(). 621 * @since 8 622 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 623 * @param callback Callback used to return the file in the format of a FileAsset instance. 624 */ 625 getNextObject(callback: AsyncCallback<FileAsset>): void; 626 /** 627 * Obtains the next FileAsset in the file retrieval result. 628 * This method uses a promise to return the file. 629 * Before calling this method, you must use isAfterLast() to check whether the result set points to the last row. 630 * This method returns the next file only when True is returned for isAfterLast(). 631 * @since 8 632 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 633 * @return A Promise instance used to return the file in the format of a FileAsset instance. 634 */ 635 getNextObject(): Promise<FileAsset>; 636 /** 637 * Obtains the last FileAsset in the file retrieval result. This method uses a callback to return the file. 638 * @since 8 639 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 640 * @param callback Callback used to return the file in the format of a FileAsset instance. 641 */ 642 getLastObject(callback: AsyncCallback<FileAsset>): void; 643 /** 644 * Obtains the last FileAsset in the file retrieval result. This method uses a promise to return the file. 645 * @since 8 646 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 647 * @return A Promise instance used to return the file in the format of a FileAsset instance. 648 */ 649 getLastObject(): Promise<FileAsset>; 650 /** 651 * Obtains the FileAsset with the specified index in the file retrieval result. 652 * This method uses a callback to return the file. 653 * @since 8 654 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 655 * @param index Index of the file to obtain. 656 * @param callback Callback used to return the file in the format of a FileAsset instance. 657 */ 658 getPositionObject(index: number, callback: AsyncCallback<FileAsset>): void; 659 /** 660 * Obtains the FileAsset with the specified index in the file retrieval result. 661 * This method uses a promise to return the file. 662 * @since 8 663 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 664 * @param index Index of the file to obtain. 665 * @return A Promise instance used to return the file in the format of a FileAsset instance. 666 */ 667 getPositionObject(index: number): Promise<FileAsset>; 668 /** 669 * Obtains all FileAssets in the file retrieval result. 670 * This method uses a callback to return the result. After this method is called, 671 * close() is automatically called to release the FetchFileResult instance and invalidate it. 672 * In this case, other methods cannot be called. 673 * @since 8 674 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 675 * @param callback Callback used to return a FileAsset array. 676 */ 677 getAllObject(callback: AsyncCallback<Array<FileAsset>>): void; 678 /** 679 * Obtains all FileAssets in the file retrieval result. 680 * This method uses a promise to return the result. that store the selected media resources. 681 * close() is automatically called to release the FetchFileResult instance and invalidate it. 682 * In this case, other methods cannot be called. 683 * @since 8 684 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 685 * @return A Promise instance used to return a FileAsset array. 686 */ 687 getAllObject(): Promise<Array<FileAsset>>; 688 } 689 690 /** 691 * Defines the album. 692 * 693 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 694 * @since 8 695 */ 696 interface Album { 697 /** 698 * Album ID. 699 * @since 8 700 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 701 */ 702 readonly albumId: number; 703 /** 704 * Album name. 705 * @since 8 706 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 707 */ 708 albumName: string; 709 /** 710 * Album uri. 711 * @since 8 712 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 713 */ 714 readonly albumUri: string; 715 /** 716 * Date (timestamp) when the album was last modified. 717 * @since 8 718 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 719 */ 720 readonly dateModified: number; 721 /** 722 * File count for the album 723 * @since 8 724 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 725 */ 726 readonly count: number; 727 /** 728 * Relative path for the album 729 * @since 8 730 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 731 */ 732 readonly relativePath: string; 733 /** 734 * coverUri for the album 735 * @since 8 736 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 737 */ 738 readonly coverUri: string; 739 740 /** 741 * Modify the meta data for the album 742 * @since 8 743 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 744 * @param callback, no value will be returned. 745 * @systemapi 746 */ 747 commitModify(callback: AsyncCallback<void>): void; 748 /** 749 * Modify the meta data for the album 750 * @since 8 751 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 752 * @systemapi 753 */ 754 commitModify(): Promise<void>; 755 /** 756 * SObtains files in an album. This method uses an asynchronous callback to return the files. 757 * @since 8 758 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 759 * @param callback Callback used to return the files in the format of a FetchFileResult instance. 760 */ 761 getFileAssets(callback: AsyncCallback<FetchFileResult>): void; 762 /** 763 * SObtains files in an album. This method uses an asynchronous callback to return the files. 764 * @since 8 765 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 766 * @param option Media retrieval options. 767 * @param callback Callback used to return the files in the format of a FetchFileResult instance. 768 */ 769 getFileAssets(options: MediaFetchOptions, callback: AsyncCallback<FetchFileResult>): void; 770 /** 771 * Obtains files in an album. This method uses a promise to return the files. 772 * @since 8 773 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 774 * @param option Media retrieval options. 775 * @return A Promise instance used to return the files in the format of a FetchFileResult instance. 776 */ 777 getFileAssets(options?: MediaFetchOptions): Promise<FetchFileResult>; 778 } 779 780 /** 781 * Enumeration public directory that predefined 782 * @since 8 783 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 784 */ 785 enum DirectoryType { 786 /** 787 * predefined public directory for files token by Camera. 788 * @since 8 789 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 790 */ 791 DIR_CAMERA = 0, 792 /** 793 * predefined public directory for VIDEO files. 794 * @since 8 795 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 796 */ 797 DIR_VIDEO, 798 /** 799 * predefined public directory for IMAGE files. 800 * @since 8 801 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 802 */ 803 DIR_IMAGE, 804 /** 805 * predefined public directory for AUDIO files. 806 * @since 8 807 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 808 */ 809 DIR_AUDIO, 810 /** 811 * predefined public directory for DOCUMENTS files. 812 * @since 8 813 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 814 */ 815 DIR_DOCUMENTS, 816 /** 817 * predefined public directory for DOWNLOAD files. 818 * @since 8 819 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 820 */ 821 DIR_DOWNLOAD 822 } 823 824 /** 825 * Defines the MediaLibrary class and provides functions to access the data in media storage. 826 * 827 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 828 * @since 6 829 */ 830 interface MediaLibrary { 831 /** 832 * get system predefined root dir, use to create file asset by relative path 833 * @since 8 834 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 835 * @param type, public directory predefined in DirectoryType. 836 * @param callback Callback return the FetchFileResult. 837 */ 838 getPublicDirectory(type: DirectoryType, callback: AsyncCallback<string>): void; 839 /** 840 * get system predefined root dir, use to create file asset by relative path 841 * @since 8 842 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 843 * @param type public directory predefined in DirectoryType. 844 * @return A promise instance used to return the public directory in the format of string 845 */ 846 getPublicDirectory(type: DirectoryType): Promise<string>; 847 /** 848 * query all assets just for count & first cover 849 * if need all data, getAllObject from FetchFileResult 850 * @since 8 851 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 852 * @param options, Media retrieval options. 853 * @param callback, Callback return the FetchFileResult. 854 */ 855 getFileAssets(options: MediaFetchOptions, callback: AsyncCallback<FetchFileResult>): void; 856 /** 857 * query all assets just for count & first cover 858 * if need all data, getAllObject from FetchFileResult 859 * @since 8 860 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 861 * @param options Media retrieval options. 862 * @return A promise instance used to return the files in the format of a FetchFileResult instance 863 */ 864 getFileAssets(options: MediaFetchOptions): Promise<FetchFileResult>; 865 /** 866 * Turn on mornitor the data changes by media type 867 * @since 8 868 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 869 * @param type one of 'deviceChange','albumChange','imageChange','audioChange','videoChange','fileChange','remoteFileChange' 870 * @param callback no value returned 871 */ 872 on(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'|'videoChange'|'fileChange'|'remoteFileChange', callback: Callback<void>): void; 873 /** 874 * Turn off mornitor the data changes by media type 875 * @since 8 876 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 877 * @param type one of 'deviceChange','albumChange','imageChange','audioChange','videoChange','fileChange','remoteFileChange' 878 * @param callback no value returned 879 */ 880 off(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'|'videoChange'|'fileChange'|'remoteFileChange', callback?: Callback<void>): void; 881 /** 882 * Create File Asset 883 * @since 8 884 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 885 * @param mediaType mediaType for example:IMAGE, VIDEO, AUDIO, FILE 886 * @param displayName file name 887 * @param relativePath relative path 888 * @param callback Callback used to return the FileAsset 889 */ 890 createAsset(mediaType: MediaType, displayName: string, relativePath: string, callback: AsyncCallback<FileAsset>): void; 891 /** 892 * Create File Asset 893 * @since 8 894 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 895 * @param mediaType mediaType for example:IMAGE, VIDEO, AUDIO, FILE 896 * @param displayName file name 897 * @param relativePath relative path 898 * @return A Promise instance used to return the FileAsset 899 */ 900 createAsset(mediaType: MediaType, displayName: string, relativePath: string): Promise<FileAsset>; 901 /** 902 * Delete File Asset 903 * @since 8 904 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 905 * @param uri FileAsset's URI 906 * @param callback no value returned 907 * @systemapi 908 */ 909 deleteAsset(uri: string, callback: AsyncCallback<void>): void; 910 /** 911 * Delete File Asset 912 * @since 8 913 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 914 * @param uri, FileAsset's URI 915 * @return A Promise instance, no value returned 916 * @systemapi 917 */ 918 deleteAsset(uri: string): Promise<void>; 919 /** 920 * Obtains albums based on the media retrieval options. This method uses an asynchronous callback to return. 921 * @since 8 922 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 923 * @param option Media retrieval options. 924 * @param callback Callback used to return an album array. 925 */ 926 getAlbums(options: MediaFetchOptions, callback: AsyncCallback<Array<Album>>): void; 927 /** 928 * Obtains albums based on the media retrieval options. This method uses a promise to return the albums. 929 * @since 8 930 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 931 * @param option Media retrieval options. 932 * @return A Promise instance used to return an album array. 933 */ 934 getAlbums(options: MediaFetchOptions): Promise<Array<Album>>; 935 /** 936 * Stores media resources. This method uses an asynchronous callback to return the URI that stores 937 * the media resources. 938 * @since 6 939 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 940 * @param option Media resource option. 941 * @param callback Callback used to return the URI that stores the media resources. 942 */ 943 storeMediaAsset(option: MediaAssetOption, callback: AsyncCallback<string>): void; 944 /** 945 * Stores media resources. This method uses a promise to return the URI that stores the media resources. 946 * @since 6 947 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 948 * @param option Media resource option. 949 * @return Promise used to return the URI that stores the media resources. 950 */ 951 storeMediaAsset(option: MediaAssetOption): Promise<string>; 952 /** 953 * Starts image preview, with the first image to preview specified. This method uses an asynchronous callback 954 * to receive the execution result. 955 * @since 6 956 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 957 * @param images List of images to preview. 958 * @param index Sequence number of the first image to preview. 959 * @param callback Callback used for image preview. No value is returned. 960 */ 961 startImagePreview(images: Array<string>, index: number, callback: AsyncCallback<void>): void; 962 /** 963 * Starts image preview. This method uses an asynchronous callback to receive the execution result. 964 * @since 6 965 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 966 * @param images List of images to preview. 967 * @param callback Callback used for image preview. No value is returned. 968 */ 969 startImagePreview(images: Array<string>, callback: AsyncCallback<void>): void; 970 /** 971 * Starts image preview, with the first image to preview specified. 972 * This method uses a promise to return the execution result. 973 * @since 6 974 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 975 * @param images List of images to preview. 976 * @param index Sequence number of the first image to preview. 977 * @return Promise used to return whether the operation is successful. 978 */ 979 startImagePreview(images: Array<string>, index?: number): Promise<void>; 980 /** 981 * Starts media selection. This method uses an asynchronous callback to 982 * return the list of URIs that store the selected media resources. 983 * @since 6 984 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 985 * @param option Media selection option. 986 * @param callback Callback used to return the list of URIs that store the selected media resources. 987 */ 988 startMediaSelect(option: MediaSelectOption, callback: AsyncCallback<Array<string>>): void; 989 /** 990 * Starts media selection. This method uses a promise to return the list of URIs 991 * that store the selected media resources. 992 * @since 6 993 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 994 * @param option Media selection option. 995 * @return Promise used to return the list of URIs that store the selected media resources. 996 */ 997 startMediaSelect(option: MediaSelectOption): Promise<Array<string>>; 998 /** 999 * Get Active Peer device information 1000 * @since 8 1001 * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore 1002 * @systemapi 1003 * @param callback, Callback return the list of the active peer devices' information 1004 */ 1005 getActivePeers(callback: AsyncCallback<Array<PeerInfo>>): void; 1006 /** 1007 * Get Active Peer device information 1008 * @since 8 1009 * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore 1010 * @systemapi 1011 * @return Promise used to return the list of the active peer devices' information 1012 */ 1013 getActivePeers(): Promise<Array<PeerInfo>>; 1014 /** 1015 * Get all the peer devices' information 1016 * @since 8 1017 * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore 1018 * @systemapi 1019 * @param callback Callback return the list of the all the peer devices' information 1020 */ 1021 getAllPeers(callback: AsyncCallback<Array<PeerInfo>>): void; 1022 /** 1023 * Get all the peer devices' information 1024 * @since 8 1025 * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore 1026 * @systemapi 1027 * @return Promise used to return the list of the all the peer devices' information 1028 */ 1029 getAllPeers(): Promise<Array<PeerInfo>>; 1030 /** 1031 * Release MediaLibrary instance 1032 * @since 8 1033 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 1034 * @param callback no value returned 1035 */ 1036 release(callback: AsyncCallback<void>): void; 1037 /** 1038 * Release MediaLibrary instance 1039 * @since 8 1040 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 1041 */ 1042 release(): Promise<void>; 1043 } 1044 1045 /** 1046 * thumbnail's size which have width and heigh 1047 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 1048 * @since 8 1049 */ 1050 interface Size { 1051 /** 1052 * Width of image file 1053 * @since 8 1054 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 1055 */ 1056 width: number; 1057 /** 1058 * Height of image file 1059 * @since 8 1060 * @syscap SystemCapability.Multimedia.MediaLibrary.Core 1061 */ 1062 height: number; 1063 } 1064 1065 /** 1066 * peer devices' information 1067 * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore 1068 * @systemapi 1069 * @since 8 1070 */ 1071 interface PeerInfo { 1072 /** 1073 * Peer device name 1074 * @since 8 1075 * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore 1076 * @systemapi 1077 */ 1078 readonly deviceName: string; 1079 /** 1080 * Peer device network id 1081 * @since 8 1082 * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore 1083 * @systemapi 1084 */ 1085 readonly networkId: string; 1086 /** 1087 * Peer device type 1088 * @since 8 1089 * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore 1090 * @systemapi 1091 */ 1092 readonly deviceType: DeviceType; 1093 /** 1094 * Peer device online status 1095 * @since 8 1096 * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore 1097 * @systemapi 1098 */ 1099 readonly isOnline: boolean; 1100 } 1101 1102 /** 1103 * peer device type 1104 * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore 1105 * @systemapi 1106 * @since 8 1107 */ 1108 enum DeviceType { 1109 /** 1110 * Unknow device type 1111 * @since 8 1112 * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore 1113 * @systemapi 1114 */ 1115 TYPE_UNKNOWN = 0, 1116 /** 1117 * Laptop device 1118 * @since 8 1119 * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore 1120 * @systemapi 1121 */ 1122 TYPE_LAPTOP, 1123 /** 1124 * Phone device 1125 * @since 8 1126 * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore 1127 * @systemapi 1128 */ 1129 TYPE_PHONE, 1130 /** 1131 * Tablet device 1132 * @since 8 1133 * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore 1134 * @systemapi 1135 */ 1136 TYPE_TABLET, 1137 /** 1138 * Watch device 1139 * @since 8 1140 * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore 1141 * @systemapi 1142 */ 1143 TYPE_WATCH, 1144 /** 1145 * Car device 1146 * @since 8 1147 * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore 1148 * @systemapi 1149 */ 1150 TYPE_CAR, 1151 /** 1152 * TV device 1153 * @since 8 1154 * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore 1155 * @systemapi 1156 */ 1157 TYPE_TV 1158 } 1159} 1160 1161export default mediaLibrary; 1162 1163