Describe the bug
When there are three or more tracks everything seems to be fine but I can't play less than 3 tracks.
To Reproduce
await TrackPlayer.add({
id: 'test',
title: 'sample title',
url: 'https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3',
});
await TrackPlayer.play();
Environment (please complete the following information):
System:
OS: Linux 5.3 Ubuntu 18.04.4 LTS (Bionic Beaver)
CPU: (4) x64 Intel(R) Core(TM) i3-4160 CPU @ 3.60GHz
Memory: 130.73 MB / 7.67 GB
Shell: 4.4.20 - /bin/bash
Binaries:
Node: 12.16.2 - /tmp/yarn--1588188922614-0.9850763653958186/node
Yarn: 1.22.4 - /tmp/yarn--1588188922614-0.9850763653958186/yarn
npm: 6.14.4 - /usr/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Languages:
Java: 1.8.0_252 - /usr/bin/javac
Python: 2.7.17 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.11.0 => 16.11.0
react-native: 0.62.2 => 0.62.2
npmGlobalPackages:
*react-native*: Not Found
What react-native-track-player version are you using?
Are you testing on a real device or in the simulator? Which OS version are you running?
What do you mean by "can't play"?
Can you listen to the first track and it crashes between the beginning and the third track? Or does it crash at the beginning of the play? Do you have an error message?
@ainar
{"code": "playback-source", "message": "Unexpected NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.toString()' on a null object reference", "type": "playback-error"}
It works for me.
Unexpected NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.toString()' on a null object reference
I usually get this error message when I try to pass something else than a string to the id property of my track object.
EDIT: I can pass an int for id, and even undefined works as an id...
I'm passing string as id. Did you check with single track?
Yes, I did.
Are you doing something else than playing, as skipping to track or removing from queue?
No. Not sure what's wrong. I'm using it as shown in the example code in post.
If I provide only one song, console.log(await TrackPlayer.getQueue()); returns empty array []
Are you saying that this dos NOT work:
await TrackPlayer.add({
id: 'test',
title: 'sample title',
url: 'https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3',
});
await TrackPlayer.play();
But this DOES work?
await TrackPlayer.add([{
id: 'test1',
title: 'sample title 1',
url: 'https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3',
},
{
id: 'test2',
title: 'sample title 2',
url: 'https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3',
},
{
id: 'test3',
title: 'sample title 3',
url: 'https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3',
}]);
await TrackPlayer.play();
@curiousdustin yes exactly!
js
await TrackPlayer.add({
id: 'test',
title: 'sample title',
url: 'https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3',
});
await TrackPlayer.play();
console.log(await TrackPlayer.getCurrentTrack()); // null
What about the queue and the current track when you add 3 tracks?
const tracks = [
{
id: 'Blue Jeans.mp3',
title: 'Blue Jeans.mp3',
url: '/storage/emulated/0/Android/data/com.sayem.downloader/files/Born To Die/Blue Jeans.mp3',
},
{
id: 'Born To Die.mp3',
title: 'Born To Die.mp3',
url: '/storage/emulated/0/Android/data/com.sayem.downloader/files/Born To Die/Born To Die.mp3',
},
{
id: 'Off To The Races.mp3',
title: 'Off To The Races.mp3',
url: '/storage/emulated/0/Android/data/com.sayem.downloader/files/Born To Die/Off To The Races.mp3',
},
];
await TrackPlayer.add(tracks);
await TrackPlayer.play();
const currentTrack = await TrackPlayer.getCurrentTrack(); // Born To Die.mp3
// should be: Blue Jeans.mp3
const queue = await TrackPlayer.getQueue();
/*
[
{
id: 'Blue Jeans.mp3',
title: 'Blue Jeans.mp3',
url: '/storage/emulated/0/Android/data/com.sayem.downloader/files/Born To Die/Blue Jeans.mp3',
},
{
id: 'Born To Die.mp3',
title: 'Born To Die.mp3',
url: '/storage/emulated/0/Android/data/com.sayem.downloader/files/Born To Die/Born To Die.mp3',
},
{
id: 'Off To The Races.mp3',
title: 'Off To The Races.mp3',
url: '/storage/emulated/0/Android/data/com.sayem.downloader/files/Born To Die/Off To The Races.mp3',
},
];
*/
{"code": "playback-source", "message": "Unexpected NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.toString()' on a null object reference", "type": "playback-error"}
The error says that the track URL is invalid, can you show what are you using as the URL?
{"code": "playback-source", "message": "Unexpected NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.toString()' on a null object reference", "type": "playback-error"}The error says that the track URL is invalid, can you show what are you using as the URL?
/storage/emulated/0/Android/data/com.sayem.downloader/files/Yikes/Yikes.mp3
^This works however when adding 3 or more tracks.
@sayem314, looks like you're using an emulator. Does this issue occur on real devices? If so, does it still occur in a release build, instead of debug mode?
@curiousdustin yes the issue occurs on physical devices even on release builds.
This will probably not help, but can you try to prefix the URLs with file:///?
e.g. file:///storage/emulated/0/Android/data/com.sayem.downloader/files/Yikes/Yikes.mp3
No changes with file:// suffix in front. It behaves the same.
How are you determining the path? Are you using react-native-fs?
Yes, I'm using 'react-native-fs' and I confirm path is correct and file exists,
Take a look at this video. While recording, found another issue when seeking.
https://streamable.com/y2lplo
Figured something strange. When the current directory the music files are on if there is more than one track on that directory the single track works 90% sometimes. But if playing a single track on a folder with only one track it doesn't work. When it doesn't work this warning is thrown.
Possible Unhandled Promise Rejection (id: 3):
Error: Given track ID was not found in queue
Can you share your code so we can take a further look?
Most helpful comment
The error says that the track URL is invalid, can you show what are you using as the URL?