I am growing a React Native app utilizing react-native-track-player for audio playback. The app works completely wonderful on Android, however I am dealing with points on iOS. Particularly, when constructing and operating the app, it freezes at “Constructing 100%” and ultimately crashes with the next error:
com.fb.react.runtime.JavaScript (9): EXC_BAD_ACCESS (code=1, deal with=0x0)
Screenshot
The error happens when i add
await TrackPlayer.setupPlayer();
to the code.
That is my code :
import React, { useEffect } from 'react';
import { View, Button } from 'react-native';
import TrackPlayer,{ Functionality } from 'react-native-track-player';
const AudioPlayer: React.FC = () => {
useEffect(() => {
const setupPlayer = async () => {
await TrackPlayer.setupPlayer();
// Ajout de la piste
const audioPath = require('../../property/audio/teddy.mp3');
await TrackPlayer.add({
id: 'trackId',
url: audioPath,
title: 'Teddy Audio',
artist: 'Inconnu',
paintings: 'https://www.instance.com/paintings.jpg',
});
// Configure les contrôles de notification
TrackPlayer.updateOptions({
capabilities: [
Capability.Play,
Capability.Pause,
Capability.Stop,
],
compactCapabilities: [
Capability.Play,
Capability.Pause,
],
notificationCapabilities: [
Capability.Play,
Capability.Pause,
Capability.Stop,
],
});
};
setupPlayer();
return () => {
TrackPlayer.cease();
};
}, []);
const playAudio = async () => {
await TrackPlayer.play();
};
const pauseAudio = async () => {
await TrackPlayer.pause();
};
return (
);
};
export default AudioPlayer;
Has anybody else skilled the same challenge or discovered an answer?
Here’s what I’ve tried to date:
- Wrapped the setup in a try-catch block to seize any potential errors.
- Verified compatibility with my React Native and react-native-track-player variations.
- Ensured needed permissions and configurations are set for Android and iOS.
- add dummy.swift file