React-native-track-player: [Android]聽Error - No task registered for key TrackPlayer

Created on 10 Oct 2017  路  7Comments  路  Source: react-native-kit/react-native-track-player

I've started testing this library on Android and so far it works great.

I'm just having an issue that maybe is related to missing configuration on my part.
But I've reading the documentation and followed all the steps indicated. Maybe you guys could point me in the right direction.

This error appears every time an action (play, pause, add tracks, ...) on the player is run.
Do you know what could be the reason?

ExceptionsManager.js:65 No task registered for key TrackPlayer

error

Thanks in advance,
Jon.

Android Question

Most helpful comment

You have to register the event handler right after registering the component with registerComponent
It would look like this:

AppRegistry.registerComponent('appname', () => App);
TrackPlayer.registerEventHandler(() => {...});

Also, make sure you're using the dev branch, we didn't pushed the new event handler to master/npm yet

All 7 comments

Do you have an event handler registered? See the part on receiving events :)

https://github.com/react-native-kit/react-native-track-player/wiki/API

Thanks for the quick response @dcvz
Yes I have it. But not sure if is in the correct place & the correct way.

This is what I got:

AppRegistry.registerComponent('appname', () => App);

TrackPlayer.setupPlayer({}).then(() => {
  TrackPlayer.updateOptions({
    capabilities: [
      TrackPlayer.CAPABILITY_PLAY,
      TrackPlayer.CAPABILITY_PAUSE
    ],
  });

  TrackPlayer.registerEventHandler(() => {
    return async (data) => {
      if (data.type == 'playback-state') {
        // Update the UI with the new state
      } else if (data.type == 'remote-play') {
        // The play button was pressed, we can forward this command to the player using
        TrackPlayer.play();
      } else if (data.type == 'remote-stop') {
        // The stop button was pressed, we can stop the player
        TrackPlayer.stop();
      } else if (data.type == 'remote-pause') {
        // The play button was pressed, we can forward this command to the player using
        TrackPlayer.pause();
      }
    };
  });
});

You have to register the event handler right after registering the component with registerComponent
It would look like this:

AppRegistry.registerComponent('appname', () => App);
TrackPlayer.registerEventHandler(() => {...});

Also, make sure you're using the dev branch, we didn't pushed the new event handler to master/npm yet

Hi @Guichaguri,
Yes I'm registering the event in the line below of AppRegistry.registerComponent.
But you're right, I was using the master/npm branch not the dev one. That must be the reason why the event handler doesn't work.

But the issue is still there if I don't declare the handler.
Is there a different way to declare the event handler for the current master version?

Thanks again for the response and the support.
I'm really enjoying using this library. Great work guys!

There is, you can use registerHeadlessTask on Android, like so:

AppRegistry.registerHeadlessTask('TrackPlayer', () => require('./player-handler.js'));

On iOS and Windows, you should use the EventEmitter from TrackPlayer.eventEmitter.addListener('event-name', callback);

That was it, now it works! Thanks a lot @Guichaguri
I will close the issue then.

Hey guys, I need some help with this issue. I am using with the track player with redux so its not really practical to register the event handler before I have setup the store. But I think more importantly I don't really understand what is causing the error. Even if I don't register the event handler at all I still get this on any reload. Perhaps someone could quickly explain whats going on here. Thanks!

Was this page helpful?
0 / 5 - 0 ratings