UNPKG

expo-media-control

Version:

Comprehensive media control module for Expo and React Native with background audio support, lock screen controls, and system integration

147 lines (112 loc) 4.65 kB
# React Native Music Control Module Requirements ## Overview This document outlines the requirements for creating a modern implementation of this module using Kotlin for Android and Swift for iOS. The module will be built as an Expo module package and will support React Native's new architecture. ## Core Requirements ### 1. Functionality - Remote media controls integration for both Android and iOS - Background audio playback support - Notification with media controls - Lock screen media controls - Remote control events handling (play/pause/stop/next/previous) - Album artwork display in notifications and lock screen - Support for rating controls - Skip forward/backward functionality - Audio interruption handling - Volume control integration ### 2. Technology Stack - **Android**: Kotlin with MediaSessionCompat and Notification APIs - **iOS**: Swift with MediaPlayer framework - **JavaScript/TypeScript**: Modern TypeScript with proper type definitions - **React Native**: Support for the new architecture and backwards compatibility ### 3. Module Structure #### Android (Kotlin) - Replace Java implementations with Kotlin equivalents: - MediaSessionCompat management - Notification creation and management - Event handling and broadcasting to JavaScript - Audio focus management - Volume control #### iOS (Swift) - Replace Objective-C implementation with Swift: - MPNowPlayingInfoCenter integration - MPRemoteCommandCenter for remote controls - Event handling and broadcasting to JavaScript #### JavaScript/TypeScript - Clean TypeScript API with comprehensive type definitions - Expo module configuration ## Detailed Requirements ### Android Implementation 1. **Media Session Management** - Create and manage MediaSessionCompat - Handle media button events - Update playback state and metadata 2. **Notification** - Create media style notifications - Support customization (icons, colors) - Handle notification actions - Support notification channels for Android 8+ 3. **Audio Focus** - Request and release audio focus - React to audio focus changes (e.g., pause on audio focus loss) 4. **Event Handling** - Bridge native events to JavaScript - Support all control events (play, pause, stop, next, previous, etc.) ### iOS Implementation 1. **Now Playing Info** - Update MPNowPlayingInfoCenter with track information - Support artwork loading and caching - Handle playback state and position updates 2. **Remote Commands** - Register handlers for MPRemoteCommandCenter - Support all relevant commands (play, pause, next, previous, seek, etc.) - Handle command events and bridge to JavaScript 3. **Background Mode** - Configure and manage audio background mode - Handle interruptions and route changes ### JavaScript API 1. **Main Interface** - Maintain compatibility with existing API - Enhance with TypeScript type definitions - Support promise-based async operations where appropriate 2. **Events** - Implement event system for receiving control commands - Support event subscription and cleanup ### Expo Integration 1. **Module Structure** - Follow Expo module structure guidelines - Support auto-linking and configuration 2. **Configuration** - Support configuration through app.json/app.config.js - Handle permissions automatically 3. **Documentation** - Provide comprehensive documentation for Expo usage - Include examples for common use cases ## Non-Functional Requirements 1. **Performance** - Minimize battery impact during background playback - Efficient handling of artwork loading and caching 2. **Compatibility** - Support Android 5.0+ (API level 21+) - Support iOS 11.0+ - Support React Native 0.64+ 3. **Testing** - Unit tests for core functionality - Integration tests with sample audio playback - Cross-device testing 4. **Code Quality** - Follow Kotlin and Swift best practices - Clear documentation and comments - Consistent error handling ## Migration Considerations 1. **API Compatibility** - Maintain the same JavaScript API interface where possible - Document any breaking changes 2. **Upgrade Path** - Provide migration guide for users of the older module - Support gradual adoption of new features ## Implementation Notes - Use Kotlin coroutines for asynchronous operations on Android - Use Swift concurrency features for iOS where appropriate - Follow React Native's new architecture guidelines for native modules - Implement proper cleanup to prevent memory leaks - Consider backward compatibility with older React Native versions