if (requestCode == SELECT_CODE && data != null) {
Uri uri = data.getData();
if (uri != null) {
nwretriver = new MediaMetadataRetriever();
try {
nwretriver.setDataSource(getApplicationContext(), uri);
} finally {
}
String duraiton
=nwretriver.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
assert duraiton != null;
int time = Integer.parseInt(duraiton);
int period = 1000000;
int len = time / period;
List<Bitmap> frames = new ArrayList<>();
for(int i = 0; i<len; i++){
Bitmap frame = nwretriver.getFrameAtTime(i *
period,MediaMetadataRetriever.OPTION_CLOSEST);
if (frame != null) {
frames.add(frame);
} else {
Log.e("Frame extraction", "Frame at time " + i * period + " is null");
}
}
Toast.makeText(this, ""+frames.isEmpty(), Toast.LENGTH_LONG).show();
try {
nwretriver.release();
} catch (IOException e) {
throw new RuntimeException(e);
}
for(Bitmap frame: frames) {
frames.add(resultBitmap);
}
try {
MediaItem mediaItem1 = MediaItem.fromUri(uri);
player.setMediaItem(mediaItem1);
player.prepare();
player.play();
} catch (Exception e) {
Log.e("ExoPlayer", "Error playing video:", e);
}
}
}
}
I am having problems witht the getFrameAtTime ı tried to upload a video from the gallery extract the frames out of it put the frames to a arraylist then display the video but when ı apply a toast message after the frame exctraction and it says frame arraylist is empty how can ı make this works does anyone know ?