From a77c77724b29332077ee933c040bcf4ac7c45504 Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Sun, 17 Apr 2016 02:39:45 -0400 Subject: [PATCH] switching between media player activities --- .../activity/AudioplayerActivity.java | 25 ++++++++++++++++ .../activity/CastplayerActivity.java | 29 ++++++++++++++++++- .../activity/VideoplayerActivity.java | 11 +++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java index bd8e43c4e..d64e19447 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -1,9 +1,11 @@ package de.danoeh.antennapod.activity; import android.content.Intent; +import android.os.Bundle; import android.text.TextUtils; import android.util.Log; +import de.danoeh.antennapod.core.cast.CastManager; import de.danoeh.antennapod.core.feed.MediaType; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.util.playback.ExternalMedia; @@ -14,6 +16,17 @@ import de.danoeh.antennapod.core.util.playback.ExternalMedia; public class AudioplayerActivity extends MediaplayerInfoActivity { public static final String TAG = "AudioPlayerActivity"; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (CastManager.getInstance().isConnected()) { + Intent intent = PlaybackService.getPlayerActivityIntent(this); + if (!intent.getComponent().getClassName().equals(AudioplayerActivity.class.getName())) { + startActivity(intent); + } + } + } + @Override protected void onResume() { super.onResume(); @@ -32,4 +45,16 @@ public class AudioplayerActivity extends MediaplayerInfoActivity { startService(launchIntent); } } + + @Override + protected void onReloadNotification(int notificationCode) { + if (notificationCode == PlaybackService.EXTRA_CODE_CAST) { + Log.d(TAG, "ReloadNotification received, switching to Castplayer now"); + finish(); + startActivity(new Intent(this, CastplayerActivity.class)); + + } else { + super.onReloadNotification(notificationCode); + } + } } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java index f15c96467..ac24e421b 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java @@ -1,10 +1,37 @@ package de.danoeh.antennapod.activity; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; + +import de.danoeh.antennapod.core.cast.CastManager; +import de.danoeh.antennapod.core.service.playback.PlaybackService; + /** - * Created by domingos on 4/16/16. + * Activity for controlling the remote playback on a Cast device. */ public class CastplayerActivity extends MediaplayerInfoActivity { public static final String TAG = "CastPlayerActivity"; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (!CastManager.getInstance().isConnected()) { + Intent intent = PlaybackService.getPlayerActivityIntent(this); + if (!intent.getComponent().getClassName().equals(CastplayerActivity.class.getName())) { + startActivity(intent); + } + } + } + @Override + protected void onReloadNotification(int notificationCode) { + if (notificationCode == PlaybackService.EXTRA_CODE_AUDIO) { + Log.d(TAG, "ReloadNotification received, switching to Audioplayer now"); + finish(); + startActivity(new Intent(this, AudioplayerActivity.class)); + } else { + super.onReloadNotification(notificationCode); + } + } } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java index 42c9edd99..8882e25e9 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java @@ -23,6 +23,7 @@ import java.lang.ref.WeakReference; import java.util.concurrent.atomic.AtomicBoolean; import de.danoeh.antennapod.R; +import de.danoeh.antennapod.core.cast.CastManager; import de.danoeh.antennapod.core.feed.MediaType; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.service.playback.PlayerStatus; @@ -64,6 +65,12 @@ public class VideoplayerActivity extends MediaplayerActivity { supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_BAR_OVERLAY); // has to be called before setting layout content super.onCreate(savedInstanceState); getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0x80000000)); + if (CastManager.getInstance().isConnected()) { + Intent intent = PlaybackService.getPlayerActivityIntent(this); + if (!intent.getComponent().getClassName().equals(VideoplayerActivity.class.getName())) { + startActivity(intent); + } + } } @Override @@ -257,6 +264,10 @@ public class VideoplayerActivity extends MediaplayerActivity { Log.d(TAG, "ReloadNotification received, switching to Audioplayer now"); finish(); startActivity(new Intent(this, AudioplayerActivity.class)); + } else if (notificationCode == PlaybackService.EXTRA_CODE_CAST) { + Log.d(TAG, "ReloadNotification received, switching to Castplayer now"); + finish(); + startActivity(new Intent(this, CastplayerActivity.class)); } }