aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--subsonic-android/AndroidManifest.xml8
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/receiver/A2dpIntentReceiver.java48
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/receiver/BluetoothIntentReceiver.java11
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Util.java29
4 files changed, 94 insertions, 2 deletions
diff --git a/subsonic-android/AndroidManifest.xml b/subsonic-android/AndroidManifest.xml
index c731b981..0a3b7c97 100644
--- a/subsonic-android/AndroidManifest.xml
+++ b/subsonic-android/AndroidManifest.xml
@@ -99,8 +99,16 @@
<intent-filter>
<action android:name="android.bluetooth.a2dp.action.SINK_STATE_CHANGED"/>
<action android:name="android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED"/> <!-- API Level 11 -->
+ <action android:name="android.bluetooth.device.action.ACL_CONNECTED"/>
+ <action android:name="android.bluetooth.device.action.ACL_DISCONNECTED"/>
</intent-filter>
</receiver>
+
+ <receiver android:name="net.sourceforge.subsonic.androidapp.receiver.A2dpIntentReceiver">
+ <intent-filter>
+ <action android:name="android.music.playstatusrequest"/>
+ </intent-filter>
+ </receiver>
<receiver android:name="github.daneren2005.dsub.provider.DSubWidgetProvider" >
<intent-filter>
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/receiver/BluetoothIntentReceiver.java b/subsonic-android/src/github/daneren2005/dsub/receiver/BluetoothIntentReceiver.java
index 5b65760a..567cf8f4 100644
--- a/subsonic-android/src/github/daneren2005/dsub/receiver/BluetoothIntentReceiver.java
+++ b/subsonic-android/src/github/daneren2005/dsub/receiver/BluetoothIntentReceiver.java
@@ -18,6 +18,7 @@
*/
package github.daneren2005.dsub.receiver;
+import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -51,10 +52,13 @@ public class BluetoothIntentReceiver extends BroadcastReceiver {
intent.getIntExtra("android.bluetooth.a2dp.extra.SINK_STATE", -1) == STATE_CONNECTED) {
return true;
}
- if ("android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED".equals(intent.getAction()) &&
+ else if ("android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED".equals(intent.getAction()) &&
intent.getIntExtra("android.bluetooth.profile.extra.STATE", -1) == STATE_CONNECTED) {
return true;
}
+ else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(intent.getAction())) {
+ return true;
+ }
return false;
}
private boolean isDisconnected(Intent intent) {
@@ -62,10 +66,13 @@ public class BluetoothIntentReceiver extends BroadcastReceiver {
intent.getIntExtra("android.bluetooth.a2dp.extra.SINK_STATE", -1) == STATE_DISCONNECTED) {
return true;
}
- if ("android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED".equals(intent.getAction()) &&
+ else if ("android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED".equals(intent.getAction()) &&
intent.getIntExtra("android.bluetooth.profile.extra.STATE", -1) == STATE_DISCONNECTED) {
return true;
}
+ else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(intent.getAction())) {
+ return true;
+ }
return false;
}
} \ 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 497df90c..2bdd969e 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;
@@ -791,7 +795,9 @@ public final class Util {
* <p>Broadcasts the given song info as the new song being played.</p>
*/
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());
@@ -800,14 +806,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);
}
/**
@@ -815,25 +838,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);
}
/**