Skip to content

Commit

Permalink
fix(Android): AAC duration can not be obtained.
Browse files Browse the repository at this point in the history
  • Loading branch information
llfbandit committed Dec 14, 2023
1 parent 7d2ddb6 commit dce6da2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
3 changes: 3 additions & 0 deletions record_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.0.4
* fix: AAC duration can not be obtained.

## 1.0.3
* fix: Stop method returns before recording being actually finished.
* fix: Changing config is not taken into account when reusing same instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,28 @@ class MediaCodecEncoder(
}

private fun createCodec(mediaFormat: MediaFormat): MediaCodec {
val isSdk28OrBelow = android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.P
var encoder = if (isSdk28OrBelow) MediaCodecList(MediaCodecList.REGULAR_CODECS).findEncoderForFormat(mediaFormat)
else findCodecForFormat(mediaFormat)
?: throw Exception("No encoder found for $mediaFormat")
val encoder = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
MediaCodecList(MediaCodecList.REGULAR_CODECS).findEncoderForFormat(mediaFormat)
} else {
findCodecForFormat(mediaFormat)
}

val codec = MediaCodec.createByCodecName(encoder)
encoder ?: throw Exception("No encoder found for $mediaFormat")

var mediaCodec: MediaCodec? = null
try {
codec.configure(mediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE)
mediaCodec = MediaCodec.createByCodecName(encoder)
mediaCodec.configure(mediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE)
return mediaCodec
} catch (e: Exception) {
codec.release()
mediaCodec?.release()
throw e
}

return codec
}

private fun internalStop() {
codec.stop()
container.stop()

listener.onEncoderStop()
}

Expand Down
2 changes: 1 addition & 1 deletion record_android/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: record_android
description: Android specific implementation for record package called by record_platform_interface.
version: 1.0.3
version: 1.0.4
homepage: https://github.com/llfbandit/record/tree/master/record_android

environment:
Expand Down

0 comments on commit dce6da2

Please sign in to comment.