New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@capacitor-community/media

Package Overview
Dependencies
Maintainers
42
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@capacitor-community/media

Enable some media features for Capacitor such as create albums, save videos, gifs and more.

  • 5.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4K
decreased by-77.78%
Maintainers
42
Weekly downloads
 
Created
Source


Capacitor Media

@capacitor-community/media

Capacitor community plugin for enabling extra media capabilities


Sponsors

Intenseloop

Maintainers

MaintainerGitHubSocial
Nisala Kalupahanankalupahana
Stewan Silvastewones@StewanSilva

Installation

Run one of the following commands, based on what you're using:

npm install @capacitor-community/media # NPM
yarn add @capacitor-community/media # Yarn

This plugin is currently for Capacitor 5. Add an @4 at the end to install for Capacitor 4.

After installing, be sure to sync by running ionic cap sync.

Migrating to Capacitor 5

A major breaking change has been made to this plugin: Saving media on Android now takes an album identifier instead of an album name. The album identifier, like on iOS, can be obtained using getAlbums(). (This call will now also return empty albums made by the plugin.) To ensure people notice this significant change, the property has been renamed from album to albumIdentifier, which will need to be updated in your code. It is still optional on iOS.

API

Unless otherwise noted, there should be full feature parity between iOS and Android. Web is not supported.

getMedias(...)

getMedias(options?: MediaFetchOptions | undefined) => Promise<MediaResponse>

Get filtered media from camera roll (pictures only currently). iOS only.

Code Examples

ParamType
optionsMediaFetchOptions

Returns: Promise<MediaResponse>


getAlbums()

getAlbums() => Promise<MediaAlbumResponse>

Get list of albums.

Code Examples

Returns: Promise<MediaAlbumResponse>


savePhoto(...)

savePhoto(options?: MediaSaveOptions | undefined) => Promise<PhotoResponse>

Saves a photo to the camera roll.

On Android and iOS, this supports web URLs, base64 encoded images (e.g. data:image/jpeg;base64,...), and local files. On Android, all image formats supported by the user's photo viewer are supported.

On iOS, all image formats supported by SDWebImage are supported. All images on iOS are converted to PNG for system compatability.

Code Examples

ParamType
optionsMediaSaveOptions

Returns: Promise<PhotoResponse>


saveVideo(...)

saveVideo(options?: MediaSaveOptions | undefined) => Promise<PhotoResponse>

Saves a video to the camera roll.

On Android and iOS, this supports web URLs, base64 encoded videos (e.g. data:image/mp4;base64,...), and local files. On Android, all video formats supported by the user's photo viewer are supported. On iOS, the supported formats are based on whatever iOS supports at the time.

Code Examples

ParamType
optionsMediaSaveOptions

Returns: Promise<PhotoResponse>


saveGif(...)

saveGif(options?: MediaSaveOptions | undefined) => Promise<PhotoResponse>

Saves an animated GIF to the camera roll.

On Android and iOS, this supports web URLs, base64 encoded GIFs (e.g. data:image/gif;base64,...), and local files. This only supports GIF files specifically.

Code Examples

ParamType
optionsMediaSaveOptions

Returns: Promise<PhotoResponse>


createAlbum(...)

createAlbum(options: MediaAlbumCreate) => Promise<void>

Creates an album.

Code Examples

ParamType
optionsMediaAlbumCreate

Interfaces

MediaResponse
PropType
mediasMediaAsset[]
MediaAsset
PropTypeDescription
identifierstringPlatform-specific identifier
datastringData for a photo asset as a base64 encoded string (JPEG only supported)
creationDatestringISO date string for creation date of asset
fullWidthnumberFull width of original asset
fullHeightnumberFull height of original asset
thumbnailWidthnumberWidth of thumbnail preview
thumbnailHeightnumberHeight of thumbnail preview
locationMediaLocationLocation metadata for the asset
MediaLocation
PropTypeDescription
latitudenumberGPS latitude image was taken at
longitudenumberGPS longitude image was taken at
headingnumberHeading of user at time image was taken
altitudenumberAltitude of user at time image was taken
speednumberSpeed of user at time image was taken
MediaFetchOptions
PropTypeDescription
quantitynumberThe number of photos to fetch, sorted by last created date descending
thumbnailWidthnumberThe width of thumbnail to return
thumbnailHeightnumberThe height of thumbnail to return
thumbnailQualitynumberThe quality of thumbnail to return as JPEG (0-100)
types"photos"Which types of assets to return. Only photos supported currently.
albumIdentifierstringWhich album identifier to query in (get identifier with getAlbums())
sort"mediaType" | "mediaSubtypes" | "sourceType" | "pixelWidth" | "pixelHeight" | "creationDate" | "modificationDate" | "isFavorite" | "burstIdentifier" | MediaSort[]Sort order of returned assets by field and ascending/descending
MediaSort
PropType
key"mediaType" | "mediaSubtypes" | "sourceType" | "pixelWidth" | "pixelHeight" | "creationDate" | "modificationDate" | "isFavorite" | "burstIdentifier"
ascendingboolean
MediaAlbumResponse
PropType
albumsMediaAlbum[]
MediaAlbum
PropType
identifierstring
namestring
typeMediaAlbumType
PhotoResponse
PropType
filePathstring
MediaSaveOptions
PropTypeDescription
pathstringWeb URL, base64 encoded URI, or local file path to save.
albumIdentifierstringAlbum identifier from getAlbums(). Since 5.0, identifier is used on both Android and iOS. Identifier is required on Android but not on iOS. On iOS 14+, if the identifier is not specified and no permissions have been requested yet, add-only permissions will be requested instead of full permissions (assuming NSPhotoLibraryAddUsageDescription is in Info.plist).
MediaAlbumCreate
PropType
namestring

Enums

MediaAlbumType
MembersValueDescription
Smart'smart'Album is a "smart" album (such as Favorites or Recently Added)
Shared'shared'Album is a cloud-shared album
User'user'Album is a user-created album

iOS

You'll need to add the following to your app's Info.plist file:

<dict>
  ...
  <key>NSPhotoLibraryUsageDescription</key>
  <string>Describe why you need access to user's photos (getting albums and media)</string>
  <key>NSPhotoLibraryAddUsageDescription</key>
  <string>Describe why you need to add photos to user's photo library</string>
  ...
</dict>

Android

You'll need to add the following to your app's AndroidManifest.xml file:

<manifest>
  ...
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
  <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
  ...
</manifest>

Note the READ_MEDIA permissions -- these are new in Android 13!

Demo

Go the the example/ folder to play with an example app that should show all functionality of this plugin.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Stew
Stew

💻 📖 🚧
Zachary Keeton
Zachary Keeton

💻
Pierre Grimaud
Pierre Grimaud

📖
Talles Alves
Talles Alves

🚧
Zyad Yasser
Zyad Yasser

🚧
Manuel Rodríguez
Manuel Rodríguez

💻 🚧
Michael
Michael

💻
Matheus Davidson
Matheus Davidson

💻 📖
Nisala Kalupahana
Nisala Kalupahana

💻 📖 💡 🚧
Masahiko Sakakibara
Masahiko Sakakibara

🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

Keywords

FAQs

Package last updated on 13 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc