8
8
import android .content .Context ;
9
9
import android .content .Intent ;
10
10
import android .content .IntentFilter ;
11
- import android .graphics .Bitmap ;
12
11
import android .graphics .Color ;
13
12
import android .os .Build ;
14
13
import android .os .RemoteException ;
18
17
import android .support .v4 .media .session .MediaSessionCompat ;
19
18
import android .support .v4 .media .session .PlaybackStateCompat ;
20
19
21
- import com .sahdeepsingh .Bop .Activities .PlayingNowList ;
20
+ import com .sahdeepsingh .Bop .Activities .MainScreen ;
22
21
import com .sahdeepsingh .Bop .R ;
23
- import com .sahdeepsingh .Bop .playerMain .Main ;
24
22
import com .sahdeepsingh .Bop .services .ServicePlayMusic ;
25
23
import com .sahdeepsingh .Bop .utils .utils ;
26
24
35
33
* won't be killed during playback.
36
34
*/
37
35
public class MediaNotificationManager extends BroadcastReceiver {
38
- public static final String ACTION_PAUSE = "com.example.android.uamp.pause" ;
39
- public static final String ACTION_PLAY = "com.example.android.uamp.play" ;
40
- public static final String ACTION_PREV = "com.example.android.uamp.prev" ;
41
- public static final String ACTION_NEXT = "com.example.android.uamp.next" ;
42
- public static final String ACTION_STOP = "com.example.android.uamp.stop" ;
43
- public static final String ACTION_STOP_CASTING = "com.example.android.uamp.stop_cast" ;
36
+ public static final String ACTION_PAUSE = "com.sahdeepsingh.Bop.pause" ;
37
+ public static final String ACTION_PLAY = "com.sahdeepsingh.Bop.play" ;
38
+ public static final String ACTION_PREV = "com.sahdeepsingh.Bop.prev" ;
39
+ public static final String ACTION_NEXT = "com.sahdeepsingh.Bop.next" ;
40
+ public static final String ACTION_STOP = "com.sahdeepsingh.Bop.stop" ;
44
41
private static final String TAG = "Notification" ;
45
- private static final String CHANNEL_ID = "com.example.android.uamp.MUSIC_CHANNEL_ID " ;
46
- private static final int NOTIFICATION_ID = 412 ;
42
+ private static final String CHANNEL_ID = "com.sahdeepsingh.Bop.BOP_MUSIC_CHANNEL_ID " ;
43
+ private static final int NOTIFICATION_ID = 777 ;
47
44
private static final int REQUEST_CODE = 100 ;
48
45
private final ServicePlayMusic mService ;
49
46
private final NotificationManager mNotificationManager ;
@@ -89,6 +86,7 @@ public void onSessionDestroyed() {
89
86
try {
90
87
updateSessionToken ();
91
88
} catch (RemoteException e ) {
89
+ e .printStackTrace ();
92
90
}
93
91
}
94
92
};
@@ -135,7 +133,7 @@ public void startNotification() {
135
133
filter .addAction (ACTION_PAUSE );
136
134
filter .addAction (ACTION_PLAY );
137
135
filter .addAction (ACTION_PREV );
138
- filter .addAction (ACTION_STOP_CASTING );
136
+ filter .addAction (ACTION_STOP );
139
137
mService .registerReceiver (this , filter );
140
138
141
139
mService .startForeground (NOTIFICATION_ID , notification );
@@ -175,6 +173,8 @@ public void onReceive(Context context, Intent intent) {
175
173
case ACTION_PREV :
176
174
mTransportControls .skipToPrevious ();
177
175
break ;
176
+ case ACTION_STOP :
177
+ mTransportControls .stop ();
178
178
default :
179
179
180
180
}
@@ -205,7 +205,7 @@ private void updateSessionToken() throws RemoteException {
205
205
}
206
206
207
207
private PendingIntent createContentIntent (MediaDescriptionCompat description ) {
208
- Intent openUI = new Intent (mService , PlayingNowList .class );
208
+ Intent openUI = new Intent (mService , MainScreen .class );
209
209
openUI .setFlags (Intent .FLAG_ACTIVITY_SINGLE_TOP );
210
210
211
211
return PendingIntent .getActivity (mService , REQUEST_CODE , openUI ,
@@ -219,14 +219,6 @@ private Notification createNotification() {
219
219
220
220
MediaDescriptionCompat description = mMetadata .getDescription ();
221
221
222
- Bitmap art = null ;
223
- if (description .getIconUri () != null ) {
224
- // This sample assumes the iconUri will be a valid URL formatted String, but
225
- // it can actually be any valid Android Uri formatted String.
226
- // async fetch the album art icon
227
- art = utils .getBitmapfromAlbumId (mService , Main .musicService .currentSong );
228
- }
229
-
230
222
// Notification channels are only supported on Android O+.
231
223
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
232
224
createNotificationChannel ();
@@ -239,7 +231,7 @@ private Notification createNotification() {
239
231
notificationBuilder
240
232
.setStyle (new androidx .media .app .NotificationCompat .MediaStyle ()
241
233
// show only play/pause in compact view
242
- .setShowActionsInCompactView (playPauseButtonPosition )
234
+ .setShowActionsInCompactView (0 , playPauseButtonPosition , 2 )
243
235
.setShowCancelButton (true )
244
236
.setCancelButtonIntent (mStopIntent )
245
237
.setMediaSession (mSessionToken ))
@@ -251,7 +243,7 @@ private Notification createNotification() {
251
243
.setContentIntent (createContentIntent (description ))
252
244
.setContentTitle (description .getTitle ())
253
245
.setContentText (description .getSubtitle ())
254
- .setLargeIcon (art );
246
+ .setLargeIcon (description . getIconBitmap () );
255
247
256
248
257
249
setNotificationPlaybackState (notificationBuilder );
@@ -263,7 +255,8 @@ private int addActions(final NotificationCompat.Builder notificationBuilder) {
263
255
264
256
int playPauseButtonPosition = 0 ;
265
257
// If skip to previous action is enabled
266
- if ((mPlaybackState .getActions () & PlaybackStateCompat .ACTION_SKIP_TO_PREVIOUS ) != 0 ) {
258
+ //left with "true" to provide customization for user ot change if s/he wants to
259
+ if ((true )) {
267
260
notificationBuilder .addAction (R .drawable .ic_previous , "previous" , mPreviousIntent );
268
261
269
262
// If there is a "skip to previous" button, the play/pause button will
@@ -289,11 +282,13 @@ private int addActions(final NotificationCompat.Builder notificationBuilder) {
289
282
notificationBuilder .addAction (new NotificationCompat .Action (icon , label , intent ));
290
283
291
284
// If skip to next action is enabled
292
- if (( mPlaybackState . getActions () & PlaybackStateCompat . ACTION_SKIP_TO_NEXT ) != 0 ) {
285
+ if (true ) {
293
286
notificationBuilder .addAction (R .drawable .ic_skip , "next" , mNextIntent );
294
287
}
295
288
289
+ notificationBuilder .addAction (R .drawable .ic_cancel , "cancel" , mStopIntent );
296
290
return playPauseButtonPosition ;
291
+
297
292
}
298
293
299
294
private void setNotificationPlaybackState (NotificationCompat .Builder builder ) {
0 commit comments