react-native-track-player icon indicating copy to clipboard operation
react-native-track-player copied to clipboard

can't initialize on Android and I'm stuck buffering.

Open Brightbong92 opened this issue 1 year ago • 7 comments

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

스크린샷 2024-07-09 오후 12 51 09

android log

스크린샷 2024-07-09 오후 12 49 56

SetupService.ts

스크린샷 2024-07-09 오후 12 50 21

App.ts

스크린샷 2024-07-09 오후 12 50 41

usecase.ts

스크린샷 2024-07-09 오후 12 52 25

스크린샷 2024-07-09 오후 12 52 37

Brightbong92 avatar Jul 09 '24 03:07 Brightbong92

try snipping the media src network request first with eg HTTPToolkit

lovegaoshi avatar Jul 09 '24 20:07 lovegaoshi

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...

c-goettert avatar Jul 11 '24 11:07 c-goettert

I have the same problem, does the current version work on Android for anyone?

git-user-1337 avatar Jul 15 '24 11:07 git-user-1337

We are having the same problem with RN 0.72.15. 😬 Any updates on this issue?

afiller avatar Jul 15 '24 13:07 afiller

@Brightbong92 did you find any solution to this?

c-goettert avatar Jul 29 '24 07:07 c-goettert

@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>
  }
)

Brightbong92 avatar Jul 29 '24 10:07 Brightbong92

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.

c-goettert avatar Jul 31 '24 13:07 c-goettert

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.

github-actions[bot] avatar Oct 30 '24 02:10 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Nov 07 '24 02:11 github-actions[bot]