aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src/github/daneren2005/dsub/receiver/A2dpIntentReceiver.java
blob: c8c3a1f9ba1b6e3ca79a99f03970844df6081799 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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);
		}
	}
}