<br />

> [!NOTE]
> **Important:** This API works **only on ChromeOS**.

<br />

<br />

## Description

Use the `chrome.mediaGalleries` API to access media files (audio, images, video) from the user's local disks (with the user's consent).

<br />

<br />

## Permissions

`mediaGalleries`  

<br />

<br />

## Availability

ChromeOS only

<br />

<br />

<br />

## Types

### AddGalleryWatchResult

#### Properties

- galleryId string
- success boolean

### GalleryChangeDetails

#### Properties

- galleryId string

  Identifies the modified gallery.
- type [GalleryChangeType](https://developer.chrome.com/docs/apps/reference/mediaGalleries#type-GalleryChangeType)

  Type of change event.

### GalleryChangeType

#### Enum

"contents_changed"   
The contents of the gallery have changed.
"watch_dropped"   
The watch has been dropped because the device has been detached, the gallery permission has been removed, or any other reason.

<br />

### GetMediaFileSystemsInteractivity

#### Enum

"no"   
Do not act interactively.
"yes"   
Ask the user to manage permitted media galleries.
"if_needed"   
Ask the user to manage permitted galleries only if the return set would otherwise be empty.

<br />

### GetMetadataType

#### Enum

"all"   
Retrieve the mime type, metadata tags, and attached images.
"mimeTypeAndTags"   
Retrieve only the mime type and the metadata tags.
"mimeTypeOnly"   
Retrieve only the mime type.

<br />

### MediaFileSystemMetadata

#### Properties

- deviceId string optional

  If the media gallery is on a removable device, a unique id for the device while the device is online.
- galleryId string

  A unique and persistent id for the media gallery.
- isAvailable boolean

  True if the device is currently available.
- isMediaDevice boolean

  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.
- isRemovable boolean

  True if the media gallery is on a removable device.
- name string

  The name of the file system.

### MediaFileSystemsDetails

#### Properties

- interactive [GetMediaFileSystemsInteractivity](https://developer.chrome.com/docs/apps/reference/mediaGalleries#type-GetMediaFileSystemsInteractivity) 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

- album string optional

  Defined for audio and video.
- artist string optional
- attachedImages Blob\[\]

  The images embedded in the media file's metadata. This is most often used for album art or video thumbnails.
- comment string optional
- copyright string optional
- disc number optional
- duration number optional

  Defined for audio and video. In seconds.
- genre string optional
- height number optional

  Defined for video. In pixels.
- language string optional
- mimeType string

  The browser sniffed mime type.
- rawTags [StreamInfo](https://developer.chrome.com/docs/apps/reference/mediaGalleries#type-StreamInfo)\[\]

  All the metadata in the media file. For formats with multiple streams, stream order will be preserved. Container metadata is the first element.
- rotation number optional

  Defined for video. In degrees.
- title string optional
- track number optional
- width number optional

### MediaMetadataOptions

#### Properties

- metadataType [GetMetadataType](https://developer.chrome.com/docs/apps/reference/mediaGalleries#type-GetMetadataType) optional

  Specifies which subset of the metadata to retrieve. Defaults to 'all' if the option is omitted.

### StreamInfo

#### Properties

- tags object

  An unfiltered string-\>string dictionary of tags for the stream.
- type string

  Describes format of container or codec of stream, i.e. "mp3", "h264".

## Methods

### addGalleryWatch()

Promise

```typescript
chrome.mediaGalleries.addGalleryWatch(
  galleryId: string,
  callback?: function,
): Promise<https://developer.chrome.com/docs/apps/reference/mediaGalleries#type-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

- galleryId string
- callback function optional


  The `callback` parameter looks like:

  ```typescript
  (result: AddGalleryWatchResult) => void
  ```

  <br />

  - result [AddGalleryWatchResult](https://developer.chrome.com/docs/apps/reference/mediaGalleries#type-AddGalleryWatchResult)

#### Returns

- Promise\<[AddGalleryWatchResult](https://developer.chrome.com/docs/apps/reference/mediaGalleries#type-AddGalleryWatchResult)\>
  Chrome 116+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### addUserSelectedFolder()

```typescript
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

- callback function


  The `callback` parameter looks like:

  ```typescript
  (mediaFileSystems: DOMFileSystem[], selectedFileSystemName: string) => void
  ```

  <br />

  - mediaFileSystems DOMFileSystem\[\]
  - selectedFileSystemName string

### getMediaFileSystemMetadata()

```typescript
chrome.mediaGalleries.getMediaFileSystemMetadata(
  mediaFileSystem: DOMFileSystem,
): MediaFileSystemMetadata | undefined
```

Get metadata about a specific media file system.

#### Parameters

- mediaFileSystem DOMFileSystem

#### Returns

- [MediaFileSystemMetadata](https://developer.chrome.com/docs/apps/reference/mediaGalleries#type-MediaFileSystemMetadata) \| undefined

### getMediaFileSystems()

Promise

```typescript
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

- details [MediaFileSystemsDetails](https://developer.chrome.com/docs/apps/reference/mediaGalleries#type-MediaFileSystemsDetails) optional
- callback function optional


  The `callback` parameter looks like:

  ```typescript
  (mediaFileSystems: DOMFileSystem[]) => void
  ```

  <br />

  - mediaFileSystems DOMFileSystem\[\]

#### Returns

- Promise\<DOMFileSystem\[\]\>
  Chrome 116+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### getMetadata()

Promise

```typescript
chrome.mediaGalleries.getMetadata(
  mediaFile: Blob,
  options?: MediaMetadataOptions,
  callback?: function,
): Promise<https://developer.chrome.com/docs/apps/reference/mediaGalleries#type-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

- mediaFile Blob
- options [MediaMetadataOptions](https://developer.chrome.com/docs/apps/reference/mediaGalleries#type-MediaMetadataOptions) optional
- callback function optional


  The `callback` parameter looks like:

  ```typescript
  (metadata: MediaMetadata) => void
  ```

  <br />

  - metadata [MediaMetadata](https://developer.chrome.com/docs/apps/reference/mediaGalleries#type-MediaMetadata)

#### Returns

- Promise\<[MediaMetadata](https://developer.chrome.com/docs/apps/reference/mediaGalleries#type-MediaMetadata)\>
  Chrome 116+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### removeGalleryWatch()

```typescript
chrome.mediaGalleries.removeGalleryWatch(
  galleryId: string,
): void
```

Removes a gallery watch for the gallery with the specified gallery ID.

#### Parameters

- galleryId string

## Events

### onGalleryChanged

```typescript
chrome.mediaGalleries.onGalleryChanged.addListener(
  callback: function,
)
```

Fired when a media gallery is changed or a gallery watch is dropped.

#### Parameters

- callback function


  The `callback` parameter looks like:

  ```typescript
  (details: GalleryChangeDetails) => void
  ```

  <br />

  - details [GalleryChangeDetails](https://developer.chrome.com/docs/apps/reference/mediaGalleries#type-GalleryChangeDetails)

<br />