Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to implement react-native-track-player ? #110

Closed
GaylordP opened this issue Nov 9, 2021 · 3 comments
Closed

How to implement react-native-track-player ? #110

GaylordP opened this issue Nov 9, 2021 · 3 comments
Labels
question Question about any part of the module

Comments

@GaylordP
Copy link

GaylordP commented Nov 9, 2021

Hello :)

Thanks you very much for your library.

You mention in your documentation react-native-track-player in order to be able to work correctly on iOS.

But I can't find an example of an implementation. I read this issue correctly but I think it is a bit incomplete.

I searched the internet a lot (especially in all github looking for the react-native-track-player package) without finding an answer.

If I use your example, how would you implement react-native-track-player ?

const taskRandom = async (taskData) => {
  if (Platform.OS === 'ios') {
      console.warn(
          'This task will not keep your app alive in the background by itself, use other library like react-native-track-player that use audio,',
          'geolocalization, etc. to keep your app alive in the background while you excute the JS from this library.'
      );
  }
  await new Promise(async (resolve) => {
      // For loop with a delay
      const { delay } = taskData;
      console.log(BackgroundJob.isRunning(), delay)
      for (let i = 0; BackgroundJob.isRunning(); i++) {
          console.log('Runned -> ', i);
          await BackgroundJob.updateNotification({ taskDesc: 'Runned -> ' + i });
          await sleep(delay);
      }
  });
};

Thanks you very much and sorry for my bad english, I'm french :)

@Rapsssito
Copy link
Owner

@GaylordP, expanding the example would be:

const taskRandom = async (taskData) => {
  if (Platform.OS === 'ios') {
      console.warn(
          'This task will not keep your app alive in the background by itself, use other library like react-native-track-player that use audio,',
          'geolocalization, etc. to keep your app alive in the background while you excute the JS from this library.'
      );
  }
  
await new Promise((resolve) => {
        // Playing listeners
        const listenerChange = TrackPlayer.addEventListener('playback-state', (newState) => {
            // Do stuff
            if (newState.state === TrackPlayer.STATE_PLAYING) {
                // What to do when the play button is pressed
            } else if (newState.state === TrackPlayer.STATE_PAUSED) {
                // What to do when the pause button is pressed
            }
        });
    });
};

@Rapsssito Rapsssito added the question Question about any part of the module label Nov 10, 2021
@GaylordP
Copy link
Author

Thanks for your reply :)

I'm sorry (maybe I don't understand because my English is bad) but this example is incomplete right ?

I that adding these few lines in the original code of this example does make it work, is something missing ?

Thanks you in adavance

@Rapsssito
Copy link
Owner

@GaylordP, there is a lot more configuration needed for react-native-track-player to work. However, this is outside the scope of this library, you may want to ask this in their repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about any part of the module
Projects
None yet
Development

No branches or pull requests

2 participants