Skip to content

NoMercy-Entertainment/MediaSession

Repository files navigation

MediaSession for Capacitor & Web

NPM Version NPM Downloads License

TypeScript Framework Agnostic GitHub Stars


About

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.


Features

  • 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

🚀 Quick Start

Installation

npm install @nomercy-entertainment/media-session

Basic Usage

import 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,
});

🎛️ Advanced Features

Media Session Integration

  • Native OS media controls (lock screen, notification, hardware buttons)
  • Customizable action handlers for all major media events
  • Automatic artwork resizing for platform compatibility

🔧 Browser & Platform Support

Feature Chrome Firefox Safari Edge
Media Session API
Capacitor N/A N/A N/A

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

# Clone the repository
https://github.com/NoMercy-Entertainment/MediaSession.git
cd MediaSession

# Install dependencies
npm install

# Build and test
npm run build
npm run test

📄 License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.


🏢 About NoMercy Entertainment

NoMercy Entertainment builds open-source media tools that give developers full control over their audio and video.

Our Ecosystem

Links


Built with ❤️ by the NoMercy Engineering Team

About

Media Session API for Capacitor and web

Resources

License

Stars

Watchers

Forks

Packages

No packages published