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

Android notification pause button not working as expected #978

Closed
Devansh8086 opened this issue Apr 28, 2023 · 4 comments
Closed

Android notification pause button not working as expected #978

Devansh8086 opened this issue Apr 28, 2023 · 4 comments
Assignees
Labels
1 backlog bug Something isn't working

Comments

@Devansh8086
Copy link

Which API doesn't behave as documented, and how does it misbehave?
When using the notification pause button on Android the music stops after few minutes and app is getting crashed/closed automatically but this is not happening in all the devices (perfectly working in Samsung M12 - Android 13, moto e13 - Android 13).

Minimal reproduction project
Provide a link here using one of two options:
The example

To Reproduce (i.e. user steps, not code)
Steps to reproduce the behavior:

  1. Launch the app
  2. Click Play
  3. Open the notification shade
  4. Click Pause on the notification
  5. App is getting crashed/closed automatically

Error messages

E/AndroidRuntime(28901): android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{729c672 u0 com.example.audio_demo/com.dooboolab.TauEngine.FlautoBackgroundAudioService}
E/AndroidRuntime(28901): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2126)
E/AndroidRuntime(28901): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(28901): 	at android.os.Looper.loop(Looper.java:236)
E/AndroidRuntime(28901): 	at android.app.ActivityThread.main(ActivityThread.java:8057)
E/AndroidRuntime(28901): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(28901): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
E/AndroidRuntime(28901): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
I/Process (28901): Sending signal. PID: 28901 SIG: 9
Lost connection to device.

Expected behavior
Music must stop.

Screenshots

Desktop (please complete the following information):

Smartphone (please complete the following information):

  • Device: Redmi note 8 pro

  • OS: Android 11

  • Device: Redmi 9i

  • OS: Android 10

  • Device: Tecno LE6

  • OS: Android 11

Flutter SDK version

[√] Flutter (Channel stable, 3.7.7, on Microsoft Windows [Version 10.0.22621.1555], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[√] Chrome - develop for the web
[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2022.1)
[√] VS Code (version 1.77.3)
[√] Connected device (4 available)
[√] HTTP Host Availability

Additional context
AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.audio_demo"
    tools:ignore="Instantiatable">

    <permission
        android:name="android.permission.MEDIA_CONTENT_CONTROL"
        tools:ignore="ReservedSystemPermission" />

    <uses-permission android:name="android.permission.READ_CALENDAR" />
    <uses-permission android:name="android.permission.WRITE_CALENDAR" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.BLUETOOTH" />

    <application
        android:name="${applicationName}"
        android:icon="@mipmap/appicon_without_shadow"
        android:label="Demo"
        android:requestLegacyExternalStorage="true"
        android:theme="@style/AppTheme"
        tools:replace="android:theme">

        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/ic_notification_icon" />
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_channel_id"
            android:value="@string/default_notification_channel_id" />

        <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
        <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

        <activity
            android:name="com.ryanheise.audioservice.AudioServiceActivity"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:exported="true"
            android:hardwareAccelerated="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:usesCleartextTraffic="true"
            android:windowSoftInputMode="adjustResize"
            tools:ignore="Instantiatable">

            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme" />

            <meta-data
                android:name="io.flutter.embedding.android.SplashScreenDrawable"
                android:resource="@drawable/launch_background" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

        </activity>

        <activity android:name="io.flutter.embedding.android.FlutterActivity" />

        <activity
            android:name="com.yalantis.ucrop.UCropActivity"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar" />

        <activity
            android:name="com.stripe.android.payments.StripeBrowserLauncherActivity"
            android:exported="true" />

        <!-- ADD THIS "SERVICE" element -->
        <service
            android:name="com.ryanheise.audioservice.AudioService"
            android:exported="true"
            android:foregroundServiceType="mediaPlayback"
            tools:ignore="Instantiatable">
            <intent-filter>
                <action android:name="android.media.browse.MediaBrowserService" />
            </intent-filter>
        </service>

        <!-- ADD THIS "RECEIVER" element -->
        <receiver
            android:name="com.ryanheise.audioservice.MediaButtonReceiver"
            android:exported="true"
            tools:ignore="Instantiatable">
            <intent-filter>
                <action android:name="android.intent.action.MEDIA_BUTTON" />
            </intent-filter>
        </receiver>

        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />

    </application>
</manifest>
@Devansh8086 Devansh8086 added 1 backlog bug Something isn't working labels Apr 28, 2023
@ryanheise
Copy link
Owner

Here's the relevant Java code:

    private void enterPlayingState() {
        ContextCompat.startForegroundService(this, new Intent(AudioService.this, AudioService.class));
        if (!mediaSession.isActive())
            mediaSession.setActive(true);

        acquireWakeLock();
        mediaSession.setSessionActivity(contentIntent);
        internalStartForeground();
    }

    private void internalStartForeground() {
        startForeground(NOTIFICATION_ID, buildNotification());
        notificationCreated = true;
    }

As you can see, startForeground is called unconditionally following every call to startForegroundService unless some OTHER exception is occurring between the first and the second call. Since you didn't report any other exception happening between those two calls, I suspect there is something inconsistent with your report. Maybe either you are not using "the example" or maybe the reproduction steps are not exactly accurate?

@jaythakkarBAPS
Copy link

same issue face

@ryanheise
Copy link
Owner

Just looking at the error message, it seems to be reporting an error in a different audio plugin (com.dooboolab.TauEngine.FlautoBackgroundAudioService). Please report the bug to that project.

Copy link

github-actions bot commented Oct 3, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with just_audio.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 backlog bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants
@ryanheise @Devansh8086 @jaythakkarBAPS and others