-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathA2dpSinkPresenter.java
More file actions
executable file
·54 lines (45 loc) · 1.85 KB
/
A2dpSinkPresenter.java
File metadata and controls
executable file
·54 lines (45 loc) · 1.85 KB
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
49
50
51
52
53
54
package com.ayst.sample.items.a2dpsink;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.MediaMetadata;
import android.media.session.PlaybackState;
import android.util.Log;
public class A2dpSinkPresenter {
private static final String TAG = "A2dpSinkPresenter";
private static final String ACTION_TRACK_EVENT =
"android.bluetooth.avrcp-controller.profile.action.TRACK_EVENT";
public static final String EXTRA_METADATA =
"android.bluetooth.avrcp-controller.profile.extra.METADATA";
public static final String EXTRA_PLAYBACK =
"android.bluetooth.avrcp-controller.profile.extra.PLAYBACK";
private Context mContext;
private IA2dpSinkView mA2dpSinkView;
public A2dpSinkPresenter(Context context, IA2dpSinkView view) {
mContext = context;
mA2dpSinkView = view;
}
public void start() {
IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_TRACK_EVENT);
mContext.registerReceiver(mBtReceiver, filter);
}
public void stop() {
mContext.unregisterReceiver(mBtReceiver);
}
private BroadcastReceiver mBtReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "onReceive intent=" + intent);
String action = intent.getAction();
if (ACTION_TRACK_EVENT.equals(action)) {
PlaybackState pbb = intent.getParcelableExtra(EXTRA_PLAYBACK);
MediaMetadata mmd = intent.getParcelableExtra(EXTRA_METADATA);
if (null != mmd) {
mA2dpSinkView.updateA2dpSinkMediaInfo(mmd);
}
}
}
};
}