Skip to content

Commit

Permalink
Workaround for a bug that crashed the app when atempting to initializ…
Browse files Browse the repository at this point in the history
…e the player

visualizer.
  • Loading branch information
synapticweb committed Feb 29, 2020
1 parent 9703ffd commit 320e451
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.widget.TextView;

import net.synapticweb.callrecorder.CrApp;
import net.synapticweb.callrecorder.CrLog;
import net.synapticweb.callrecorder.R;
import net.synapticweb.callrecorder.TemplateActivity;
import net.synapticweb.callrecorder.contactdetail.ContactDetailPresenter;
Expand Down Expand Up @@ -76,7 +77,14 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
visualizer.setColor(getResources().getColor(R.color.colorAccentLighter));
visualizer.setDensity(getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_PORTRAIT ? DENSITY_PORTRAIT : DENSITY_LANDSCAPE);
visualizer.setPlayer(AUDIO_SESSION_ID);
//crash report nr. 886:
try {
visualizer.setPlayer(AUDIO_SESSION_ID);
}
catch (Exception exc) {
CrLog.log(CrLog.ERROR, "Error initializing visualizer.");
visualizer = null;
}
audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

playPause = findViewById(R.id.test_player_play_pause);
Expand Down Expand Up @@ -165,10 +173,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
visualizer.setDensity(DENSITY_LANDSCAPE);
else
visualizer.setDensity(DENSITY_PORTRAIT);
if(visualizer != null) {
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
visualizer.setDensity(DENSITY_LANDSCAPE);
else
visualizer.setDensity(DENSITY_PORTRAIT);
}
}

@Override
Expand Down Expand Up @@ -222,7 +232,8 @@ protected void onDestroy() {
editor.remove(IS_PLAYING);
editor.remove(CURRENT_POS);
editor.apply();
visualizer.release();
if(visualizer != null)
visualizer.release();
if(audioManager != null)
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, phoneVolume, 0);
}
Expand Down

0 comments on commit 320e451

Please sign in to comment.