GithubHelp home page GithubHelp logo

Comments (7)

c-goettert avatar c-goettert commented on August 26, 2024 1

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

from react-native-track-player.

git-user-1337 avatar git-user-1337 commented on August 26, 2024 1

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

from react-native-track-player.

lovegaoshi avatar lovegaoshi commented on August 26, 2024

try snipping the media src network request first with eg HTTPToolkit

from react-native-track-player.

afiller avatar afiller commented on August 26, 2024

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

from react-native-track-player.

c-goettert avatar c-goettert commented on August 26, 2024

@Brightbong92 did you find any solution to this?

from react-native-track-player.

Brightbong92 avatar Brightbong92 commented on August 26, 2024

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

from react-native-track-player.

c-goettert avatar c-goettert commented on August 26, 2024

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.

from react-native-track-player.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.