{"_id":"@darkpo13/capacitor-media-session","name":"@darkpo13/capacitor-media-session","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@darkpo13/capacitor-media-session","version":"0.0.1","description":"Capacitor plugin for media notifications and platform media keys as well as background audio playback","main":"dist/plugin.cjs.js","module":"dist/esm/index.js","types":"dist/esm/index.d.ts","unpkg":"dist/plugin.js","author":{"name":"Vladyslav Polovyk","email":"vladpolovukkenway@gmail.com"},"license":"GPL-3.0-or-later","repository":{"type":"git","url":"git+https://github.com/DarkPo13/capacitor-media-session.git"},"bugs":{"url":"https://github.com/DarkPo13/capacitor-media-session/issues"},"keywords":["capacitor","plugin","native"],"scripts":{"verify":"npm run verify:android && npm run verify:web","verify:android":"cd android && ./gradlew clean build test && cd ..","verify:web":"npm run build","lint":"npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint","fmt":"npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format","eslint":"eslint . --ext ts","prettier":"prettier \"**/*.{css,html,ts,js,java}\"","swiftlint":"node-swiftlint","docgen":"docgen --api MediaSessionPlugin --output-readme README.md --output-json dist/docs.json","build":"npm run clean && npm run docgen && tsc && rollup -c rollup.config.js","clean":"rimraf ./dist","watch":"tsc --watch","prepublishOnly":"npm run build"},"devDependencies":{"@capacitor/android":"^7.0.0","@capacitor/core":"^7.0.0","@capacitor/docgen":"^0.0.18","@ionic/eslint-config":"^0.3.0","@ionic/prettier-config":"^1.0.1","@ionic/swiftlint-config":"^1.1.2","eslint":"^7.11.0","prettier":"~2.3.0","prettier-plugin-java":"~1.0.2","rimraf":"^3.0.2","rollup":"^2.32.0","swiftlint":"^1.0.1","typescript":"~4.4.0"},"peerDependencies":{"@capacitor/core":"^7.0.0"},"prettier":"@ionic/prettier-config","swiftlint":"@ionic/swiftlint-config","eslintConfig":{"extends":"@ionic/eslint-config/recommended"},"capacitor":{"android":{"src":"android"}},"_id":"@darkpo13/capacitor-media-session@0.0.1","gitHead":"4dd31a42e82fc749c9ee4d09cf4e0ea661ee55e3","homepage":"https://github.com/DarkPo13/capacitor-media-session#readme","_nodeVersion":"20.16.0","_npmVersion":"10.8.1","dist":{"integrity":"sha512-lXy3fi0dd/r+aFVOW8wjniZbRuU6IIl/rVfisWXa8lRPEiVx8RQ7w4jUWgVxRu98HlXCN7/R6RqNzYCTVwimkA==","shasum":"fef27a04cfa32fb0d3b5e22235d2c52716211f05","tarball":"https://registry.npmjs.org/@darkpo13/capacitor-media-session/-/capacitor-media-session-0.0.1.tgz","fileCount":31,"unpackedSize":104487,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIB5lOU8fgLs5xKrVOwHTv6QO2VRuTjTDkxHifNH9CIROAiAa4H9mo/5zmJu0C/lVITKgnitFJTvh338LHIBdHRzu8Q=="}]},"_npmUser":{"name":"darkpo13","email":"vladpolovukkenway@gmail.com"},"directories":{},"maintainers":[{"name":"darkpo13","email":"vladpolovukkenway@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/capacitor-media-session_0.0.1_1746362019346_0.6424189754962379"},"_hasShrinkwrap":false}},"time":{"created":"2025-05-04T12:33:39.269Z","0.0.1":"2025-05-04T12:33:39.586Z","modified":"2025-05-04T12:33:39.910Z"},"maintainers":[{"name":"darkpo13","email":"vladpolovukkenway@gmail.com"}],"description":"Capacitor plugin for media notifications and platform media keys as well as background audio playback","homepage":"https://github.com/DarkPo13/capacitor-media-session#readme","keywords":["capacitor","plugin","native"],"repository":{"type":"git","url":"git+https://github.com/DarkPo13/capacitor-media-session.git"},"author":{"name":"Vladyslav Polovyk","email":"vladpolovukkenway@gmail.com"},"bugs":{"url":"https://github.com/DarkPo13/capacitor-media-session/issues"},"license":"GPL-3.0-or-later","readme":"### 🛠️ About this fork\n\nThis project is a modified version of [@jofr/capacitor-media-session](https://github.com/jofr/capacitor-media-session), originally developed by [@jofr](https://github.com/jofr), licensed under the GNU General Public License v3.0.\nThis fork adds support for the latest version of Capacitor (Capacitor 7) and adapts the plugin for more modern app setups.\nThis fork continues to be licensed under **GPL-3.0**. See the [LICENSE](./LICENSE) file for details.\n\n# capacitor-media-session\n\nCapacitor plugin for Media Sessions on Web, Android and iOS. Just like the [Media Session Web API](https://w3c.github.io/mediasession/) this enables\n- customizable media playback notifications (including controls) on iOS, Android and some browsers\n- media control using hardware media keys (e.g. on headsets, remote controls, etc.)\n- setting media metadata that can be used by the platform UI\n\nThis plugin is necessary for Capacitor apps because the Android WebView does not support the Media Session Web API (if you don't need Android support you could just use the Web API directly on Web and iOS). On Web and iOS this plugin is actually just a very thin wrapper around the Web API and uses it directly, only Android needs a native implementation.\n\nAnother problem with audio playback (using web standards, e.g. an `<audio>` element) in Capacitor apps on Android is that it does not work reliably in the background. If your app is in the background Android will force your app to go to sleep even if audio is currently playing in the WebView. This plugin also tries to solve this problem by starting a [foreground service](https://developer.android.com/guide/components/foreground-services) for active Media Sessions enabling background playback.\n\n## Install\n\nCapacitor 7\n\n```bash\nnpm install @darkpo13/capacitor-media-session\nnpx cap sync\n```\n\n## Usage\n\nThe API of this plugin is modeled after the [already widely supported](https://developer.mozilla.org/en-US/docs/Web/API/Media_Session_API#browser_compatibility) Media Session Web API. That way most available documentation for this web standard should be easily adaptable to this Capacitor plugin and it should be easy to use if you are already familiar with it. If your are not yet familiar with the concepts you can [read more about that on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Media_Session_API) or [on web.dev](https://web.dev/media-session/).\n\n__There is one notable difference compared to the Web API__: You have to explicitly set the playback state to `\"playing\"` (using [`setPlaybackState()`](#setplaybackstate)) for the notification to start showing. You also have to explicitly set action handlers for play/pause (using [`setActionHandler()`](#setactionhandler)) for the controls in the notification to show up and work. For simple cases on the Web platform (e.g. playing audio using an `<audio>` element) the browser detects playback and wires simple actions like play/pause automatically up. Using this plugin you have to wire up the `<audio>` element manually because the plugin cannot detect audio playback in the WebView on Android automatically. There is an example app included in the repository [that shows how to do that](https://github.com/DarkPo13/capacitor-media-session/blob/main/example/src/js/media-session.js).\n\n## API\n\n<docgen-index>\n\n* [`setMetadata(...)`](#setmetadata)\n* [`setPlaybackState(...)`](#setplaybackstate)\n* [`setActionHandler(...)`](#setactionhandler)\n* [`setPositionState(...)`](#setpositionstate)\n* [Interfaces](#interfaces)\n* [Type Aliases](#type-aliases)\n\n</docgen-index>\n\n<docgen-api>\n<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->\n\n### setMetadata(...)\n\n```typescript\nsetMetadata(options: MetadataOptions) => Promise<void>\n```\n\nSets metadata of the currently playing media. Analogue to setting the\r\n[metadata property of the MediaSession\r\ninterface](https://developer.mozilla.org/en-US/docs/Web/API/MediaSession/metadata)\r\nwhen using the Media Session API directly.\n\n| Param         | Type                                                        |\n| ------------- | ----------------------------------------------------------- |\n| **`options`** | <code><a href=\"#metadataoptions\">MetadataOptions</a></code> |\n\n--------------------\n\n\n### setPlaybackState(...)\n\n```typescript\nsetPlaybackState(options: PlaybackStateOptions) => Promise<void>\n```\n\nIndicate whether media is playing or not. Analogue to setting the\r\n[playbackState property of the MediaSession\r\ninterface](https://developer.mozilla.org/en-US/docs/Web/API/MediaSession/playbackState)\r\nwhen using the Media Session API directly.\n\n| Param         | Type                                                                  |\n| ------------- | --------------------------------------------------------------------- |\n| **`options`** | <code><a href=\"#playbackstateoptions\">PlaybackStateOptions</a></code> |\n\n--------------------\n\n\n### setActionHandler(...)\n\n```typescript\nsetActionHandler(options: ActionHandlerOptions, handler: ActionHandler | null) => Promise<void>\n```\n\nSets handler for media session actions (e.g. initiated via onscreen media\r\ncontrols or physical buttons). Analogue to calling [setActionHandler() of\r\nthe MediaSession\r\ninterface](https://developer.mozilla.org/en-US/docs/Web/API/MediaSession/setActionHandler)\r\nwhen using the Media Session API directly.\n\n| Param         | Type                                                                  |\n| ------------- | --------------------------------------------------------------------- |\n| **`options`** | <code><a href=\"#actionhandleroptions\">ActionHandlerOptions</a></code> |\n| **`handler`** | <code><a href=\"#actionhandler\">ActionHandler</a> \\| null</code>       |\n\n--------------------\n\n\n### setPositionState(...)\n\n```typescript\nsetPositionState(options: PositionStateOptions) => Promise<void>\n```\n\nUpdate current media playback position, duration and speed. Analogue to\r\ncalling [setPositionState() of the MediaSession\r\ninterface](https://developer.mozilla.org/en-US/docs/Web/API/MediaSession/setPositionState)\r\nwhen using the Media Session API directly.\n\n| Param         | Type                                                                  |\n| ------------- | --------------------------------------------------------------------- |\n| **`options`** | <code><a href=\"#positionstateoptions\">PositionStateOptions</a></code> |\n\n--------------------\n\n\n### Interfaces\n\n\n#### MetadataOptions\n\n| Prop          | Type                |\n| ------------- | ------------------- |\n| **`album`**   | <code>string</code> |\n| **`artist`**  | <code>string</code> |\n| **`artwork`** | <code>any[]</code>  |\n| **`title`**   | <code>string</code> |\n\n\n#### PlaybackStateOptions\n\n| Prop                | Type                                   |\n| ------------------- | -------------------------------------- |\n| **`playbackState`** | <code>MediaSessionPlaybackState</code> |\n\n\n#### ActionHandlerOptions\n\n| Prop         | Type                            |\n| ------------ | ------------------------------- |\n| **`action`** | <code>MediaSessionAction</code> |\n\n\n#### ActionDetails\n\n| Prop           | Type                            |\n| -------------- | ------------------------------- |\n| **`action`**   | <code>MediaSessionAction</code> |\n| **`seekTime`** | <code>number \\| null</code>     |\n\n\n#### PositionStateOptions\n\n| Prop               | Type                |\n| ------------------ | ------------------- |\n| **`duration`**     | <code>number</code> |\n| **`playbackRate`** | <code>number</code> |\n| **`position`**     | <code>number</code> |\n\n\n### Type Aliases\n\n\n#### ActionHandler\n\n<code>(details: <a href=\"#actiondetails\">ActionDetails</a>): void</code>\n\n</docgen-api>\n","readmeFilename":"README.md","_rev":"1-b8c592548a5dd15be4a04650d6214e41"}