Skip to content
This repository was archived by the owner on Oct 6, 2022. It is now read-only.

PlayPause button on Lightning EarPods doesn't work #396

Closed
2 of 4 tasks
dwgdev07 opened this issue Nov 14, 2021 · 1 comment
Closed
2 of 4 tasks

PlayPause button on Lightning EarPods doesn't work #396

dwgdev07 opened this issue Nov 14, 2021 · 1 comment

Comments

@dwgdev07
Copy link

dwgdev07 commented Nov 14, 2021

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.

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

  1. Platform ?

    • iOS
    • Android
  1. Device
  • Simulator
  • Real device
@dwgdev07
Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant