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

RepeatMode.Off Not Respected on Android Device #2428

Open
kimangell opened this issue Jan 11, 2025 · 0 comments
Open

RepeatMode.Off Not Respected on Android Device #2428

kimangell opened this issue Jan 11, 2025 · 0 comments
Labels

Comments

@kimangell
Copy link

kimangell commented Jan 11, 2025

Describe the Bug
No matter if repeat mode is set to RepeatMode.Off or RepeatMode.Track, audio repeats on Android device. I know a similar issue was reported before, but it was the opposite situation that time. I can confirm repeat mode is correctly set and has the right value by calling getRepeatMode() after setting it:

 const currentMode = await TrackPlayer.getRepeatMode();
 console.log('Repeat mode after set:', currentMode);

RepeatMode.Off is also respected on iOS simulator using the same codebase.

Steps To Reproduce

  1. Set up track player. I set mine up like so:
import { useEffect, useRef } from 'react';
import TrackPlayer, { Capability, RatingType, RepeatMode } from 'react-native-track-player';
import { AppKilledPlaybackBehavior } from 'react-native-track-player';

const setupPlayer = async () => {
  await TrackPlayer.setupPlayer({
    maxCacheSize: 1024 * 50,
  })

  await TrackPlayer.updateOptions({
    ratingType: RatingType.Heart,
    capabilities: [
      Capability.Play,
      Capability.Pause,
      Capability.SeekTo
    ],
    android: {
      appKilledPlaybackBehavior: AppKilledPlaybackBehavior.StopPlaybackAndRemoveNotification
    },
  })

  await TrackPlayer.setVolume(1);
  await TrackPlayer.setRepeatMode(RepeatMode.Off);
}
  1. Prepare a track object
    I'm preparing mine like so:
const track = {
    id: audio.id,
    url: url,
    artwork: artwork,
    title: audio.title,
    duration: audio.duration ? Number(audio.duration) : undefined,
    headers: {},
}
  1. Load and play track
const handlePress = async () => {
      await TrackPlayer.load(track);
      await TrackPlayer.play();
  }
  1. Let track end by itself

Code To Reproduce
See last section

Replicable on Example App?
I'm unable to get gradle to work on my machine, so not sure how to set up the example app. I use eas build -p android for my app.

Environment Info:
Result of npx react-native info:

System:
  OS: macOS 14.5
  CPU: (8) arm64 Apple M1
  Memory: 105.58 MB / 8.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.4
    path: /opt/homebrew/bin/node
  Yarn:
    version: 1.22.22
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.7.0
    path: /opt/homebrew/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods: Not Found
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: Not Found
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.25
    path: /opt/homebrew/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.74.5
    wanted: 0.74.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

React Native and RNTP versions:

"react-native-track-player": "^4.1.1",
"react-native": "0.74.5",

Platform-specific app.json config:

{
    "ios": {
      "supportsTablet": false,
      "bundleIdentifier": "[redacted]",
      "infoPlist": {
        "UIBackgroundModes": [
          "audio"
        ],
        "NSMicrophoneUsageDescription": "This app requires access to the microphone to record audio.",
        "ITSAppUsesNonExemptEncryption": false
      }
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/images/adaptive-icon.png",
        "backgroundColor": "#121212"
      },
      "softwareKeyboardLayoutMode": "pan",
      "package": "[redacted]"
    },
    "plugins": [
      [
        "expo-build-properties",
        {
          "android": {
            "minSdkVersion": 24
          }
        }
      ]
    ],
    "experiments": {
      "typedRoutes": true
    }
  }
}

The issue occurs on Android device. Everything works fine on iOS simulator.

How I can Help
What can you do to help resolve this?

  • Open to any suggestions

Have you investigated the underlying JS or Swift/Android code causing this bug?

  • Not sure where to look. Both setRepeatMode and getRepeatMode work as they should. Which function is responsible for evaluating whether to repeat or not on track end?

Can you create a Pull Request with a fix?

  • Not currently

Thank you so much everyone involved in creating and maintaining this library! It's been invaluable <3

@kimangell kimangell added the Bug label Jan 11, 2025
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

1 participant