Skip to content

Commit

Permalink
Merge pull request #275 from 100mslive/feature/frame-capture
Browse files Browse the repository at this point in the history
added extension function for onFrame
  • Loading branch information
PratimMallick authored Aug 12, 2022
2 parents 9409b50 + 12e0f79 commit 1396ead
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,15 @@ class ActiveSpeakerFragment : VideoGridBaseFragment() {
}
contextSafe { context, activity -> mediaPlayerManager.startPlay(R.raw.camera_shut, context )}
surfaceView?.vibrateStrong()
surfaceView?.addFrameListener(object : EglRenderer.FrameListener{
override fun onFrame(bitmap: Bitmap?) {

//this is returning on the render thread
contextSafe { context, activity ->
//stores the bitmap in local cache thus avoiding any permission
val uri = bitmap?.saveCaptureToLocalCache(context)
//the uri is used to open share intent
uri?.let { activity.openShareIntent(it) }
}

//can't call on render thread this is important and just capture a single frame
activity?.runOnUiThread { surfaceView?.removeFrameListener(this) }
surfaceView?.onBitMap(onBitmap = { bitmap ->
contextSafe { context, activity ->
//stores the bitmap in local cache thus avoiding any permission
val uri = bitmap?.saveCaptureToLocalCache(context)
//the uri is used to open share intent
uri?.let { activity.openShareIntent(it) }
}
}, 1.0f)
})
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,15 @@ abstract class VideoGridBaseFragment : Fragment() {

contextSafe { context, activity -> mediaPlayerManager.startPlay(R.raw.camera_shut, context )}
surfaceView?.vibrateStrong()
surfaceView?.addFrameListener(object : EglRenderer.FrameListener{
override fun onFrame(bitmap: Bitmap?) {

//this is returning on the render thread
contextSafe { context, activity ->
//stores the bitmap in local cache thus avoiding any permission
val uri = bitmap?.saveCaptureToLocalCache(context)
//the uri is used to open share intent
uri?.let { activity.openShareIntent(it) }
}

//can't call on render thread this is important and just capture a single frame
activity?.runOnUiThread { surfaceView?.removeFrameListener(this) }
surfaceView?.onBitMap(onBitmap = { bitmap ->
contextSafe { context, activity ->
//stores the bitmap in local cache thus avoiding any permission
val uri = bitmap?.saveCaptureToLocalCache(context)
//the uri is used to open share intent
uri?.let { activity.openShareIntent(it) }
}
}, 1.0f)
})
}

protected fun bindVideo(binding: VideoCardBinding, item: MeetingTrack) {
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/live/hms/app2/util/ViewExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.os.Looper
import android.view.HapticFeedbackConstants
import android.view.View
import android.view.accessibility.AccessibilityManager
import androidx.core.content.FileProvider
import live.hms.app2.helpers.OnSingleClickListener
import live.hms.video.media.tracks.HMSVideoTrack
import org.webrtc.EglRenderer
import org.webrtc.SurfaceViewRenderer
import java.io.File
import java.io.FileOutputStream
import java.util.logging.Handler


fun View.setOnSingleClickListener(l: View.OnClickListener) {
Expand Down Expand Up @@ -109,4 +113,14 @@ fun Context.showTileListDialog(

builder.show()

}

fun SurfaceViewRenderer.onBitMap(onBitmap: (Bitmap?) -> Unit, scale : Float = 1.0f) {
kotlin.runCatching { }
this.addFrameListener(object : EglRenderer.FrameListener{
override fun onFrame(bitmap: Bitmap?) {
onBitmap.invoke(bitmap)
android.os.Handler(Looper.getMainLooper()).post { removeFrameListener(this) }
}
}, scale)
}

0 comments on commit 1396ead

Please sign in to comment.