Possible Bug:
I want to play tracks from my local file system using react-native-track-player, but getting no audible audio play on the Android device that I am emulating and testing on. Plus, no error feedback on Metro or React Native Debugger. If it is an overlook on my side, can you give some pointers about how to solve?
What I Tried:
I have tried several audio formats and local directories, but still not getting past “ready” PlaybackState
in TrackPlayer.addEventListener
- Formats: AAC, MP3
- Directories:
file:///data/user/0/audiopath…
file:///storage/emulated/0/Android/data/audiopath…
file:///storage/emulated/0//Download/audiopath…
I read through all RNFS, RNFetchBlob, RNFB related issues in this lib, but nothing helped.
Code To Reproduce:
const Player = ({list}) => {
const [isPlayerReady, setIsPlayerReady] = useState(false);
useEffect(() => {
async function setup() {
let isSetup = await SetupTrackPlayer();
const queue = await TrackPlayer.getQueue();
if (isSetup && queue.length <= 0) {
await addTracksToQueue(list);
}
setIsPlayerReady(isSetup);
}
setup();
}, [list]);
const addTracksToQueue = async list => {
list.docs.map(doc => ({
id: docID,
url: file:///data/user/0/audiopath..., //tried other dir as stated above
artwork: file:///data/user/0/imagepath..., //also not loading
title: doc.title,
artist: doc.author,
})),
await TrackPlayer.add(tracks);
await TrackPlayer.setRepeatMode(RepeatMode.Queue);
};
//jsx
};
export async function SetupTrackPlayer() {
let isSetup = false;
try {
await TrackPlayer.getActiveTrackIndex();
isSetup = true;
} catch {
await TrackPlayer.setupPlayer();
await TrackPlayer.updateOptions({
android: {
alwaysPauseOnInterruption: true,
appKilledPlaybackBehavior: AppKilledPlaybackBehavior.ContinuePlayback,
},
capabilities: [
Capability.Play,
Capability.Pause,
Capability.SkipToNext,
Capability.SkipToPrevious,
],
compactCapabilities: [Capability.Play, Capability.Pause],
});
isSetup = true;
} finally {
return isSetup;
}
}
Current Status:
- I could confirm that the audio files do exist in the directories listed above, via Android Studio or File Explorer.
TrackPlayer.getActiveTrack()
does pick the 1st item in the array passed toTrackPlayer.add()
, but still no audible play.- Having RNN and RNGH installed, I wrapped all the View registries with
Navigation.registerComponent()
andgestureHandlerRootHOC()
. Not sure if there are lib conflicts, but for RNTP, I only usedTrackPlayer.registerPlaybackService(() => PlaybackService)
Env Info:
OS:Windows 11 10.0.22631
Android:12
Nodeversion:20.11.1
openjdk:11.0.22
react-native:0.72.15
react-native-track-player:4.1.1
audiopathreact-native-navigation:7.35.2
audiopathreact-native-reanimated:3.3.0
audiopathreact-native-gesture-handler:2.11.0
react-native-fs:2.20.0
hermesEnabled:true
newArchEnabled:false
androidmanifest.xml permissions:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>