ultrasonic-app-subsonic-and.../src/com/thejoshwa/ultrasonic/androidapp/receiver/A2dpIntentReceiver.java

65 lines
1.7 KiB
Java
Raw Normal View History

package com.thejoshwa.ultrasonic.androidapp.receiver;
import com.thejoshwa.ultrasonic.androidapp.domain.MusicDirectory.Entry;
import com.thejoshwa.ultrasonic.androidapp.service.DownloadService;
import com.thejoshwa.ultrasonic.androidapp.service.DownloadServiceImpl;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class A2dpIntentReceiver extends BroadcastReceiver {
private static final String PLAYSTATUS_RESPONSE = "com.android.music.playstatusresponse";
@Override
public void onReceive(Context context, Intent intent) {
DownloadService downloadService = DownloadServiceImpl.getInstance();
if (downloadService == null) {
return;
}
if (downloadService.getCurrentPlaying() == null) {
return;
}
Entry song = downloadService.getCurrentPlaying().getSong();
if (song == null) {
return;
}
Intent avrcpIntent = new Intent(PLAYSTATUS_RESPONSE);
Integer duration = song.getDuration();
Integer playerPosition = downloadService.getPlayerPosition();
Integer listSize = downloadService.getDownloads().size();
if (duration != null) {
avrcpIntent.putExtra("duration", (long) duration);
}
2013-06-07 10:47:57 +02:00
avrcpIntent.putExtra("position", (long) playerPosition);
avrcpIntent.putExtra("ListSize", (long) listSize);
2013-06-07 10:47:57 +02:00
switch (downloadService.getPlayerState()) {
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);
}
}