From ae83b1c8f13a108a2dcde8a9cdfe8badb97e0b02 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 24 May 2017 10:48:22 +0300 Subject: [PATCH 1/3] Fix #3710 --- .../src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index d6379b9262..372e783257 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -1116,6 +1116,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } public void recordAudio(double lat, double lon, final MapActivity mapActivity) { + AudioManager am = (AudioManager)app.getSystemService(Context.AUDIO_SERVICE); + am.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_MUTE, 0); if (ActivityCompat.checkSelfPermission(mapActivity, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) { initRecMenu(AVActionType.REC_AUDIO, lat, lon); @@ -1538,6 +1540,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { closeRecordingMenu(); } } + AudioManager am = (AudioManager)app.getSystemService(Context.AUDIO_SERVICE); + am.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_UNMUTE, 0); } private LatLon getNextRecordingLocation() { From d7d699e32d3084e75a8d19148191f837252be081 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 24 May 2017 15:02:37 +0300 Subject: [PATCH 2/3] Fix #3710 --- .../audionotes/AudioVideoNotesPlugin.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index 372e783257..e8c8e52743 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -1117,9 +1117,18 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { public void recordAudio(double lat, double lon, final MapActivity mapActivity) { AudioManager am = (AudioManager)app.getSystemService(Context.AUDIO_SERVICE); - am.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_MUTE, 0); + int voiceGuidanceOutput = app.getSettings().AUDIO_STREAM_GUIDANCE.get(); if (ActivityCompat.checkSelfPermission(mapActivity, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ + am.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_MUTE, 0); + if (voiceGuidanceOutput != AudioManager.STREAM_MUSIC) + am.adjustStreamVolume(voiceGuidanceOutput, AudioManager.ADJUST_MUTE, 0); + } else { + am.setStreamMute(AudioManager.STREAM_MUSIC, true); + if (voiceGuidanceOutput != AudioManager.STREAM_MUSIC) + am.setStreamMute(voiceGuidanceOutput, true); + } initRecMenu(AVActionType.REC_AUDIO, lat, lon); MediaRecorder mr = new MediaRecorder(); final File f = getBaseFileName(lat, lon, app, THREEGP_EXTENSION); @@ -1530,6 +1539,19 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { recordControl.setExplicitlyVisible(false); mapActivity.getMapLayers().getMapInfoLayer().recreateControls(); } + if (currentRecording.type == AVActionType.REC_AUDIO) { + AudioManager am = (AudioManager) app.getSystemService(Context.AUDIO_SERVICE); + int voiceGuidanceOutput = app.getSettings().AUDIO_STREAM_GUIDANCE.get(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ + am.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_UNMUTE, 0); + if (voiceGuidanceOutput != AudioManager.STREAM_MUSIC) + am.adjustStreamVolume(voiceGuidanceOutput, AudioManager.ADJUST_UNMUTE, 0); + } else { + am.setStreamMute(AudioManager.STREAM_MUSIC, false); + if (voiceGuidanceOutput != AudioManager.STREAM_MUSIC) + am.setStreamMute(voiceGuidanceOutput, false); + } + } stopCameraRecording(false); if (recordControl != null) { setRecordListener(recordControl, mapActivity); @@ -1540,8 +1562,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { closeRecordingMenu(); } } - AudioManager am = (AudioManager)app.getSystemService(Context.AUDIO_SERVICE); - am.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_UNMUTE, 0); } private LatLon getNextRecordingLocation() { From 2ec8826fdb8b221f9810cb711edf9c6e5297cf03 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 24 May 2017 16:58:49 +0300 Subject: [PATCH 3/3] Fix #3710 --- .../audionotes/AudioVideoNotesPlugin.java | 53 +++++++++++-------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index e8c8e52743..507100f0ac 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -1116,19 +1116,9 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } public void recordAudio(double lat, double lon, final MapActivity mapActivity) { - AudioManager am = (AudioManager)app.getSystemService(Context.AUDIO_SERVICE); - int voiceGuidanceOutput = app.getSettings().AUDIO_STREAM_GUIDANCE.get(); if (ActivityCompat.checkSelfPermission(mapActivity, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ - am.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_MUTE, 0); - if (voiceGuidanceOutput != AudioManager.STREAM_MUSIC) - am.adjustStreamVolume(voiceGuidanceOutput, AudioManager.ADJUST_MUTE, 0); - } else { - am.setStreamMute(AudioManager.STREAM_MUSIC, true); - if (voiceGuidanceOutput != AudioManager.STREAM_MUSIC) - am.setStreamMute(voiceGuidanceOutput, true); - } + muteStreamMusicAndOutputGuidance(); initRecMenu(AVActionType.REC_AUDIO, lat, lon); MediaRecorder mr = new MediaRecorder(); final File f = getBaseFileName(lat, lon, app, THREEGP_EXTENSION); @@ -1140,6 +1130,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { try { runMediaRecorder(mapActivity, mr, f); } catch (Exception e) { + unmuteStreamMusicAndOutputGuidance(); log.error("Error starting audio recorder ", e); Toast.makeText(app, app.getString(R.string.recording_error) + " : " + e.getMessage(), Toast.LENGTH_LONG).show(); @@ -1153,6 +1144,34 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } } + private void muteStreamMusicAndOutputGuidance() { + AudioManager am = (AudioManager)app.getSystemService(Context.AUDIO_SERVICE); + int voiceGuidanceOutput = app.getSettings().AUDIO_STREAM_GUIDANCE.get(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ + am.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_MUTE, 0); + if (voiceGuidanceOutput != AudioManager.STREAM_MUSIC) + am.adjustStreamVolume(voiceGuidanceOutput, AudioManager.ADJUST_MUTE, 0); + } else { + am.setStreamMute(AudioManager.STREAM_MUSIC, true); + if (voiceGuidanceOutput != AudioManager.STREAM_MUSIC) + am.setStreamMute(voiceGuidanceOutput, true); + } + } + + private void unmuteStreamMusicAndOutputGuidance() { + AudioManager am = (AudioManager) app.getSystemService(Context.AUDIO_SERVICE); + int voiceGuidanceOutput = app.getSettings().AUDIO_STREAM_GUIDANCE.get(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ + am.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_UNMUTE, 0); + if (voiceGuidanceOutput != AudioManager.STREAM_MUSIC) + am.adjustStreamVolume(voiceGuidanceOutput, AudioManager.ADJUST_UNMUTE, 0); + } else { + am.setStreamMute(AudioManager.STREAM_MUSIC, false); + if (voiceGuidanceOutput != AudioManager.STREAM_MUSIC) + am.setStreamMute(voiceGuidanceOutput, false); + } + } + public void takePhoto(final double lat, final double lon, final MapActivity mapActivity, final boolean forceInternal) { if (ActivityCompat.checkSelfPermission(mapActivity, Manifest.permission.CAMERA) @@ -1540,17 +1559,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { mapActivity.getMapLayers().getMapInfoLayer().recreateControls(); } if (currentRecording.type == AVActionType.REC_AUDIO) { - AudioManager am = (AudioManager) app.getSystemService(Context.AUDIO_SERVICE); - int voiceGuidanceOutput = app.getSettings().AUDIO_STREAM_GUIDANCE.get(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ - am.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_UNMUTE, 0); - if (voiceGuidanceOutput != AudioManager.STREAM_MUSIC) - am.adjustStreamVolume(voiceGuidanceOutput, AudioManager.ADJUST_UNMUTE, 0); - } else { - am.setStreamMute(AudioManager.STREAM_MUSIC, false); - if (voiceGuidanceOutput != AudioManager.STREAM_MUSIC) - am.setStreamMute(voiceGuidanceOutput, false); - } + unmuteStreamMusicAndOutputGuidance(); } stopCameraRecording(false); if (recordControl != null) {