diff options
author | Domingos Lopes <domingos86lopes+github@gmail.com> | 2016-03-26 12:51:47 -0400 |
---|---|---|
committer | Domingos Lopes <domingos86lopes+github@gmail.com> | 2016-04-23 21:39:54 -0400 |
commit | 40fc7b4816908e7bc85fd2e1be1602e3dafd76b2 (patch) | |
tree | 720983cd03f81ebe43387a7eb901c5048a663613 /core/src/main/java | |
parent | 1088fae74506bbd9620fc0d3659976afbae6fcb2 (diff) | |
download | AntennaPod-40fc7b4816908e7bc85fd2e1be1602e3dafd76b2.zip |
initialize mediaplayer according to local or remote device
Diffstat (limited to 'core/src/main/java')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java | 45 |
1 files changed, 26 insertions, 19 deletions
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 d85bcb820..80007b862 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 @@ -260,10 +260,6 @@ public class PlaybackService extends Service implements SharedPreferences.OnShar Log.d(TAG, "Service created."); isRunning = true; - CastManager castMgr = CastManager.getInstance(); - castMgr.addCastConsumer(castConsumer); - isCasting = castMgr.isConnected(); - registerReceiver(headsetDisconnected, new IntentFilter( Intent.ACTION_HEADSET_PLUG)); registerReceiver(shutdownReceiver, new IntentFilter( @@ -281,7 +277,14 @@ public class PlaybackService extends Service implements SharedPreferences.OnShar registerReceiver(pauseResumeCurrentEpisodeReceiver, new IntentFilter( ACTION_RESUME_PLAY_CURRENT_EPISODE)); taskManager = new PlaybackServiceTaskManager(this, taskManagerCallback); - mediaPlayer = new LocalPSMP(this, mediaPlayerCallback); + CastManager castMgr = CastManager.getInstance(); + castMgr.addCastConsumer(castConsumer); + isCasting = castMgr.isConnected(); + if (isCasting) { + onCastAppConnected(true); + } else { + mediaPlayer = new LocalPSMP(this, mediaPlayerCallback); + } ComponentName eventReceiver = new ComponentName(getApplicationContext(), MediaButtonReceiver.class); @@ -1561,20 +1564,7 @@ public class PlaybackService extends Service implements SharedPreferences.OnShar private CastConsumer castConsumer = new CastConsumerImpl() { @Override public void onApplicationConnected(ApplicationMetadata appMetadata, String sessionId, boolean wasLaunched) { - Log.d(TAG, "A cast device application was connected"); - isCasting = true; - if (mediaPlayer != null) { - PlaybackServiceMediaPlayer.PSMPInfo info = mediaPlayer.getPSMPInfo(); - if (info.playerStatus == PlayerStatus.PLAYING) { - // could be pause, but this way we make sure the new player will get the correct position, since pause runs asynchronously - saveCurrentPosition(false, 0); - } - } - switchMediaPlayer(new RemotePSMP(PlaybackService.this, mediaPlayerCallback), - (mediaPlayer != null) ? mediaPlayer.getPSMPInfo() : - new PlaybackServiceMediaPlayer.PSMPInfo(PlayerStatus.STOPPED, null)); - sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, EXTRA_CODE_CAST); - registerWifiBroadcastReceiver(); + PlaybackService.this.onCastAppConnected(wasLaunched); } @Override @@ -1620,6 +1610,23 @@ public class PlaybackService extends Service implements SharedPreferences.OnShar } }; + private void onCastAppConnected(boolean wasLaunched) { + Log.d(TAG, "A cast device application was connected"); + isCasting = true; + if (mediaPlayer != null) { + PlaybackServiceMediaPlayer.PSMPInfo info = mediaPlayer.getPSMPInfo(); + if (info.playerStatus == PlayerStatus.PLAYING) { + // could be pause, but this way we make sure the new player will get the correct position, since pause runs asynchronously + saveCurrentPosition(false, 0); + } + } + switchMediaPlayer(new RemotePSMP(PlaybackService.this, mediaPlayerCallback), + (mediaPlayer != null) ? mediaPlayer.getPSMPInfo() : + new PlaybackServiceMediaPlayer.PSMPInfo(PlayerStatus.STOPPED, null)); + sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, EXTRA_CODE_CAST); + registerWifiBroadcastReceiver(); + } + private void switchMediaPlayer(@NonNull PlaybackServiceMediaPlayer newPlayer, @NonNull PlaybackServiceMediaPlayer.PSMPInfo info) { if (mediaPlayer != null) { |