react-native-haptic-music-player-new
v1.0.6
Published
A fully fledged audio module created for music apps
Maintainers
Readme
react-native-haptic-music-player
A fully-fledged audio module created for music apps. Provides audio playback, external media controls, background mode and more!
Quick Start (Recommended)
For React Native 0.70+ and New Architecture compatibility, use the built-in simple player:
# No installation needed - uses built-in React Native componentsSimple Haptic Player Usage
import React from 'react';
import { View } from 'react-native';
import PureRNHapticPlayer from './PureRNHapticPlayer'; // Copy from package
export default function App() {
return (
<View style={{ flex: 1 }}>
<PureRNHapticPlayer />
</View>
);
}Android Permission
Add to android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.VIBRATE" />Customize Tracks
// In PureRNHapticPlayer.js, modify:
const tracks = [
{ title: 'Your Song 1', artist: 'Your Artist 1' },
{ title: 'Your Song 2', artist: 'Your Artist 2' },
];Advanced Installation (Legacy)
For older React Native versions or advanced features:
npm install react-native-haptic-music-player-newiOS Setup
cd ios && pod installAndroid Setup
Auto-linking handles setup for RN 0.60+
Clean Build (If needed)
npx react-native start --reset-cache
cd ios && xcodebuild clean && pod install
cd android && ./gradlew clean
npx react-native run-androidUsage Examples
Basic Setup (Advanced)
import HapticPlayer from 'react-native-haptic-music-player-new';
const setupPlayer = async () => {
try {
await HapticPlayer.setupPlayer();
await HapticPlayer.add({
id: 'track1',
url: 'https://example.com/song.mp3',
title: 'Song Title',
artist: 'Artist Name'
});
await HapticPlayer.play();
} catch (error) {
console.error('Setup failed:', error);
}
};React Hooks (Advanced)
import { useProgress, usePlaybackState } from 'react-native-haptic-music-player-new';
function Player() {
const progress = useProgress();
const playbackState = usePlaybackState();
return (
<View>
<Text>{progress.position} / {progress.duration}</Text>
<Text>State: {playbackState.state}</Text>
</View>
);
}Features Comparison
| Feature | Simple Player | Advanced Package | |---------|---------------|------------------| | Haptic Feedback | ✅ | ✅ | | Play/Pause | ✅ | ✅ | | Track Navigation | ✅ | ✅ | | Progress Bar | ✅ | ✅ | | Background Play | ❌ | ✅ | | Media Controls | ❌ | ✅ | | Streaming | ❌ | ✅ | | Dependencies | None | Audio libraries | | RN 0.83+ Support | ✅ | ⚠️ |
Troubleshooting
"cannot read property HapticPlayerModule"
Solution: Use the Simple Player instead - it has no native dependencies.
Build Errors with New Architecture
Solution: Copy PureRNHapticPlayer.js and use built-in components.
Compatibility Issues
Solution: The Simple Player works with all React Native versions.
Recommendation
For new projects: Use PureRNHapticPlayer.js - it's dependency-free and works with all React Native versions including 0.83+ and New Architecture.
For existing projects: Migrate to the Simple Player to avoid compatibility issues.
Why Simple Player?
- ✅ Zero Dependencies - No native modules to break
- ✅ Always Compatible - Works with any React Native version
- ✅ Haptic Feedback - Built-in vibration API
- ✅ Modern UI - Spotify-inspired design
- ✅ Easy Setup - Just copy and use
Maintainer
This package is maintained and developed by me as a personal project.
