Skip to content

playbackState.state !== State.Ended not triggering on audio completion, causing repeat playback #2432

Open
@MalikAamirDev

Description

Describe the Bug
I am encountering an issue where playbackState.state === State.Ended is not reliably triggered when an audio file finishes playing. Instead of reaching Ended, the playback state sometimes gets stuck in Loading or Buffering, and the same audio repeats unexpectedly.

This issue occurs inconsistently and seems to affect both real devices and emulators.

Steps To Reproduce
1. Setup react-native-track-player with a simple audio queue.
2. Monitor usePlaybackState() to detect when a track ends.
3. Observe the playback state when the audio completes.
4. Occasionally, the state does not transition to Ended, and instead:
• Gets stuck in Buffering or Loading
• Restarts the same audio instead of proceeding to the next track

Code To Reproduce
import TrackPlayer, { Event, State, usePlaybackState } from 'react-native-track-player';
import { useEffect } from 'react';

const playbackState = usePlaybackState();

useEffect(() => {
console.log('🟢 Current playback state:', playbackState.state);

if (playbackState.state === State.Ended) {
console.log("✅ Audio finished playing");
// Handle track completion logic here
}
}, [playbackState]);

Expected Behavior:
• State should transition to Ended when audio finishes.
• Should not get stuck in Buffering or Loading after finishing a track.

Actual Behavior:
• The track sometimes repeats instead of stopping.
• The state gets stuck in Buffering or Loading instead of Ended.

Replicable on Example App?
No

Environment Info:
System:
OS: macOS 15.3
CPU: (8) arm64 Apple M2
Memory: 143.38 MB / 8.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 23.2.0
path: /opt/homebrew/bin/node
Yarn:
version: 1.22.22
path: /opt/homebrew/bin/yarn
npm:
version: 10.9.0
path: /opt/homebrew/bin/npm
Watchman:
version: 2024.11.11.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.16.2
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 24.2
- iOS 18.2
- macOS 15.2
- tvOS 18.2
- visionOS 2.2
- watchOS 11.2
Android SDK: Not Found
IDEs:
Android Studio: 2024.2 AI-242.23726.103.2422.12816248
Xcode:
version: 16.2/16C5032a
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.13
path: /usr/bin/javac
Ruby:
version: 2.6.10
path: /usr/bin/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.72.10
wanted: 0.72.10
react-native-macos: Not Found
npmGlobalPackages:
"react-native": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false

react-native-track-player: 4.1.1
Both Android and iOS
Both Real and Simulators/Emulators
Android: 14
ios: 18.1.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions