React-native-track-player: No task registered for key TrackPlayer

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

hi all , first of all thank you for this package , its very useful
today i init a new project but when i setup it gets me an error below:

TrackPlayerModule.setupPlayer got 2 arguments, expected 3
invoke
    JavaMethodWrapper.java:344

so i change my code to this for setup: TrackPlayer.setupPlayer({});
_it works!_

after that when i call add every thinks is ok but if i TrackPlayer.play() i have error:

No task registered for key TrackPlayer
startHeadlessTask
    C:\Users\Mohammad\Desktop\Player\node_modules\react-native\Libraries\ReactNative\AppRegistry.js:222:12

all of my app codes:

import React, { Component } from 'react';
import {
  StyleSheet,
  View,
  Button
} from 'react-native';
import TrackPlayer from 'react-native-track-player';

export default class App extends Component {

  async componentDidMount() {
    await TrackPlayer.setupPlayer({});
    await TrackPlayer.add({
      id: 'track',
      url: 'http://tegos.kz/new/mp3_full/Luis_Fonsi_feat._Daddy_Yankee_-_Despacito.mp3', // just for test!
      title: 'Despacito',
      artist: 'Luis Fonsi Feat. Daddy Yankee',
      artwork: 'https://images-eu.ssl-images-amazon.com/images/I/61JH2ggghmL._AC_US160_.jpg'
    })
    TrackPlayer.play();
  }

  render() {
    return (
      <View style={styles.container}>

        <Button onPress={() => this.play()} title="play" color="#841584" accessibilityLabel="Learn more about this purple button" />
        <Button onPress={() => TrackPlayer.stop()} title="stop" color="#841584" accessibilityLabel="Learn more about this purple button" />
      </View>
    );
  }

  play() {
    TrackPlayer.add({
      id: 'track',
      url: 'http://tegos.kz/new/mp3_full/Luis_Fonsi_feat._Daddy_Yankee_-_Despacito.mp3',
      title: 'Despacito',
      artist: 'Luis Fonsi Feat. Daddy Yankee',
      artwork: 'https://images-eu.ssl-images-amazon.com/images/I/61JH2ggghmL._AC_US160_.jpg'
    }).then(() => {
      TrackPlayer.play();
    });
  }

}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  }
});

how i can fix this?
dependencies:

  • "react": "16.0.0-beta.5",
  • "react-native": "0.49.3",
  • "react-native-cli": "^2.0.1",
  • "react-native-fetch-blob": "^0.10.8",
  • "react-native-track-player": "^0.1.0"
  • -
Android Duplicate Question

Most helpful comment

I am getting the same issue with 1.0.0.

I added this to index.js file

import TrackPlayer from 'react-native-track-player';

TrackPlayer.setupPlayer({}).then(async () => {
})

All 3 comments

If you're using the dev branch, register an event handler.
If you're using the master branch (or npm), register the headless task.

See more about it in #54

now it works , thank you @Guichaguri

I am getting the same issue with 1.0.0.

I added this to index.js file

import TrackPlayer from 'react-native-track-player';

TrackPlayer.setupPlayer({}).then(async () => {
})
Was this page helpful?
0 / 5 - 0 ratings

Related issues

mckmarc picture mckmarc  路  4Comments

JakeMotta picture JakeMotta  路  3Comments

amed picture amed  路  4Comments

elioscordo picture elioscordo  路  3Comments

mnlbox picture mnlbox  路  4Comments