tlenclos / react-native-audio-streaming

iOS & Android react native module to play an audio stream, with background support and media controls
MIT License
781 stars 255 forks source link

Player notification stays active but unresponsive when app is closed #79

Open gwitteveen opened 7 years ago

gwitteveen commented 7 years ago

The player notification stays in the notification screen when the app is closed, but becomes unresponsive as in the play button doesn't work and the close button doesn't work.

You would expect the notification to be removed when the app is closed or at least be able to dismiss the notification.

I thought it might due to the way I implemented react-native-audio-streaming, but I checked LaCaveWebradio from the Play store and there the issue seems to persist.

Tested on Android 7.0

jerodb commented 7 years ago

@gwitteveen, the solution @samyachour proposes in #49 fixes the problem.

MichaelPintos commented 7 years ago

not working #49

jerodb commented 7 years ago

Hi @MichaelPintos, did you add the created service to your app's AndroidManifest.xml?

1) Create new Service (I called it OnTaskRemovedService). I created a new file with the following content:

package com.example;

import android.app.Service;
import android.os.IBinder;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;

public class OnTaskRemovedService extends Service {
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onTaskRemoved(Intent rootIntent) {
        super.onTaskRemoved(rootIntent);
        NotificationManager nManager = ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE));
        nManager.cancelAll();
    }
}

2) Start service in MainActivity.java:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startService(new Intent(this, OnTaskRemovedService.class));
    }

Don't forget to import Intent and Bundle into your MainActivity.java:

import android.content.Intent;
import android.os.Bundle;

3) Finally add the service in the app's AndroidManifest.xml like this:

<service android:name="com.example.OnTaskRemovedService" android:stopWithTask="false" />

In all cases replace com.example with com.whateverYourApp

This worked for me. You can see a working example I uploaded to the play store a few days ago here: https://play.google.com/store/apps/details?id=com.am750&hl=en The only issue I couldn't resolve for this app was #80 . For the rest of the repo, it's a great work by @tlenclos

MichaelPintos commented 7 years ago

Hi, thx for help #80 work fine

El 28 abr. 2017, a las 14:46, Jero notifications@github.com escribió:

Hi @MichaelPintos https://github.com/MichaelPintos, did you add the created service to your app's AndroidManifest.xml?

Create new Service (I called it OnTaskRemovedService). I created a new file with the following content: package com.example;

import android.app.Service; import android.os.IBinder; import android.app.NotificationManager; import android.content.Context; import android.content.Intent;

public class OnTaskRemovedService extends Service { /* interface for clients that bind / @Override public IBinder onBind(Intent intent) { return null; }

@Override
public void onTaskRemoved(Intent rootIntent) {
    super.onTaskRemoved(rootIntent);
    NotificationManager nManager = ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE));
    nManager.cancelAll();
}

} Start service in MainActivity.java: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); startService(new Intent(this, OnTaskRemovedService.class)); } Don't forget to import Intent and Bundle into your MainActivity.java:

import android.content.Intent; import android.os.Bundle; Finally declare the service in the app's AndroidManifest.xml:

In all cases replace com.example with com.whateverYourApp

This worked for me. You can see a working example I uploaded to the app store a few days ago here: https://play.google.com/store/apps/details?id=com.am750&hl=en https://play.google.com/store/apps/details?id=com.am750&hl=en The only issue I couldn't resolve for this app was #80 https://github.com/tlenclos/react-native-audio-streaming/issues/80 . For rest of the repo, it's a great work by @tlenclos https://github.com/tlenclos — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tlenclos/react-native-audio-streaming/issues/79#issuecomment-298062822, or mute the thread https://github.com/notifications/unsubscribe-auth/AZpDPpj0qBSvhmUtfW-GKyzopcnvX1_Xks5r0iXvgaJpZM4MiMR5.