From 4770337d1e8c78facb5fe4f5bf7bfcd428e2cfa9 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 20 Nov 2012 21:53:30 -0800 Subject: Added Bluetooth metadata --- .../dsub/receiver/A2dpIntentReceiver.java | 48 ++++++++++++++++++++++ .../src/github/daneren2005/dsub/util/Util.java | 29 +++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 subsonic-android/src/github/daneren2005/dsub/receiver/A2dpIntentReceiver.java (limited to 'subsonic-android/src/github/daneren2005') diff --git a/subsonic-android/src/github/daneren2005/dsub/receiver/A2dpIntentReceiver.java b/subsonic-android/src/github/daneren2005/dsub/receiver/A2dpIntentReceiver.java new file mode 100644 index 00000000..c8c3a1f9 --- /dev/null +++ b/subsonic-android/src/github/daneren2005/dsub/receiver/A2dpIntentReceiver.java @@ -0,0 +1,48 @@ +package github.daneren2005.dsub.receiver; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; +import github.daneren2005.dsub.service.DownloadService; +import github.daneren2005.dsub.service.DownloadServiceImpl; + +public class A2dpIntentReceiver extends BroadcastReceiver { + private static final String PLAYSTATUS_RESPONSE = "com.android.music.playstatusresponse"; + private String TAG = A2dpIntentReceiver.class.getSimpleName(); + + @Override + public void onReceive(Context context, Intent intent) { + Log.i(TAG, "GOT INTENT " + intent); + + DownloadService downloadService = DownloadServiceImpl.getInstance(); + + if (downloadService != null){ + + 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()); + + 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); + } + } +} \ No newline at end of file diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java index 7616964b..f8d108d3 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java @@ -58,6 +58,7 @@ import github.daneren2005.dsub.domain.RepeatMode; import github.daneren2005.dsub.domain.Version; import github.daneren2005.dsub.provider.DSubWidgetProvider; import github.daneren2005.dsub.receiver.MediaButtonIntentReceiver; +import github.daneren2005.dsub.service.DownloadService; import github.daneren2005.dsub.service.DownloadServiceImpl; import org.apache.http.HttpEntity; @@ -98,6 +99,9 @@ public final class Util { public static final String EVENT_META_CHANGED = "github.daneren2005.dsub.EVENT_META_CHANGED"; public static final String EVENT_PLAYSTATE_CHANGED = "github.daneren2005.dsub.EVENT_PLAYSTATE_CHANGED"; + public static final String AVRCP_PLAYSTATE_CHANGED = "com.android.music.playstatechanged"; + public static final String AVRCP_METADATA_CHANGED = "com.android.music.metachanged"; + private static boolean pauseFocus = false; private static boolean lowerFocus = false; private static int currentVolume = 0; @@ -784,7 +788,9 @@ public final class Util { *

Broadcasts the given song info as the new song being played.

*/ public static void broadcastNewTrackInfo(Context context, MusicDirectory.Entry song) { + DownloadService downloadService = (DownloadServiceImpl)context; Intent intent = new Intent(EVENT_META_CHANGED); + Intent avrcpIntent = new Intent(AVRCP_METADATA_CHANGED); if (song != null) { intent.putExtra("title", song.getTitle()); @@ -793,14 +799,31 @@ public final class Util { File albumArtFile = FileUtil.getAlbumArtFile(context, song); intent.putExtra("coverart", albumArtFile.getAbsolutePath()); + + avrcpIntent.putExtra("track", song.getTitle()); + avrcpIntent.putExtra("artist", song.getArtist()); + avrcpIntent.putExtra("album", song.getAlbum()); + avrcpIntent.putExtra("ListSize",(long) downloadService.getSongs().size()); + avrcpIntent.putExtra("id", (long) downloadService.getCurrentPlayingIndex()+1); + avrcpIntent.putExtra("duration", (long) downloadService.getPlayerDuration()); + avrcpIntent.putExtra("position", (long) downloadService.getPlayerPosition()); } else { intent.putExtra("title", ""); intent.putExtra("artist", ""); intent.putExtra("album", ""); intent.putExtra("coverart", ""); + + avrcpIntent.putExtra("track", ""); + avrcpIntent.putExtra("artist", ""); + avrcpIntent.putExtra("album", ""); + avrcpIntent.putExtra("ListSize",(long)0); + avrcpIntent.putExtra("id", (long) 0); + avrcpIntent.putExtra("duration", (long )0); + avrcpIntent.putExtra("position", (long) 0); } context.sendBroadcast(intent); + context.sendBroadcast(avrcpIntent); } /** @@ -808,25 +831,31 @@ public final class Util { */ public static void broadcastPlaybackStatusChange(Context context, PlayerState state) { Intent intent = new Intent(EVENT_PLAYSTATE_CHANGED); + Intent avrcpIntent = new Intent(AVRCP_PLAYSTATE_CHANGED); switch (state) { case STARTED: intent.putExtra("state", "play"); + avrcpIntent.putExtra("playing", true); break; case STOPPED: intent.putExtra("state", "stop"); + avrcpIntent.putExtra("playing", false); break; case PAUSED: intent.putExtra("state", "pause"); + avrcpIntent.putExtra("playing", false); break; case COMPLETED: intent.putExtra("state", "complete"); + avrcpIntent.putExtra("playing", false); break; default: return; // No need to broadcast. } context.sendBroadcast(intent); + context.sendBroadcast(avrcpIntent); } /** -- cgit v1.2.3