• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 7
129   * @syscap SystemCapability.Multimedia.MediaLibrary.Core
130   * @import import mediaLibrary from '@ohos.multimedia.mediaLibrary'
131   */
132  interface FileAsset {
133    /**
134     * File ID.
135     * @since 7
136     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
137     */
138    readonly id: number;
139    /**
140     * URI of the file.
141     * @since 7
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 7
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 7
160     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
161     */
162    displayName: string;
163    /**
164     * File name title (without the file name extension).
165     * @since 7
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 7
184     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
185     */
186    readonly size: number;
187    /**
188     * Date (timestamp) when the file was added.
189     * @since 7
190     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
191     */
192    readonly dateAdded: number;
193    /**
194     * Date (timestamp) when the file was modified.
195     * @since 7
196     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
197     */
198    readonly dateModified: number;
199    /**
200     * Date (timestamp) when the file was taken.
201     * @since 7
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 7
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 7
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 7
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 7
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 7
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     * @permission ohos.permission.READ_MEDIA
266     * @param callback Callback return the result of isDerectory.
267     */
268    isDirectory(callback: AsyncCallback<boolean>): void;
269    /**
270     * If it is a directory where the file is located.
271     * @since 8
272     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
273     * @permission ohos.permission.READ_MEDIA
274     */
275    isDirectory():Promise<boolean>;
276    /**
277     * Modify meta data where the file is located.
278     * @since 8
279     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
280     * @permission ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
281     * @param callback no value will be returned.
282     */
283    commitModify(callback: AsyncCallback<void>): void;
284    /**
285     * Modify meta data where the file is located.
286     * @since 8
287     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
288     * @permission ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
289     */
290    commitModify(): Promise<void>;
291    /**
292     * Open the file is located.
293     * @since 8
294     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
295     * @permission ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
296     * @param mode mode for open, for example: rw, r, w.
297     * @param callback Callback return the fd of the file.
298     */
299    open(mode: string, callback: AsyncCallback<number>): void;
300    /**
301     * Open the file is located.
302     * @since 8
303     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
304     * @permission ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
305     * @param mode mode for open, for example: rw, r, w.
306     */
307    open(mode: string): Promise<number>;
308    /**
309     * Close the file is located.
310     * @since 8
311     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
312     * @permission ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
313     * @param fd fd of the file which had been opened
314     * @param callback no value will be returned.
315     */
316    close(fd: number, callback: AsyncCallback<void>): void;
317    /**
318     * Close the file is located.
319     * @since 8
320     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
321     * @permission ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
322     * @param fd fd of the file which had been opened
323     */
324    close(fd: number): Promise<void>;
325    /**
326     * Get thumbnail of the file when the file is located.
327     * @since 8
328     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
329     * @permission ohos.permission.READ_MEDIA
330     * @param callback Callback used to return the thumbnail's pixelmap.
331     */
332    getThumbnail(callback: AsyncCallback<image.PixelMap>): void;
333    /**
334     * Get thumbnail of the file when the file is located.
335     * @since 8
336     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
337     * @permission ohos.permission.READ_MEDIA
338     * @param size thumbnail's size
339     * @param callback Callback used to return the thumbnail's pixelmap.
340     */
341    getThumbnail(size: Size, callback: AsyncCallback<image.PixelMap>): void;
342    /**
343     * Get thumbnail of the file when the file is located.
344     * @since 8
345     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
346     * @permission ohos.permission.READ_MEDIA
347     * @param size thumbnail's size
348     */
349    getThumbnail(size?: Size): Promise<image.PixelMap>;
350    /**
351     * Set favorite for the file when the file is located.
352     * @since 8
353     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
354     * @permission ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
355     * @param isFavorite ture is favorite file, false is not favorite file
356     * @param callback Callback used to return, No value is returned.
357     */
358    favorite(isFavorite: boolean, callback: AsyncCallback<void>): void;
359    /**
360     * Set favorite for the file when the file is located.
361     * @since 8
362     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
363     * @permission ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
364     * @param isFavorite ture is favorite file, false is not favorite file
365     */
366    favorite(isFavorite: boolean): Promise<void>;
367    /**
368     * If the file is favorite when the file is located.
369     * @since 8
370     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
371     * @permission ohos.permission.READ_MEDIA
372     * @param callback Callback used to return true or false.
373     */
374    isFavorite(callback: AsyncCallback<boolean>): void;
375    /**
376     * If the file is favorite when the file is located.
377     * @since 8
378     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
379     * @permission ohos.permission.READ_MEDIA
380     */
381    isFavorite():Promise<boolean>;
382    /**
383     * Set trash for the file when the file is located.
384     * @since 8
385     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
386     * @permission ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
387     * @param isTrash true is trashed file, false is not trashed file
388     * @param callback Callback used to return, No value is returned.
389     */
390    trash(isTrash: boolean, callback: AsyncCallback<void>): void;
391    /**
392     * Set trash for the file when the file is located.
393     * @since 8
394     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
395     * @permission ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
396     * @param isTrash true is trashed file, false is not trashed file
397     */
398    trash(isTrash: boolean): Promise<void>;
399    /**
400     * If the file is in trash when the file is located.
401     * @since 8
402     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
403     * @permission ohos.permission.READ_MEDIA
404     * @param callback Callback used to return true or false.
405     */
406    isTrash(callback: AsyncCallback<boolean>): void;
407    /**
408     * If the file is in trash when the file is located.
409     * @since 8
410     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
411     * @permission ohos.permission.READ_MEDIA
412     */
413    isTrash():Promise<boolean>;
414  }
415
416  /**
417   * Describes MediaFetchOptions's selection
418   * @since 8
419   * @syscap SystemCapability.Multimedia.MediaLibrary.Core
420   */
421  enum FileKey {
422    /**
423     * File ID
424     * @since 8
425     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
426     */
427    ID = "file_id",
428    /**
429     * Relative Path
430     * @since 8
431     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
432     */
433    RELATIVE_PATH = "relative_path",
434    /**
435     * File name
436     * @since 8
437     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
438     */
439    DISPLAY_NAME = "display_name",
440    /**
441     * Parent folder file id
442     * @since 8
443     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
444     */
445    PARENT = "parent",
446    /**
447     * Mime type of the file
448     * @since 8
449     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
450     */
451    MIME_TYPE = "mime_type",
452    /**
453     * Media type of the file
454     * @since 8
455     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
456     */
457    MEDIA_TYPE = "media_type",
458    /**
459     * Size of the file
460     * @since 8
461     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
462     */
463    SIZE = "size",
464    /**
465     * Date of the file creation
466     * @since 8
467     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
468     */
469    DATE_ADDED = "date_added",
470    /**
471     * Modify date of the file
472     * @since 8
473     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
474     */
475    DATE_MODIFIED = "date_modified",
476    /**
477     * Date taken of the file
478     * @since 8
479     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
480     */
481    DATE_TAKEN = "date_taken",
482    /**
483     * Title of the file
484     * @since 8
485     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
486     */
487    TITLE = "title",
488    /**
489     * Artist of the audio file
490     * @since 8
491     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
492     */
493    ARTIST = "artist",
494    /**
495     * Audio album of the audio file
496     * @since 8
497     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
498     */
499    AUDIOALBUM = "audio_album",
500    /**
501     * Duration of the audio and video file
502     * @since 8
503     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
504     */
505    DURATION = "duration",
506    /**
507     * Width of the image file
508     * @since 8
509     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
510     */
511    WIDTH = "width",
512    /**
513     * Height of the image file
514     * @since 8
515     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
516     */
517    HEIGHT = "height",
518    /**
519     * Orientation of the image file
520     * @since 8
521     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
522     */
523    ORIENTATION = "orientation",
524    /**
525     * Album id of the file
526     * @since 8
527     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
528     */
529    ALBUM_ID = "bucket_id",
530    /**
531     * Album name of the file
532     * @since 8
533     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
534     */
535    ALBUM_NAME = "bucket_display_name",
536  }
537
538  /**
539   * Fetch parameters applicable on images, videos, audios, albums and other media
540   * @since 7
541   * @syscap SystemCapability.Multimedia.MediaLibrary.Core
542   */
543  interface MediaFetchOptions {
544    /**
545     * Fields to retrieve, for example, selections: "media_type =? OR media_type =?".
546     * @since 7
547     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
548     */
549    selections: string;
550    /**
551     * Conditions for retrieval, for example, selectionArgs: [IMAGE, VIDEO].
552     * @since 7
553     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
554     */
555    selectionArgs: Array<string>;
556    /**
557     * Sorting criterion of the retrieval results, for example, order: "datetaken DESC,display_name DESC, file_id DESC".
558     * @since 7
559     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
560     */
561    order?: string;
562    /**
563     * uri for retrieval
564     * @since 8
565     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
566     */
567    uri?: string;
568    /**
569     * networkId for retrieval
570     * @since 8
571     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
572     */
573    networkId?: string;
574    /**
575     * extendArgs for retrieval
576     * @since 8
577     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
578     */
579    extendArgs?: string;
580  }
581
582  /**
583   * Implements file retrieval.
584   * @since 7
585   * @syscap SystemCapability.Multimedia.MediaLibrary.Core
586   * @import import mediaLibrary from '@ohos.multimedia.mediaLibrary'
587   */
588  interface FetchFileResult {
589    /**
590     * Obtains the total number of files in the file retrieval result.
591     * @since 7
592     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
593     * @return Total number of files.
594     */
595    getCount(): number;
596    /**
597     * Checks whether the result set points to the last row.
598     * @since 7
599     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
600     * @return Whether the file is the last one.
601     * You need to check whether the file is the last one before calling getNextObject,
602     * which returns the next file only when True is returned for this method.
603     */
604    isAfterLast(): boolean;
605    /**
606     * Releases the FetchFileResult instance and invalidates it. Other methods cannot be called.
607     * @since 7
608     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
609     */
610    close(): void;
611    /**
612     * Obtains the first FileAsset in the file retrieval result. This method uses a callback to return the file.
613     * @since 7
614     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
615     * @param callback Callback used to return the file in the format of a FileAsset instance.
616     */
617    getFirstObject(callback: AsyncCallback<FileAsset>): void;
618    /**
619     * Obtains the first FileAsset in the file retrieval result. This method uses a promise to return the file.
620     * @since 7
621     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
622     * @return A Promise instance used to return the file in the format of a FileAsset instance.
623     */
624    getFirstObject(): Promise<FileAsset>;
625    /**
626     * Obtains the next FileAsset in the file retrieval result.
627     * This method uses a callback to return the file.
628     * Before calling this method, you must use isAfterLast() to check whether the result set points to the last row.
629     * This method returns the next file only when True is returned for isAfterLast().
630     * @since 7
631     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
632     * @param callback Callback used to return the file in the format of a FileAsset instance.
633     */
634    getNextObject(callback: AsyncCallback<FileAsset>): void;
635    /**
636     * Obtains the next FileAsset in the file retrieval result.
637     * This method uses a promise to return the file.
638     * Before calling this method, you must use isAfterLast() to check whether the result set points to the last row.
639     * This method returns the next file only when True is returned for isAfterLast().
640     * @since 7
641     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
642     * @return A Promise instance used to return the file in the format of a FileAsset instance.
643     */
644    getNextObject(): Promise<FileAsset>;
645    /**
646     * Obtains the last FileAsset in the file retrieval result. This method uses a callback to return the file.
647     * @since 7
648     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
649     * @param callback Callback used to return the file in the format of a FileAsset instance.
650     */
651    getLastObject(callback: AsyncCallback<FileAsset>): void;
652    /**
653     * Obtains the last FileAsset in the file retrieval result. This method uses a promise to return the file.
654     * @since 7
655     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
656     * @return A Promise instance used to return the file in the format of a FileAsset instance.
657     */
658    getLastObject(): Promise<FileAsset>;
659    /**
660     * Obtains the FileAsset with the specified index in the file retrieval result.
661     * This method uses a callback to return the file.
662     * @since 7
663     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
664     * @param index Index of the file to obtain.
665     * @param callback Callback used to return the file in the format of a FileAsset instance.
666     */
667    getPositionObject(index: number, callback: AsyncCallback<FileAsset>): void;
668    /**
669     * Obtains the FileAsset with the specified index in the file retrieval result.
670     * This method uses a promise to return the file.
671     * @since 7
672     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
673     * @param index Index of the file to obtain.
674     * @return A Promise instance used to return the file in the format of a FileAsset instance.
675     */
676    getPositionObject(index: number): Promise<FileAsset>;
677     /**
678     * Obtains all FileAssets in the file retrieval result.
679     * This method uses a callback to return the result. After this method is called,
680     * close() is automatically called to release the FetchFileResult instance and invalidate it.
681     * In this case, other methods cannot be called.
682     * @since 7
683     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
684     * @param callback Callback used to return a FileAsset array.
685     */
686    getAllObject(callback: AsyncCallback<Array<FileAsset>>): void;
687    /**
688     * Obtains all FileAssets in the file retrieval result.
689     * This method uses a promise to return the result. that store the selected media resources.
690     * close() is automatically called to release the FetchFileResult instance and invalidate it.
691     * In this case, other methods cannot be called.
692     * @since 7
693     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
694     * @return A Promise instance used to return a FileAsset array.
695     */
696    getAllObject(): Promise<Array<FileAsset>>;
697  }
698
699  /**
700   * Defines the album.
701   *
702   * @syscap SystemCapability.Multimedia.MediaLibrary.Core
703   * @since 7
704   */
705  interface Album {
706    /**
707     * Album ID.
708     * @since 7
709     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
710     */
711    readonly albumId: number;
712    /**
713     * Album name.
714     * @since 7
715     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
716     */
717    albumName: string;
718    /**
719     * Album uri.
720     * @since 8
721     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
722     */
723    readonly albumUri: string;
724    /**
725     * Date (timestamp) when the album was last modified.
726     * @since 7
727     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
728     */
729    readonly dateModified: number;
730    /**
731     * File count for the album
732     * @since 8
733     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
734     */
735    readonly count: number;
736    /**
737     * Relative path for the album
738     * @since 8
739     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
740     */
741    readonly relativePath: string;
742    /**
743     * coverUri for the album
744     * @since 8
745     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
746     */
747    readonly coverUri: string;
748
749    /**
750     * Modify the meta data for the album
751     * @since 8
752     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
753     * @permission ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
754     * @param callback, no value will be returned.
755     */
756    commitModify(callback: AsyncCallback<void>): void;
757    /**
758     * Modify the meta data for the album
759     * @since 8
760     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
761     * @permission ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
762     */
763    commitModify(): Promise<void>;
764    /**
765     * SObtains files in an album. This method uses an asynchronous callback to return the files.
766     * @since 7
767     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
768     * @permission ohos.permission.READ_MEDIA
769     * @param callback Callback used to return the files in the format of a FetchFileResult instance.
770     */
771    getFileAssets(callback: AsyncCallback<FetchFileResult>): void;
772    /**
773     * SObtains files in an album. This method uses an asynchronous callback to return the files.
774     * @since 7
775     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
776     * @permission ohos.permission.READ_MEDIA
777     * @param option Media retrieval options.
778     * @param callback Callback used to return the files in the format of a FetchFileResult instance.
779     */
780    getFileAssets(options: MediaFetchOptions, callback: AsyncCallback<FetchFileResult>): void;
781    /**
782     * Obtains files in an album. This method uses a promise to return the files.
783     * @since 7
784     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
785     * @permission ohos.permission.READ_MEDIA
786     * @param option Media retrieval options.
787     * @return A Promise instance used to return the files in the format of a FetchFileResult instance.
788     */
789    getFileAssets(options?: MediaFetchOptions): Promise<FetchFileResult>;
790  }
791
792  /**
793   * Enumeration public directory that predefined
794   * @since 8
795   * @syscap SystemCapability.Multimedia.MediaLibrary.Core
796   */
797  enum DirectoryType {
798    /**
799     * predefined public directory for files token by Camera.
800     * @since 8
801     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
802     */
803    DIR_CAMERA = 0,
804    /**
805     * predefined public directory for VIDEO files.
806     * @since 8
807     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
808     */
809    DIR_VIDEO,
810    /**
811     * predefined public directory for IMAGE files.
812     * @since 8
813     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
814     */
815    DIR_IMAGE,
816    /**
817     * predefined public directory for AUDIO files.
818     * @since 8
819     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
820     */
821    DIR_AUDIO,
822    /**
823     * predefined public directory for DOCUMENTS files.
824     * @since 8
825     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
826     */
827    DIR_DOCUMENTS,
828    /**
829     * predefined public directory for DOWNLOAD files.
830     * @since 8
831     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
832     */
833    DIR_DOWNLOAD
834  }
835
836  /**
837   * Defines the MediaLibrary class and provides functions to access the data in media storage.
838   *
839   * @syscap SystemCapability.Multimedia.MediaLibrary.Core
840   * @since 6
841   */
842  interface MediaLibrary {
843    /**
844     * get system predefined root dir, use to create file asset by relative path
845     * @since 8
846     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
847     * @param type, public directory predefined in DirectoryType.
848     * @param callback Callback return the FetchFileResult.
849     */
850    getPublicDirectory(type: DirectoryType, callback: AsyncCallback<string>): void;
851    /**
852     * get system predefined root dir, use to create file asset by relative path
853     * @since 8
854     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
855     * @param type public directory predefined in DirectoryType.
856     * @return A promise instance used to return the public directory in the format of string
857     */
858    getPublicDirectory(type: DirectoryType): Promise<string>;
859    /**
860     * query all assets just for count & first cover
861     * if need all data, getAllObject from FetchFileResult
862     * @since 7
863     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
864     * @permission ohos.permission.READ_MEDIA
865     * @param options, Media retrieval options.
866     * @param callback, Callback return the FetchFileResult.
867     */
868    getFileAssets(options: MediaFetchOptions, callback: AsyncCallback<FetchFileResult>): void;
869    /**
870     * query all assets just for count & first cover
871     * if need all data, getAllObject from FetchFileResult
872     * @since 7
873     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
874     * @permission ohos.permission.READ_MEDIA
875     * @param options Media retrieval options.
876     * @return A promise instance used to return the files in the format of a FetchFileResult instance
877     */
878    getFileAssets(options: MediaFetchOptions): Promise<FetchFileResult>;
879    /**
880     * Turn on mornitor the data changes by media type
881     * @since 8
882     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
883     * @param type one of 'deviceChange','albumChange','imageChange','audioChange','videoChange','fileChange','remoteFileChange'
884     * @param callback no value returned
885     */
886    on(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'|'videoChange'|'fileChange'|'remoteFileChange', callback: Callback<void>): void;
887    /**
888     * Turn off mornitor the data changes by media type
889     * @since 8
890     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
891     * @param type one of 'deviceChange','albumChange','imageChange','audioChange','videoChange','fileChange','remoteFileChange'
892     * @param callback no value returned
893     */
894     off(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'|'videoChange'|'fileChange'|'remoteFileChange', callback?: Callback<void>): void;
895    /**
896     * Create File Asset
897     * @since 8
898     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
899     * @permission ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
900     * @param mediaType mediaType for example:IMAGE, VIDEO, AUDIO, FILE
901     * @param displayName file name
902     * @param relativePath relative path
903     * @param callback Callback used to return the FileAsset
904     */
905    createAsset(mediaType: MediaType, displayName: string, relativePath: string, callback: AsyncCallback<FileAsset>): void;
906    /**
907     * Create File Asset
908     * @since 8
909     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
910     * @permission ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
911     * @param mediaType mediaType for example:IMAGE, VIDEO, AUDIO, FILE
912     * @param displayName file name
913     * @param relativePath relative path
914     * @return A Promise instance used to return the FileAsset
915     */
916    createAsset(mediaType: MediaType, displayName: string, relativePath: string): Promise<FileAsset>;
917    /**
918     * Delete File Asset
919     * @since 8
920     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
921     * @permission ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
922     * @param uri FileAsset's URI
923     * @param callback no value returned
924     * @systemapi
925     */
926    deleteAsset(uri: string, callback: AsyncCallback<void>): void;
927    /**
928     * Delete File Asset
929     * @since 8
930     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
931     * @permission ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
932     * @param uri, FileAsset's URI
933     * @return A Promise instance, no value returned
934     * @systemapi
935     */
936    deleteAsset(uri: string): Promise<void>;
937    /**
938     * Obtains albums based on the media retrieval options. This method uses an asynchronous callback to return.
939     * @since 7
940     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
941     * @permission ohos.permission.READ_MEDIA
942     * @param option Media retrieval options.
943     * @param callback Callback used to return an album array.
944     */
945    getAlbums(options: MediaFetchOptions, callback: AsyncCallback<Array<Album>>): void;
946    /**
947     * Obtains albums based on the media retrieval options. This method uses a promise to return the albums.
948     * @since 7
949     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
950     * @permission ohos.permission.READ_MEDIA
951     * @param option Media retrieval options.
952     * @return A Promise instance used to return an album array.
953     */
954    getAlbums(options: MediaFetchOptions): Promise<Array<Album>>;
955    /**
956     * Stores media resources. This method uses an asynchronous callback to return the URI that stores
957     * the media resources.
958     * @since 6
959     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
960     * @param option Media resource option.
961     * @param callback Callback used to return the URI that stores the media resources.
962     */
963    storeMediaAsset(option: MediaAssetOption, callback: AsyncCallback<string>): void;
964    /**
965     * Stores media resources. This method uses a promise to return the URI that stores the media resources.
966     * @since 6
967     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
968     * @param option Media resource option.
969     * @return Promise used to return the URI that stores the media resources.
970     */
971    storeMediaAsset(option: MediaAssetOption): Promise<string>;
972    /**
973     * Starts image preview, with the first image to preview specified. This method uses an asynchronous callback
974     * to receive the execution result.
975     * @since 6
976     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
977     * @param images List of images to preview.
978     * @param index Sequence number of the first image to preview.
979     * @param callback Callback used for image preview. No value is returned.
980     */
981    startImagePreview(images: Array<string>, index: number, callback: AsyncCallback<void>): void;
982    /**
983     * Starts image preview. This method uses an asynchronous callback to receive the execution result.
984     * @since 6
985     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
986     * @param images List of images to preview.
987     * @param callback Callback used for image preview. No value is returned.
988     */
989    startImagePreview(images: Array<string>, callback: AsyncCallback<void>): void;
990    /**
991     * Starts image preview, with the first image to preview specified.
992     * This method uses a promise to return the execution result.
993     * @since 6
994     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
995     * @param images List of images to preview.
996     * @param index Sequence number of the first image to preview.
997     * @return Promise used to return whether the operation is successful.
998     */
999    startImagePreview(images: Array<string>, index?: number): Promise<void>;
1000    /**
1001     * Starts media selection. This method uses an asynchronous callback to
1002     * return the list of URIs that store the selected media resources.
1003     * @since 6
1004     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
1005     * @param option Media selection option.
1006     * @param callback Callback used to return the list of URIs that store the selected media resources.
1007     */
1008    startMediaSelect(option: MediaSelectOption, callback: AsyncCallback<Array<string>>): void;
1009    /**
1010     * Starts media selection. This method uses a promise to return the list of URIs
1011     * that store the selected media resources.
1012     * @since 6
1013     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
1014     * @param option Media selection option.
1015     * @return Promise used to return the list of URIs that store the selected media resources.
1016     */
1017    startMediaSelect(option: MediaSelectOption): Promise<Array<string>>;
1018    /**
1019     * Get Active Peer device information
1020     * @since 8
1021     * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore
1022     * @permission ohos.permission.READ_MEDIA
1023     * @systemapi
1024     * @param callback, Callback return the list of the active peer devices' information
1025     */
1026    getActivePeers(callback: AsyncCallback<Array<PeerInfo>>): void;
1027    /**
1028     * Get Active Peer device information
1029     * @since 8
1030     * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore
1031     * @permission ohos.permission.READ_MEDIA
1032     * @systemapi
1033     * @return Promise used to return the list of the active peer devices' information
1034     */
1035    getActivePeers(): Promise<Array<PeerInfo>>;
1036    /**
1037     * Get all the peer devices' information
1038     * @since 8
1039     * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore
1040     * @permission ohos.permission.READ_MEDIA
1041     * @systemapi
1042     * @param callback Callback return the list of the all the peer devices' information
1043     */
1044    getAllPeers(callback: AsyncCallback<Array<PeerInfo>>): void;
1045    /**
1046     * Get all the peer devices' information
1047     * @since 8
1048     * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore
1049     * @permission ohos.permission.READ_MEDIA
1050     * @systemapi
1051     * @return Promise used to return the list of the all the peer devices' information
1052     */
1053    getAllPeers(): Promise<Array<PeerInfo>>;
1054    /**
1055     * Release MediaLibrary instance
1056     * @since 8
1057     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
1058     * @param callback no value returned
1059     */
1060    release(callback: AsyncCallback<void>): void;
1061    /**
1062     * Release MediaLibrary instance
1063     * @since 8
1064     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
1065     */
1066    release(): Promise<void>;
1067  }
1068
1069  /**
1070   * thumbnail's size which have width and heigh
1071   * @syscap SystemCapability.Multimedia.MediaLibrary.Core
1072   * @since 8
1073   */
1074  interface Size {
1075    /**
1076     * Width of image file
1077     * @since 8
1078     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
1079     */
1080    width: number;
1081    /**
1082     * Height of image file
1083     * @since 8
1084     * @syscap SystemCapability.Multimedia.MediaLibrary.Core
1085     */
1086    height: number;
1087  }
1088
1089  /**
1090   * peer devices' information
1091   * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore
1092   * @systemapi
1093   * @since 8
1094   */
1095  interface PeerInfo {
1096    /**
1097     * Peer device name
1098     * @since 8
1099     * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore
1100     * @systemapi
1101     */
1102    readonly deviceName: string;
1103    /**
1104     * Peer device network id
1105     * @since 8
1106     * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore
1107     * @systemapi
1108     */
1109    readonly networkId: string;
1110    /**
1111     * Peer device type
1112     * @since 8
1113     * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore
1114     * @systemapi
1115     */
1116    readonly deviceType: DeviceType;
1117    /**
1118     * Peer device online status
1119     * @since 8
1120     * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore
1121     * @systemapi
1122     */
1123    readonly isOnline: boolean;
1124  }
1125
1126  /**
1127   * peer device type
1128   * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore
1129   * @systemapi
1130   * @since 8
1131   */
1132  enum DeviceType {
1133    /**
1134     * Unknow device type
1135     * @since 8
1136     * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore
1137     * @systemapi
1138     */
1139    TYPE_UNKNOWN = 0,
1140    /**
1141     * Laptop device
1142     * @since 8
1143     * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore
1144     * @systemapi
1145     */
1146    TYPE_LAPTOP,
1147    /**
1148     * Phone device
1149     * @since 8
1150     * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore
1151     * @systemapi
1152     */
1153    TYPE_PHONE,
1154    /**
1155     * Tablet device
1156     * @since 8
1157     * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore
1158     * @systemapi
1159     */
1160    TYPE_TABLET,
1161    /**
1162     * Watch device
1163     * @since 8
1164     * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore
1165     * @systemapi
1166     */
1167    TYPE_WATCH,
1168    /**
1169     * Car device
1170     * @since 8
1171     * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore
1172     * @systemapi
1173     */
1174    TYPE_CAR,
1175    /**
1176     * TV device
1177     * @since 8
1178     * @syscap SystemCapability.Multimedia.MediaLibrary.DistributedCore
1179     * @systemapi
1180     */
1181    TYPE_TV
1182  }
1183}
1184
1185export default mediaLibrary;
1186