hi, in my google play console in section anr, i found a bug.
Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{d9ac2d5 u0 com.radiosreunion/com.guichaguri.trackplayer.service.MusicService}
This error has been fixed in the dev branch, which I'll release a new version soon.
Released 1.0.1.
hi, i found this error in the last version branch#dev 1.0.2
Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{dacd6f7 u0 com.radiosreunion/com.guichaguri.trackplayer.service.MusicService}
@GH974 do you have complete debug logs?
"main" tid=1 Native
"main" prio=5 tid=1 Native
| group="main" sCount=1 dsCount=0 flags=1 obj=0x72bbc4d8 self=0xeb86b000
| sysTid=14397 nice=0 cgrp=default sched=0/0 handle=0xeffdb4bc
| state=S schedstat=( 185338497 19749151 275 ) utm=10 stm=8 core=0 HZ=100
| stack=0xff02d000-0xff02f000 stackSize=8MB
| held mutexes=
#00 pc 0000000000049e58 /system/lib/libc.so (__epoll_pwait+20)
#01 pc 000000000001b6f1 /system/lib/libc.so (epoll_pwait+60)
#02 pc 000000000001b721 /system/lib/libc.so (epoll_wait+12)
#03 pc 0000000000010337 /system/lib/libutils.so (_ZN7android6Looper9pollInnerEi+118)
#04 pc 0000000000010229 /system/lib/libutils.so (_ZN7android6Looper8pollOnceEiPiS1_PPv+32)
#05 pc 00000000000e267d /system/lib/libandroid_runtime.so (_ZN7android18NativeMessageQueue8pollOnceEP7_JNIEnvP8_jobjecti+24)
#06 pc 00000000001a8edd /system/framework/arm/boot-framework.oat (Java_android_os_MessageQueue_nativePollOnce__JI+92)
at android.os.MessageQueue.nativePollOnce (Native method)
at android.os.MessageQueue.next (MessageQueue.java:325)
at android.os.Looper.loop (Looper.java:142)
at android.app.ActivityThread.main (ActivityThread.java:6938)
at java.lang.reflect.Method.invoke (Native method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)
What are the steps have you taken to reproduce this issue?
Sorry, I don't know, this bug is appear on production app, in google play. i found this, in log google play dev.
Can you send the code that you are running inside the event handler?
yes in my page index.js
import {AppRegistry, Platform} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import TrackPlayer from 'react-native-track-player';
AppRegistry.registerComponent(appName, () => App);
TrackPlayer.registerBackendService(() => require('./player-handler.js'));
and page player-handler.js
import TrackPlayer from 'react-native-track-player';
module.exports = async function() {
TrackPlayer.addEventListener('remote-play', () => {
TrackPlayer.play();
})
TrackPlayer.addEventListener('remote-pause', () => {
TrackPlayer.pause();
});
TrackPlayer.addEventListener('remote-next', async () => {
TrackPlayer.skipToNext();
});
TrackPlayer.addEventListener('remote-previous', () => {
TrackPlayer.skipToPrevious();
});
TrackPlayer.addEventListener('remote-stop', () => {
TrackPlayer.destroy();
});
};
I've got this problem as well.
I've got 22 ANR in 4 days, quite a lot !
Update :
I cannot reproduce the bug, but I've got some information from my users. And it might be when the player is in background and the track ends.
Not sure...
This issue should be reopened @Guichaguri
Hi, have you find any solution ?
Not yet, I need more details to find out what's causing the problem.
hi, sorry i don't know. In google play dev, this bug is not describe explicitly. I have now more 700bug for this.

It looks like the problem is only on android 8 and mostly on samsung device.

I still get the errors quite often mostly on android 8.
What could be the next step ?
Hi, if i have add crashlytics on the app, I could have the errors ?
I use sentry and ,unfortunately , i don't get the error in sentry. It appears only on the Google Play Console :/
I got 140 ANR in 7days and 11 anr within 24h.
yes me too.
I suppose it's a warning error, and not fatal error.
because it's impossible to reproduce the crash
That's really weird...
But if it's an ANR, it should crash the app, no ?
I will try to reproduce by using my app (if i can).
Can confirm this is also happening with my users, but not specific to Android 8 (8.1 and 9.0 included)
Context.startForegroundService() did not then call Service.startForeground()
I do not believe this happened my last version. Could be a new bug that was introduced?
@illestrater which version of the module were you using before?
I've been periodically merging your commits to my own fork which helped fix some other crashes, but then the ANR started appearing. Here's my commit with the changes that were added:
FYI, I had forked a while ago so that I could add a live audio levels meter to my app. I do not currently believe my alterations are contributing to the ANR
Unfortunately, that commit doesn't have anything suspicious...
As I don't know how to reproduce the issue, I'll start changing a few things and we'll see if that fixes the issue.
Can someone please try https://github.com/react-native-kit/react-native-track-player/commit/926b8306ee12677587fa141b47a1e30f10b650df in production to see if it fixes the crashes?
Nobody can try this fix ? :)
Is it risky ?
Worst case scenario is that when you press a media button, it stops the music. I haven't tried on emulator yet, but you should test it before releasing it to production.
I will deploy this to production for testing in my next release (due sometime next week) and report back
@Guichaguri, I will implement here, because today I will present an update in production, if successful I tell you!
Good morning @Guichaguri ,
Apparently so far the problem was solved, as it is possible to observe in the image below without fail of ANRs.


While in other versions the error was quick to be detected.

Being even found a new bug, which happened in an earlier version that I had never seen:
executing service com.hunterfm/com.guichaguri.trackplayer.service.MusicService
com.guichaguri.trackplayer.service.MusicService
Note: If you want, we can wait until Monday so I'll tell you if there was any mistake.
@xgustavoh thank you, that's great!
Yes, please do tell me. I'd love to know whether it worked :rocket:
Also deploying today, so will get back to you after a while of app usage has passed!
@Guichaguri, Good Morning!
Unfortunately the error happened, But this time it was only once, in a single device. Oo

Complete error:

Well, at least it's we've done some progress here.
Just for context, previous Android versions used to allow apps to run code in background while the app was closed. Android 8 requires the service to start as foreground (which requires a notification) when the app is in background, so the user knows whether the app is doing some work.
After starting the service, Android 8 gives only 5 seconds for the service to foreground itself, if it doesn't, it crashes. So there might be a racing issue here, a device slow enough crashes because the service doesn't set itself as foreground fast enough.
I think this one isolated crash might be it.
This issue has been reported to Google numerous times, but they are not fixing it. https://issuetracker.google.com/issues/76112072
Good afternoon @Guichaguri,
Apparently the error was not corrected. As you can see from the photo below, the error has increased.

Same here. The Bug appears with the newest version as well.

Most helpful comment
Good morning @Guichaguri ,
Apparently so far the problem was solved, as it is possible to observe in the image below without fail of ANRs.


While in other versions the error was quick to be detected.

Being even found a new bug, which happened in an earlier version that I had never seen:
executing service com.hunterfm/com.guichaguri.trackplayer.service.MusicService com.guichaguri.trackplayer.service.MusicServiceNote: If you want, we can wait until Monday so I'll tell you if there was any mistake.