The `spotify-audio-element` package provides a custom web component, `<spotify-audio>`, designed to embed and control Spotify audio playback directly within HTML. It aims to replicate the standard HTML `<audio>` element's API, offering a familiar interface for developers. Currently at version `1.0.4`, this package is part of the `muxinc/media-elements` monorepo, which sees active development across its various media component offerings. While `spotify-audio-element` itself might not have frequent individual version bumps, the monorepo has consistent updates across its related packages. Its primary differentiators include a compliant `HTMLMediaElement` API surface, making it intuitive for those familiar with native audio elements, and seamless integration capabilities with `Media Chrome` for advanced UI customization.
npm install spotify-audio-elementVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import and instantiate the `spotify-audio` custom element, set its source, append it to the DOM, and programmatically control playback. It uses an environment variable for a Spotify Track URI to ensure a runnable example.
Review Spotify's Web Playback SDK documentation and Developer Policy regarding authentication, domain whitelisting, Premium account requirements, and commercial usage. Ensure your application handles user login and token management appropriately for full functionality.
Always refer to the official NPM page or project repository for the latest recommended installation instructions and version numbers. For CDN usage, update the version in the URL to the latest stable release (e.g., `spotify-audio-element@1`).
For wider browser compatibility, consider adding web component polyfills to your project, especially if targeting older browsers or environments that do not fully support Custom Elements v1. `npm install @webcomponents/custom-elements` and import it early in your application's entry point.
Stay informed about Spotify's API and SDK policy changes. Always test your implementation thoroughly with different Spotify account types and ensure your application's API permissions are up-to-date and compliant with Spotify's developer policies.
Ensure that `import 'spotify-audio-element';` or the CDN script tag is included only once in your application. For example, import it only in your main JavaScript entry file, not in multiple components or HTML partials.
Verify that the user is logged into a Spotify Premium account in their browser. If integrating with a custom application, ensure your application's `redirect_uri` and origin are correctly configured and whitelisted in your Spotify Developer Dashboard. Handle cases where the user does not have a Premium account or is not logged in.
Ensure the `src` attribute is set to a specific Spotify Track URI (e.g., `spotify:track:YOUR_TRACK_ID`) for direct audio playback. If you intend to play an album or artist's popular tracks, you would first need to use the Spotify Web API to retrieve track URIs. The README example's artist URI might not produce playable audio directly.
No dependency data recorded yet.