can't initialize on Android and I'm stuck buffering.
What is the need and use case of this feature?
It sets up normally in ios, but not in android. It stays buffering. Why is that?
ios log
android log
SetupService.ts
App.ts
usecase.ts
try snipping the media src network request first with eg HTTPToolkit
I am facing the same issue (using react-native: 0.72.15). Downgrading to 4.0.0-rc04 fixes the issue for me which shows it's not a network issue...
I have the same problem, does the current version work on Android for anyone?
We are having the same problem with RN 0.72.15. 😬 Any updates on this issue?
@Brightbong92 did you find any solution to this?
@c-goettert I am sharing the method that I have solved.
"react-native": "0.74.1",
"react-native-track-player": "^4.1.1",
// useSetupPalyer.ts
import { useEffect, useState } from 'react';
import TrackPlayer from 'react-native-track-player';
import { SetupService } from '@/utils/track-player';
export interface UseSetupPlayerProps {
cb?: () => Promise<void>;
}
export function useSetupPlayer({ cb }: UseSetupPlayerProps) {
const [isPlayerReady, setIsPlayerReady] = useState<boolean>(false);
useEffect(() => {
let unmounted = false;
(async () => {
await SetupService();
if (unmounted) return;
setIsPlayerReady(true);
const queue = await TrackPlayer.getQueue();
if (unmounted) return;
if (queue.length <= 0) {
cb && cb();
}
})();
return () => {
unmounted = true;
};
}, []);
return isPlayerReady;
}
// useHooks.ts
const track1 = {
url, // Load media from the network
title: 'Avaritia',
artist: 'deadmau5',
album: 'while(1<2)',
genre: 'Progressive House, Electro House',
date: '2014-05-20T07:00:00+00:00', // RFC 3339
artwork: 'https://example.com', // Load artwork from the network
duration: 0, // Duration in seconds
};
...
const addPlayer = useCallback(async () => {
await TrackPlayer.add([track1]);
}, []);
const isPlayerReady = useSetupPlayer({ cb: addPlayer });
...
return {
...
isReady: isPlayerReady
...
};
// view.tsx
...
const {isReady} = useHooks();
...
return (
{
isReady ? <Text>show</Text> : <Text>loading...</Text>
}
)
Thanks for posting you solution @Brightbong92 . Indeed I found out that for me it was something else that has caused the bug: I was calling TrackPlayer.reset() immediately before starting the Player without waiting for it. Something like:
...
await TrackPlayer.setupPlayer()
...
TrackPlayer.reset()
...
await TrackPlayer.add([track])
TrackPlayer.play()
As the reset call is asynchronous it also removed the track I added to the queue immediately after the call. I could fix it by adding an await to the reset function (it returns a promise). This issue can be closed from my perspective.
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.