-
Notifications
You must be signed in to change notification settings - Fork 25
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
Background Mode Not Working #11
Comments
@sirgatsen Try adding |
@fromage9747 you mean |
If you use this plugin it will no longer run in the background but in the foreground and will not stop if the app goes to the background. Recently had it myself and solved it with this plugin You can then make it like this I have inside the play() {} |
That's pretty much what I have in mine. So far so good 👍 |
That is also pretty much my setup as well, but like I said my Android app dies randomly after a few varied minutes. |
Anyone solved this issue? Mine plays a few minutes then die. I'm using Native Media . Also, my media controls are showing in the notifications, but not when phone is locked. And I can't skip or go to previous from my car bluetooth |
@@ -3,6 +3,7 @@ package com.getcapacitor;
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
+import android.view.View;
import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
@@ -49,4 +50,9 @@ public class CapacitorWebView extends WebView {
}
return super.dispatchKeyEvent(event);
}
+
+ @Override
+ public void dispatchWindowVisibilityChanged(int visibility) {
+ super.onWindowVisibilityChanged(View.VISIBLE);
+ }
}
I override the Hope this can solve the problem your meet. |
@Amoyens1s I am desperate. I have been trying to fix this background audio issue forever. I am attempting to incorporate your fix above, but am not having any luck. I beg for your guidance. |
@bonomite I'm not sure if your audio application scenario is similar, but if you're using the By the way, I'm using Capacitor 5 and using If you have any further questions, feel free to reply to me. |
Ah ok... I have added that code to that file... testing it now... it takes 5 minutes when the screen is off for the audio to stop playing. |
This is nuts... it's working! You have NO idea how long I've been trying to figure this out. So there is no way to add this change on the front end? It has to be inside the Capacitor package? |
Yes, it has to be done inside the Capacitor package. There is no way to achieve this through front-end techniques. |
@Amoyens1s do you have a PayPal or venmo account? |
You don't need to pay me. I encountered the same problem and struggled a lot before finally solving it. Being able to help others is my greatest joy. I'm just happy I could solve your problem. |
I'd like to buy you a drink at least. |
Just adding this here for copy and paste purposes. I didn't ever have an issue with my audio playing in the background, it just worked, but what I did have an issue with was coming back to my app I would need the screen to be touched in order for it to display and update the track in the UI that is currently playing. Haven't tested this yet, but I hope that this code sorts that.
|
you have said before that after 5 minutes audio would stop working. did it get fixed? |
My app uses the standard HTML5 Audio element to play audio and Android keeps killing my app after a few (3-4) minutes in the background. My test device is on Android 11
I know you are using a foreground service to provide this functionality but can you maybe look into adding the wake lock if you aren't already?
The text was updated successfully, but these errors were encountered: