diff options
author | Domingos Lopes <domingos86lopes+github@gmail.com> | 2016-06-28 02:07:43 -0400 |
---|---|---|
committer | Domingos Lopes <domingos86lopes+github@gmail.com> | 2016-06-28 02:18:11 -0400 |
commit | 6d0debfd4d0c19ebe0287b136072b05ae6d8e65f (patch) | |
tree | 5537d380200a1980484c517a28af46d2ab39581c /core/src | |
parent | 926f3912cfc774ebf89db9d668ec3d31c6634f70 (diff) | |
download | AntennaPod-6d0debfd4d0c19ebe0287b136072b05ae6d8e65f.zip |
implement custom mediaroute playback controller
Diffstat (limited to 'core/src')
6 files changed, 41 insertions, 18 deletions
diff --git a/core/src/free/java/de/danoeh/antennapod/core/CastCallbacks.java b/core/src/free/java/de/danoeh/antennapod/core/CastCallbacks.java new file mode 100644 index 000000000..2e266c736 --- /dev/null +++ b/core/src/free/java/de/danoeh/antennapod/core/CastCallbacks.java @@ -0,0 +1,7 @@ +package de.danoeh.antennapod.core; + +/** + * Callbacks for Chromecast support on the core module + */ +public interface CastCallbacks { +} diff --git a/core/src/free/java/de/danoeh/antennapod/core/ClientConfig.java b/core/src/free/java/de/danoeh/antennapod/core/ClientConfig.java index d1c93d782..eb2e6fc9e 100644 --- a/core/src/free/java/de/danoeh/antennapod/core/ClientConfig.java +++ b/core/src/free/java/de/danoeh/antennapod/core/ClientConfig.java @@ -30,6 +30,8 @@ public class ClientConfig { public static DBTasksCallbacks dbTasksCallbacks; + public static CastCallbacks castCallbacks; + private static boolean initialized = false; public static synchronized void initialize(Context context) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 76c960607..c79d662cb 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -28,11 +28,9 @@ import android.support.v7.app.NotificationCompat; import android.text.TextUtils; import android.util.Log; import android.util.Pair; -import android.view.Display; import android.view.InputDevice; import android.view.KeyEvent; import android.view.SurfaceHolder; -import android.view.WindowManager; import android.widget.Toast; import com.bumptech.glide.Glide; @@ -945,31 +943,32 @@ public class PlaybackService extends Service { builder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, p.getEpisodeTitle()); builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, p.getFeedTitle()); - if (p.getImageLocation() != null && UserPreferences.setLockscreenBackground()) { - builder.putString(MediaMetadataCompat.METADATA_KEY_ART_URI, p.getImageLocation().toString()); - try { - if (isCasting) { + String imageLocation = p.getImageLocation(); + + if (!TextUtils.isEmpty(imageLocation)) { + if (isCasting || UserPreferences.setLockscreenBackground()) { + builder.putString(MediaMetadataCompat.METADATA_KEY_ART_URI, imageLocation); + builder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI, imageLocation); + try { Bitmap art = Glide.with(this) - .load(p.getImageLocation()) + .load(imageLocation) .asBitmap() .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) .into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .get(); builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, art); - } else { - WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); - Display display = wm.getDefaultDisplay(); - Bitmap art = Glide.with(this) - .load(p.getImageLocation()) + // Icon is useful for MediaDescription, + Bitmap icon = Glide.with(this) + .load(imageLocation) .asBitmap() .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) - .centerCrop() - .into(display.getWidth(), display.getHeight()) + .fitCenter() + .into(128, 128) .get(); - builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, art); + builder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, icon); + } catch (Throwable tr) { + Log.e(TAG, Log.getStackTraceString(tr)); } - } catch (Throwable tr) { - Log.e(TAG, Log.getStackTraceString(tr)); } } if (!Thread.currentThread().isInterrupted() && started) { diff --git a/core/src/play/java/de/danoeh/antennapod/core/CastCallbacks.java b/core/src/play/java/de/danoeh/antennapod/core/CastCallbacks.java new file mode 100644 index 000000000..770fee9b9 --- /dev/null +++ b/core/src/play/java/de/danoeh/antennapod/core/CastCallbacks.java @@ -0,0 +1,12 @@ +package de.danoeh.antennapod.core; + +import android.support.annotation.Nullable; +import android.support.v7.app.MediaRouteDialogFactory; + +/** + * Callbacks for Chromecast support on the core module + */ +public interface CastCallbacks { + + @Nullable MediaRouteDialogFactory getMediaRouterDialogFactory(); +} diff --git a/core/src/play/java/de/danoeh/antennapod/core/ClientConfig.java b/core/src/play/java/de/danoeh/antennapod/core/ClientConfig.java index 9bbccbb82..3dfd6ea65 100644 --- a/core/src/play/java/de/danoeh/antennapod/core/ClientConfig.java +++ b/core/src/play/java/de/danoeh/antennapod/core/ClientConfig.java @@ -31,6 +31,8 @@ public class ClientConfig { public static DBTasksCallbacks dbTasksCallbacks; + public static CastCallbacks castCallbacks; + private static boolean initialized = false; public static synchronized void initialize(Context context) { diff --git a/core/src/play/java/de/danoeh/antennapod/core/cast/CastManager.java b/core/src/play/java/de/danoeh/antennapod/core/cast/CastManager.java index 66b4558be..0674990f1 100644 --- a/core/src/play/java/de/danoeh/antennapod/core/cast/CastManager.java +++ b/core/src/play/java/de/danoeh/antennapod/core/cast/CastManager.java @@ -62,6 +62,7 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.TimeUnit; +import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.core.R; import static com.google.android.gms.cast.RemoteMediaPlayer.RESUME_STATE_PLAY; @@ -130,12 +131,12 @@ public class CastManager extends BaseCastManager implements OnFailedListener { public static synchronized CastManager init(Context context) { if (INSTANCE == null) { - //TODO also setup dialog factory if necessary CastConfiguration castConfiguration = new CastConfiguration.Builder(CAST_APP_ID) .enableDebug() .enableAutoReconnect() .enableWifiReconnection() .setLaunchOptions(true, Locale.getDefault()) + .setMediaRouteDialogFactory(ClientConfig.castCallbacks.getMediaRouterDialogFactory()) .build(); Log.d(TAG, "New instance of CastManager is created"); if (ConnectionResult.SUCCESS != GoogleApiAvailability.getInstance() |