From 31c4502c2b0b012a3aa8d6a06b788c937e44e6f1 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 24 Sep 2014 14:59:44 -0700 Subject: #287 Try to recreate mediaPlayer, apply EQ, then resume on failure to initialize EQ --- .../daneren2005/dsub/service/DownloadService.java | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/github') diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index 798b4541..dc256c5b 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -1009,6 +1009,10 @@ public class DownloadService extends Service { } mediaPlayer.setOnErrorListener(null); mediaPlayer.setOnCompletionListener(null); + if(Build.VERSION.SKD_INT >= Build.VERSION_CODES.JELLY_BEAN && nextSetup) { + mediaPlayer.setNextMediaPlayer(null); + nextSetup = false; + } mediaPlayer.reset(); subtractPosition = 0; } catch (Exception x) { @@ -1198,7 +1202,26 @@ public class DownloadService extends Service { } public EqualizerController getEqualizerController() { - return effectsController.getEqualizerController(); + try { + return effectsController.getEqualizerController(); + } catch(Exception e) { + // If we failed, we are going to try to reinitialize the MediaPlayer + boolean playing = playerState == STARTED; + int pos = getPlayerPosition(); + reset(); + + EqualizerController controller; + try { + controller = effectsController.getEqualizerController(); + } catch(Exception e) { + // Don't try again, just resetup media player + } + + // Restart from same position and state we left off in + play(getCurrentPlayingIndex(), playing, pos); + + return controller; + } } public MediaRouteSelector getRemoteSelector() { -- cgit v1.2.3