Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS. Buffering takes too long or ends in an error #2345

Open
yeezussniper opened this issue Jul 20, 2024 · 1 comment
Open

IOS. Buffering takes too long or ends in an error #2345

yeezussniper opened this issue Jul 20, 2024 · 1 comment
Labels

Comments

@yeezussniper
Copy link

The behaviour is random, I can successfully and quickly turn on 3-5 tracks and everything hangs, but it can also hang immediately on the first track. The behaviour is not clear to me, it works very randomly

I know this isn't a new problem, I've been seeing threads since ~20 years. But I don't see a normal explanation or solution

My init player code

async function initPlayer() {
    let isPlayerInitialized = false;

    if (!isPlayerInitialized) {
        try {
            await TrackPlayer.setupPlayer({
                autoHandleInterruptions: true,
                waitForBuffer: true
            }).then(async () => {
                await TrackPlayer.updateOptions({
                    capabilities: [
                        Capability.Play,
                        Capability.Pause,
                        Capability.JumpBackward,
                        Capability.JumpForward,
                        Capability.SeekTo
                    ]
                });
            });

            TrackPlayer.addEventListener(Event.PlaybackState, (e) => {
                console.log('PlaybackState', e, dayjs().format('HH:MM:SS YYYY-MM-DD'))
            })

            isPlayerInitialized = true;
            console.log('Player initial')
        } catch (e) {
            isPlayerInitialized = false;
            console.log(e)
        }
    }
}

initPlayer()

How I switch tracks

    const activeTrack = await TrackPlayer.getActiveTrack()

    if (activeTrack) {
        await TrackPlayer.stop()
        await TrackPlayer.reset()
        console.warn('Old track has been reset');
    }

    await TrackPlayer.add({
        url: episode.recordUrl,
        title: episode.title,
        artist: episode.album.author,
        album: episode.album.title,
        artwork: process.env.EXPO_PUBLIC_API_URL + episode.image,
        id: episode.id,
        contentType: 'audio/mpeg'
    }).then(async () => {
        console.warn('New track has been added');
        await TrackPlayer.play()
    });

Logs

 LOG  PlaybackState {"state": "loading"} 07:21:15 2024-07-20
 LOG  PlaybackState {"state": "buffering"} 07:21:15 2024-07-20
 LOG  PlaybackState {"state": "ready"} 07:21:32 2024-07-20
 LOG  PlaybackState {"state": "playing"} 07:21:32 2024-07-20

or

 LOG  PlaybackState {"state": "loading"} 07:22:02 2024-07-20
 LOG  PlaybackState {"state": "buffering"} 07:22:02 2024-07-20
 LOG  PlaybackState {"error": {"code": "ios_failed_to_load_resource", "message": "Failed to load resource"}, "state": "error"} 07:24:02 2024-07-20
 ERROR  {"error": "The operation couldn’t be completed. (SwiftAudioEx.AudioPlayerError.PlaybackError error 1.)"}

Environment Info:
Paste the results of npx react-native info
Paste the exact react-native-track-player version you are using
Real device? Or simulator?
What OS are you running?

Packages version:
"react-native": "0.74.1",
"react-native-track-player": "^4.1.1"
IOS Simulator 17.5
Mac OS

@yeezussniper yeezussniper changed the title Buffering takes too long or ends in an error IOS. Buffering takes too long or ends in an error Jul 20, 2024
@mfucek
Copy link

mfucek commented Sep 6, 2024

I had the same issue on my end. Only sometimes does it get stuck in a buffering state, but when it does clearing the queue and playing another track doesn't fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants