Welcome What's new in Chrome extensions API reference Samples
Welcome What's new in Chrome extensions API reference Samples

chrome.mediaGalleries

This API is part of the Chrome Apps platform, which was deprecated in 2020. It remains supported for Enterprise and Education customers on ChromeOS until at least Jan 2025. Learn more about migrating your app.
  • 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
    mediaGalleries

Summary

Types

AddGalleryWatchResult

Properties

  • galleryId

    string

  • success

    boolean

GalleryChangeDetails

Properties

  • galleryId

    string

    Identifies the modified gallery.

  • 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.

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.

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.

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

  • 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

  • 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

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

chrome.mediaGalleries.addGalleryWatch(
  galleryId: string,
  callback?: function,
)
Promise

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

Returns

  • Chrome 116+

    Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.

addUserSelectedFolder

chrome.mediaGalleries.addUserSelectedFolder(
  callback: function,
)

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: (mediaFileSystems: DOMFileSystem[], selectedFileSystemName: string) => void

    • mediaFileSystems

      DOMFileSystem[]

    • selectedFileSystemName

      string

getMediaFileSystemMetadata

chrome.mediaGalleries.getMediaFileSystemMetadata(
  mediaFileSystem: DOMFileSystem,
)

Get metadata about a specific media file system.

Parameters

  • mediaFileSystem

    DOMFileSystem

Returns

getMediaFileSystems

chrome.mediaGalleries.getMediaFileSystems(
  details?: MediaFileSystemsDetails,
  callback?: function,
)
Promise

Get the media galleries configured in this user agent. If none are configured or available, the callback will receive an empty array.

Parameters

  • details
  • callback

    function optional

    The callback parameter looks like: (mediaFileSystems: DOMFileSystem[]) => void

    • mediaFileSystems

      DOMFileSystem[]

Returns

  • Promise<DOMFileSystem[]>

    Chrome 116+

    Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.

getMetadata

chrome.mediaGalleries.getMetadata(
  mediaFile: Blob,
  options?: MediaMetadataOptions,
  callback?: function,
)
Promise

Gets the media-specific metadata for a media file. This should work for files in media galleries as well as other DOM filesystems.

Parameters

Returns

  • Promise<MediaMetadata>

    Chrome 116+

    Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.

removeGalleryWatch

chrome.mediaGalleries.removeGalleryWatch(
  galleryId: string,
)

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

Parameters

  • galleryId

    string

Events

onGalleryChanged

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

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

Parameters

This site uses cookies to deliver and enhance the quality of its services and to analyze traffic. If you agree, cookies are also used to serve advertising and to personalize the content and advertisements that you see. Learn more about our use of cookies.