Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:Failed to stop recording #163 #167

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ private const val RECORD_AUDIO_REQUEST_CODE = 1001
class AudioRecorder : PluginRegistry.RequestPermissionsResultListener {
private var permissions = arrayOf(Manifest.permission.RECORD_AUDIO)
private var useLegacyNormalization = false
private var mediaMetadataRetriever = MediaMetadataRetriever()
private var audioInfoArrayList = ArrayList<String>()

fun getDecibel(result: MethodChannel.Result, recorder: MediaRecorder?) {
if (useLegacyNormalization) {
Expand Down Expand Up @@ -72,6 +70,7 @@ class AudioRecorder : PluginRegistry.RequestPermissionsResultListener {
reset()
release()
}
val audioInfoArrayList = ArrayList<String>()
val duration = getDuration(path)
audioInfoArrayList.add(path)
audioInfoArrayList.add(duration)
Expand All @@ -82,13 +81,17 @@ class AudioRecorder : PluginRegistry.RequestPermissionsResultListener {
}

private fun getDuration(path: String): String {
mediaMetadataRetriever.setDataSource(path)
val duration = mediaMetadataRetriever.extractMetadata(METADATA_KEY_DURATION)
return duration ?: "-1"
}

fun releaseMetaDataRetriever(){
mediaMetadataRetriever.release()
val mediaMetadataRetriever = MediaMetadataRetriever()
try {
mediaMetadataRetriever.setDataSource(path)
val duration = mediaMetadataRetriever.extractMetadata(METADATA_KEY_DURATION)
return duration ?: "-1"
} catch (e: Exception) {
Log.e(LOG_TAG, "Failed to get recording duration")
} finally {
mediaMetadataRetriever.release()
}
return "-1"
}

fun startRecorder(result: MethodChannel.Result, recorder: MediaRecorder?, useLegacy: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class AudioWaveformsPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
audioRecorder.stopRecording(result, recorder, path!!)
recorder = null
}
Constants.releaseMetaDataRetriever -> audioRecorder.releaseMetaDataRetriever()
Constants.pauseRecording -> audioRecorder.pauseRecording(result, recorder)
Constants.resumeRecording -> audioRecorder.resumeRecording(result, recorder)
Constants.getDecibel -> audioRecorder.getDecibel(result, recorder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ object Constants {
const val onCurrentExtractedWaveformData = "onCurrentExtractedWaveformData"
const val waveformData = "waveformData"
const val useLegacyNormalization = "useLegacyNormalization"
const val releaseMetaDataRetriever = "releaseMetaDataRetriever"
}

enum class FinishMode(val value:Int) {
Expand Down
4 changes: 0 additions & 4 deletions lib/src/base/audio_waveforms_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ class AudioWaveformsInterface {
return hasPermission ?? false;
}

Future<void> releaseMetaDataRetriever() async {
await _methodChannel.invokeMethod(Constants.releaseMetaDataRetriever);
}

///platform call to prepare player
Future<bool> preparePlayer(String path, String key, [double? volume]) async {
var result = await _methodChannel.invokeMethod(Constants.preparePlayer, {
Expand Down
1 change: 0 additions & 1 deletion lib/src/base/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ class Constants {
static const String onCurrentExtractedWaveformData =
"onCurrentExtractedWaveformData";
static const String useLegacyNormalization = "useLegacyNormalization";
static const String releaseMetaDataRetriever = "releaseMetaDataRetriever";
}
7 changes: 0 additions & 7 deletions lib/src/controllers/recorder_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -410,18 +410,11 @@ class RecorderController extends ChangeNotifier {
_recorderState = state;
}

/// This function is to release resources taken by android native
/// MetaDataRetriever.
void _release() {
AudioWaveformsInterface.instance.releaseMetaDataRetriever();
}

/// Releases any resources taken by this recorder and with this
/// controller is also disposed.
@override
void dispose() async {
if (recorderState != RecorderState.stopped) await stop();
if (Platform.isAndroid) _release();
_currentScrolledDuration.dispose();
_currentDurationController.close();
_recorderStateController.close();
Expand Down