Hi, i have the problem, that the playPause button on EarPods with lightning connector doesn't work - bluetooth earphones work as expected.
Here is the hook I use to init the music controls.
import MusicControl, {Command} from 'react-native-music-control';
import {usePlayerStore} from './usePlayerStore';
import {Platform} from 'react-native';
export const useControlCenter = () => {
const playerStore = usePlayerStore();
const init = () => {
MusicControl.enableBackgroundMode(true);
if (Platform.OS === 'ios') {
MusicControl.handleAudioInterruptions(true);
}
// Basic Controls
MusicControl.enableControl('play', true);
MusicControl.enableControl('pause', true);
MusicControl.enableControl('stop', false);
MusicControl.on(Command.play, () => {
playerStore.updatePaused(false);
});
// on iOS this event will also be triggered by audio router change events
// happening when headphones are unplugged or a bluetooth audio peripheral disconnects from the device
MusicControl.on(Command.pause, () => {
playerStore.updatePaused(true);
});
MusicControl.on(Command.stop, () => {
playerStore.updatePaused(true);
});
MusicControl.on(Command.togglePlayPause, () => {
playerStore.updatePaused(!playerStore.paused);
});
};
const updatePosition = (position: number) => {
MusicControl.updatePlayback({
elapsedTime: position,
});
};
return {
init: init,
updatePosition: updatePosition,
};
};
Found it. Had to enable togglePlayPause with MusicControl.enableControl('togglePlayPause', true);.
Maybe it would be helpful to include this line in the README.md examples.
Description
Hi, i have the problem, that the playPause button on EarPods with lightning connector doesn't work - bluetooth earphones work as expected. Here is the hook I use to init the music controls.
Platform ?