Description
Use the chrome.mediaGalleries API to access media files (audio, images, video) from the user's local disks (with the user's consent).
Permissions
mediaGalleriesTypes
AddGalleryWatchResult
Properties
- 
    galleryIdstring 
- 
    successboolean 
GalleryChangeDetails
Properties
- 
    galleryIdstring Identifies the modified gallery. 
- 
    typeType of change event. 
GalleryChangeType
Enum
"contents_changed"  "watch_dropped" 
 The contents of the gallery have changed.
 The watch has been dropped because the device has been detached, the gallery permission has been removed, or any other reason.
GetMediaFileSystemsInteractivity
Enum
"no"  "yes"  "if_needed" 
 Do not act interactively.
 Ask the user to manage permitted media galleries.
 Ask the user to manage permitted galleries only if the return set would otherwise be empty.
GetMetadataType
Enum
"all"  "mimeTypeAndTags"  "mimeTypeOnly" 
 Retrieve the mime type, metadata tags, and attached images.
 Retrieve only the mime type and the metadata tags.
 Retrieve only the mime type.
MediaFileSystemMetadata
Properties
- 
    deviceIdstring optional If the media gallery is on a removable device, a unique id for the device while the device is online. 
- 
    galleryIdstring A unique and persistent id for the media gallery. 
- 
    isAvailableboolean True if the device is currently available. 
- 
    isMediaDeviceboolean True if the device the media gallery is on was detected as a media device. i.e. a PTP or MTP device, or a DCIM directory is present. 
- 
    isRemovableboolean True if the media gallery is on a removable device. 
- 
    namestring The name of the file system. 
MediaFileSystemsDetails
Properties
- 
    interactiveGetMediaFileSystemsInteractivity optional Whether to prompt the user for permission to additional media galleries before returning the permitted set. Default is silent. If the value 'yes' is passed, or if the application has not been granted access to any media galleries and the value 'if_needed' is passed, then the media gallery configuration dialog will be displayed. 
MediaMetadata
Properties
- 
    albumstring optional Defined for audio and video. 
- 
    artiststring optional 
- 
    attachedImagesBlob[] The images embedded in the media file's metadata. This is most often used for album art or video thumbnails. 
- 
    commentstring optional 
- 
    copyrightstring optional 
- 
    discnumber optional 
- 
    durationnumber optional Defined for audio and video. In seconds. 
- 
    genrestring optional 
- 
    heightnumber optional Defined for video. In pixels. 
- 
    languagestring optional 
- 
    mimeTypestring The browser sniffed mime type. 
- 
    rawTagsAll the metadata in the media file. For formats with multiple streams, stream order will be preserved. Container metadata is the first element. 
- 
    rotationnumber optional Defined for video. In degrees. 
- 
    titlestring optional 
- 
    tracknumber optional 
- 
    widthnumber optional 
MediaMetadataOptions
Properties
- 
    metadataTypeGetMetadataType optional Specifies which subset of the metadata to retrieve. Defaults to 'all' if the option is omitted. 
StreamInfo
Properties
- 
    tagsobject An unfiltered string->string dictionary of tags for the stream. 
- 
    typestring Describes format of container or codec of stream, i.e. "mp3", "h264". 
Methods
addGalleryWatch()
chrome.mediaGalleries.addGalleryWatch(
galleryId: string,
callback?: function,
): Promise<AddGalleryWatchResult>
Adds a gallery watch for the gallery with the specified gallery ID. The given callback is then fired with a success or failure result.
Parameters
- 
    galleryIdstring 
- 
    callbackfunction optional The callbackparameter looks like:(result: AddGalleryWatchResult) => void - 
    result
 
- 
    
Returns
- 
            Promise<AddGalleryWatchResult> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
addUserSelectedFolder()
chrome.mediaGalleries.addUserSelectedFolder(
callback: function,
): void
Present a directory picker to the user and add the selected directory as a gallery. If the user cancels the picker, selectedFileSystemName will be empty. A user gesture is required for the dialog to display. Without a user gesture, the callback will run as though the user canceled.
Parameters
- 
    callbackfunction The callbackparameter looks like:(mediaFileSystems: DOMFileSystem[], selectedFileSystemName: string) => void - 
    mediaFileSystemsDOMFileSystem[] 
- 
    selectedFileSystemNamestring 
 
- 
    
getMediaFileSystemMetadata()
chrome.mediaGalleries.getMediaFileSystemMetadata(
mediaFileSystem: DOMFileSystem,
): MediaFileSystemMetadata | undefined
Get metadata about a specific media file system.
Parameters
- 
    mediaFileSystemDOMFileSystem 
Returns
- 
            MediaFileSystemMetadata | undefined 
getMediaFileSystems()
chrome.mediaGalleries.getMediaFileSystems(
details?: MediaFileSystemsDetails,
callback?: function,
): Promise<DOMFileSystem[]>
Get the media galleries configured in this user agent. If none are configured or available, the callback will receive an empty array.
Parameters
- 
    detailsMediaFileSystemsDetails optional 
- 
    callbackfunction optional The callbackparameter looks like:(mediaFileSystems: DOMFileSystem[]) => void - 
    mediaFileSystemsDOMFileSystem[] 
 
- 
    
Returns
- 
            Promise<DOMFileSystem[]> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
getMetadata()
chrome.mediaGalleries.getMetadata(
mediaFile: Blob,
options?: MediaMetadataOptions,
callback?: function,
): Promise<MediaMetadata>
Gets the media-specific metadata for a media file. This should work for files in media galleries as well as other DOM filesystems.
Parameters
- 
    mediaFileBlob 
- 
    optionsMediaMetadataOptions optional 
- 
    callbackfunction optional The callbackparameter looks like:(metadata: MediaMetadata) => void - 
    metadata
 
- 
    
Returns
- 
            Promise<MediaMetadata> Chrome 116+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks. 
removeGalleryWatch()
chrome.mediaGalleries.removeGalleryWatch(
galleryId: string,
): void
Removes a gallery watch for the gallery with the specified gallery ID.
Parameters
- 
    galleryIdstring 
Events
onGalleryChanged
chrome.mediaGalleries.onGalleryChanged.addListener(
callback: function,
)
Fired when a media gallery is changed or a gallery watch is dropped.
Parameters
- 
    callbackfunction The callbackparameter looks like:(details: GalleryChangeDetails) => void - 
    details
 
-