set pending activity intent on mediasession

This commit is contained in:
Domingos Lopes 2016-07-02 11:37:28 -04:00
parent 247fa77f9d
commit 2f235fc46e
2 changed files with 14 additions and 12 deletions

View File

@ -29,6 +29,7 @@ import android.support.v4.media.MediaDescriptionCompat;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import android.support.v4.view.InputDeviceCompat;
import android.support.v7.app.NotificationCompat;
import android.text.TextUtils;
import android.util.Log;
@ -41,8 +42,8 @@ import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.Target;
import java.util.List;
import java.util.ArrayList;
import java.util.List;
import de.danoeh.antennapod.core.ClientConfig;
import de.danoeh.antennapod.core.R;
@ -300,7 +301,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
List<MediaSessionCompat.QueueItem> queueItems = new ArrayList<>();
try {
for (FeedItem feedItem: taskManager.getQueue()) {
for (FeedItem feedItem : taskManager.getQueue()) {
queueItems.add(new MediaSessionCompat.QueueItem(feedItem.getMedia().getMediaItem().getDescription(), feedItem.getId()));
}
mediaSession.setQueue(queueItems);
@ -343,7 +344,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
}
@Override
public BrowserRoot onGetRoot(String clientPackageName, int clientUid, Bundle rootHints) {
public BrowserRoot onGetRoot(@NonNull String clientPackageName, int clientUid, Bundle rootHints) {
Log.d(TAG, "OnGetRoot: clientPackageName=" + clientPackageName +
"; clientUid=" + clientUid + " ; rootHints=" + rootHints);
return new BrowserRoot(
@ -361,10 +362,10 @@ public class PlaybackService extends MediaBrowserServiceCompat {
}
@Override
public void onLoadChildren(String parentId,
Result<List<MediaBrowserCompat.MediaItem>> result) {
public void onLoadChildren(@NonNull String parentId,
@NonNull Result<List<MediaBrowserCompat.MediaItem>> result) {
Log.d(TAG, "OnLoadChildren: parentMediaId=" + parentId);
List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<MediaBrowserCompat.MediaItem>();
List<MediaBrowserCompat.MediaItem> mediaItems = new ArrayList<>();
if (parentId.equals(getResources().getString(R.string.app_name))) {
// Root List
mediaItems.add(createBrowsableMediaItemForRoot());
@ -409,7 +410,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
if (keycode != -1) {
Log.d(TAG, "Received media button event");
handleKeycode(keycode, intent.getIntExtra(MediaButtonReceiver.EXTRA_SOURCE,
InputDevice.SOURCE_CLASS_NONE));
InputDeviceCompat.SOURCE_CLASS_NONE));
} else if (!flavorHelper.castDisconnect(castDisconnect)) {
started = true;
boolean stream = intent.getBooleanExtra(EXTRA_SHOULD_STREAM,
@ -1024,7 +1025,9 @@ public class PlaybackService extends MediaBrowserServiceCompat {
}
}
if (!Thread.currentThread().isInterrupted() && started) {
//TODO mediaSession.setSessionActivity();
mediaSession.setSessionActivity(PendingIntent.getActivity(this, 0,
PlaybackService.getPlayerActivityIntent(this),
PendingIntent.FLAG_UPDATE_CURRENT));
mediaSession.setMetadata(builder.build());
}
};
@ -1171,8 +1174,8 @@ public class PlaybackService extends MediaBrowserServiceCompat {
.setShowActionsInCompactView(compactActionList.toArray())
.setShowCancelButton(true)
.setCancelButtonIntent(stopButtonPendingIntent))
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setColor(Notification.COLOR_DEFAULT);
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setColor(NotificationCompat.COLOR_DEFAULT);
notification = notificationBuilder.build();

View File

@ -75,9 +75,8 @@ public class PlaybackServiceFlavorHelper {
boolean castDisconnect(boolean castDisconnect) {
if (castDisconnect) {
castManager.disconnect();
return true;
}
return false;
return castDisconnect;
}
boolean onMediaPlayerInfo(Context context, int code, @StringRes int resourceId) {