Skip to content

Commit

Permalink
fix(android): record not working when starting from an Android Foregr…
Browse files Browse the repository at this point in the history
…oundService
  • Loading branch information
llfbandit authored Oct 9, 2024
2 parents b38bf12 + 0605e85 commit cc8893b
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ package com.llfbandit.record.record.stream
import android.app.Activity
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.EventChannel.EventSink
import android.os.Handler
import android.os.Looper

class RecorderRecordStreamHandler : EventChannel.StreamHandler {
// Event producer
private var eventSink: EventSink? = null
private var activity: Activity? = null

private val uiThreadHandler = Handler(Looper.getMainLooper())

override fun onListen(arguments: Any?, events: EventSink?) {
this.eventSink = events
}
Expand All @@ -18,9 +22,9 @@ class RecorderRecordStreamHandler : EventChannel.StreamHandler {
}

fun sendRecordChunkEvent(buffer: ByteArray) {
activity?.runOnUiThread {
uiThreadHandler.post(Runnable {
eventSink?.success(buffer)
}
})
}

fun setActivity(activity: Activity?) {
Expand Down

0 comments on commit cc8893b

Please sign in to comment.