Audinaut-subsonic-app-android/app/src/main/java/net/nullsum/audinaut/receiver/A2dpIntentReceiver.java

49 lines
1.6 KiB
Java
Raw Normal View History

2017-01-09 08:01:12 +01:00
package net.nullsum.audinaut.receiver;
2016-12-18 18:41:30 +01:00
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
2018-03-25 03:28:28 +02:00
2017-01-09 08:01:12 +01:00
import net.nullsum.audinaut.service.DownloadService;
2016-12-18 18:41:30 +01:00
public class A2dpIntentReceiver extends BroadcastReceiver {
2018-03-24 20:25:12 +01:00
private static final String PLAYSTATUS_RESPONSE = "com.android.music.playstatusresponse";
2018-03-25 03:28:28 +02:00
private final String TAG = A2dpIntentReceiver.class.getSimpleName();
2018-03-24 20:25:12 +01:00
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "GOT INTENT " + intent);
DownloadService downloadService = DownloadService.getInstance();
2018-03-25 03:28:28 +02:00
if (downloadService != null) {
2018-03-24 20:25:12 +01:00
Intent avrcpIntent = new Intent(PLAYSTATUS_RESPONSE);
avrcpIntent.putExtra("duration", (long) downloadService.getPlayerDuration());
avrcpIntent.putExtra("position", (long) downloadService.getPlayerPosition());
avrcpIntent.putExtra("ListSize", (long) downloadService.getSongs().size());
2018-03-25 03:28:28 +02:00
switch (downloadService.getPlayerState()) {
2018-03-24 20:25:12 +01:00
case STARTED:
avrcpIntent.putExtra("playing", true);
break;
case STOPPED:
avrcpIntent.putExtra("playing", false);
break;
case PAUSED:
avrcpIntent.putExtra("playing", false);
break;
case COMPLETED:
avrcpIntent.putExtra("playing", false);
break;
default:
return;
}
context.sendBroadcast(avrcpIntent);
}
}
}