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:
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 () => {
})
Most helpful comment
I am getting the same issue with 1.0.0.
I added this to index.js file