-1

I want to create an app that is playing a live video . Have to capture the current frame while clicking the button. Thanks,

Priya
  • 177
  • 1
  • 2
  • 10

1 Answers1

0

You can get frame using MediaMetadataRetriever

private fun getVideoFrame() {
    val retriever = MediaMetadataRetriever()
    retriever.setDataSource(VIDEO_PATH)
    val bitmap = retriever.getFrameAtTime(yourTime, MediaMetadataRetriever.OPTION_CLOSEST)
}
Akshay Raiyani
  • 1,243
  • 9
  • 21
  • Thanks for your time. When I click the button the app will be crashed and the error is the following... java.lang.IllegalArgumentException at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:76) at qc.yotm.mes.com.yo_qc.MainActivity$3.onClick(MainActivity.java:306) at android.view.View.performClick(View.java:6608) at android.view.View.performClickInternal(View.java:6585) at android.view.View.access$3100(View.java:785) – Priya Oct 09 '19 at 06:57
  • It means your the path is invalid. make sure you have the VIDEO_PATH present correctly – King of Masses Oct 09 '19 at 07:02
  • The video is playing – Priya Oct 09 '19 at 07:03
  • I assume your streaming the video from url / uri not from the local path. So in your case use this setDataSource (Context context, Uri uri) – King of Masses Oct 09 '19 at 07:03
  • Yes, it is an RTSP link. – Priya Oct 09 '19 at 07:05
  • I have tried that too... It shows the following error. E/AndroidRuntime: FATAL EXCEPTION: main Process: qc.yotm.mes.com.yo_qc, PID: 2128 java.lang.IllegalArgumentException at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:172) at qc.yotm.mes.com.yo_qc.MainActivity$3.onClick(MainActivity.java:307) at android.view.View.performClick(View.java:6608) at android.view.View.performClickInternal(View.java:6585) at android.view.View.access$3100(View.java:785) – Priya Oct 09 '19 at 07:09
  • It seams your url might be expecting some additional params as well (like headers) etc. So you need to check for that method in setDataSource in MediaMetadataRetriever documentation – King of Masses Oct 09 '19 at 07:11
  • My Code is MediaMetadataRetriever retriever = new MediaMetadataRetriever(); Uri uri = Uri.parse(liveVideoPath); retriever.setDataSource(getApplicationContext(),uri); Bitmap bitmap = retriever.getFrameAtTime(60000000, MediaMetadataRetriever.OPTION_CLOSEST); imageViewNew.setVisibility(View.VISIBLE); imageViewNew.setImageBitmap(bitmap); – Priya Oct 09 '19 at 07:11
  • check my old answer here https://stackoverflow.com/a/46483591/3983054 – King of Masses Oct 09 '19 at 07:13
  • did your liveVideoPath url is playing directly in your media player ? else your adding any extra parameters to play it ? – King of Masses Oct 09 '19 at 07:14
  • mediaPlayer.setDataSource(liveVideoPath); – Priya Oct 09 '19 at 07:16
  • still the same issue ? I have updated my answer with few more points – King of Masses Oct 09 '19 at 07:29
  • Yes, still the problem occurs. – Priya Oct 09 '19 at 07:33