A cross-platform Media Session API wrapper for Capacitor and web. Provides unified media controls, metadata, and playback state management for audio/video apps.
Empowers media experiences in NoMercyTV and other NoMercy projects.
- Unified API: Works seamlessly on web and Capacitor platforms
- Media Metadata: Set title, artist, album, and artwork
- Playback State: Control and reflect play, pause, stop, etc.
- Position State: Sync duration, position, and playback rate
- Action Handlers: Respond to play, pause, seek, next/previous, and more
- TypeScript Support: Full typings for safe integration
- Framework Agnostic: Use with any frontend framework
npm install @nomercy-entertainment/media-sessionimport MediaSession from '@nomercy-entertainment/media-session';
const mediaSession = new MediaSession();
// Set metadata
mediaSession.setMetadata({
title: 'Song Title',
artist: 'Artist Name',
album: 'Album Name',
artwork: 'https://example.com/artwork.jpg'
});
// Set playback state
mediaSession.setPlaybackState('playing');
const audioElement = document.createElement('audio');
// Set position state
mediaSession.setPositionState({
duration: audioElement.duration,
playbackRate: audioElement.playbackRate,
position: audioElement.currentTime
});
// Set action handlers
mediaSession.setActionHandler({
play: () => audioElement.play(),
pause: () => audioElement.pause(),
stop: () => {
audioElement.pause();
audioElement.currentTime = 0;
audioElement.removeAttribute('src');
},
previous: () => {},
next: () => {},
seek: (time) => audioElement.currentTime = time,
getPosition: () => audioElement.currentTime,
});- Native OS media controls (lock screen, notification, hardware buttons)
- Customizable action handlers for all major media events
- Automatic artwork resizing for platform compatibility
| Feature | Chrome | Firefox | Safari | Edge |
|---|---|---|---|---|
| Media Session API | ✅ | ✅ | ✅ | ✅ |
| Capacitor | ✅ | N/A | N/A | N/A |
We welcome contributions! Please see our Contributing Guide for details.
# Clone the repository
https://github.com/NoMercy-Entertainment/MediaSession.git
cd MediaSession
# Install dependencies
npm install
# Build and test
npm run build
npm run testThis project is licensed under the Apache 2.0 License - see the LICENSE file for details.
NoMercy Entertainment builds open-source media tools that give developers full control over their audio and video.
- 🌐 Website: nomercy.tv
- 📧 Contact: [email protected]
- 💼 GitHub: @NoMercy-Entertainment
Built with ❤️ by the NoMercy Engineering Team