Get frames in a video in Sketchware
This sample shows how to get the frames in a video and display it in a GridView in Sketchware.
1. Create a new project in Sketchware.
2. In main.xml add a LinearLayout linear1. Below this add a ListView listview1.
3. Create a more block custom.xml. Add an ImageView imageview1 in it.
4. For listview1, select custom.xml as Custom View. Set height of linear1 to match_parent.
5. In View main.xml add a Floating Action Button _fab.
6. Add a FilePicker Component fp: video/*, and a Camera component cam.
7. Create a More block extra and declare GridView gridview1 and a list of bitmap images frames using following codes:
} GridView gridview1;
ArrayList<Bitmap> frames; {
8. Create a String path, a Map variable map, a List String list and a List Map imagelist.
9. In onCreate event put following codes.
gridview1 = new GridView(this);
gridview1.setLayoutParams(new GridView.LayoutParams(GridView.LayoutParams.MATCH_PARENT, GridView.LayoutParams.MATCH_PARENT));
gridview1.setBackgroundColor(Color.WHITE);
gridview1.setNumColumns(2); gridview1.setColumnWidth(GridView.AUTO_FIT);
gridview1.setVerticalSpacing(16); gridview1.setHorizontalSpacing(2); gridview1.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
linear1.removeAllViews();
linear1.addView(gridview1);
gridview1.setAdapter(new Listview1Adapter(imagelist));
((BaseAdapter)gridview1.getAdapter()).notifyDataSetChanged();
10. In fab onClick event, use File Picker fp pick files block.
11. In File Picker onFilesPicked event, use following codes:
path = _filePath.get((int)(0));
java.util.concurrent.ExecutorService executor = java.util.concurrent.Executors.newSingleThreadExecutor();
final Handler handler = new Handler(Looper.getMainLooper());
executor.execute(new Runnable() {
@Override
public void run() {
//Background work here
imagelist.clear();
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(getApplicationContext(), FileProvider.getUriForFile(MainActivity.this, getApplicationContext().getPackageName() + ".provider", new java.io.File(path)));
String duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
int millSecond = Integer.parseInt(duration);
int duration_second = millSecond / 1000;
frames = new ArrayList<>();
int numeroFrameCaptured = (int)(duration_second*2);
for (int i = 0; i < numeroFrameCaptured; i++){
frames.add(retriever.getFrameAtTime((duration_second*1000000*i)/numeroFrameCaptured));
map = new HashMap<>();
map.put("frame", "new");
imagelist.add(map);
}
handler.post(new Runnable() {
@Override
public void run() {
//UI Thread work here
gridview1.setAdapter(new Listview1Adapter(imagelist));
((BaseAdapter)gridview1.getAdapter()).notifyDataSetChanged();
} });
} });
The code in blue above is for doing the task of retrieving frames in background thread.
12. In ListView onBindCustomView event, display bitmap from bitmap list frames, in imageview1.
imageview1.setImageBitmap(frames.get(_position));
13. Run the project.
Watch video below
thanks brother
ReplyDeleteWhen you are eager to hire one from our agency then give us the chance to provide the most elite independent models and highest rated Delhi escort for your best moments in life when visiting Delhi
ReplyDeleteI don't edit videos much. Time consuming. However this is a useful tutorial.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteWow this is a very cool tutorial. Pls sir can you help us make a tutorial on how to enable sav webpage in webview ( like save for offline pages) pls.
ReplyDeleteI have read Your Article and Learn a lot from it. I can Imagine the time it took to get all this expertise exposed . You can also look here to see where to easily get a HIGH QUALITY BANK STATEMENTS FOR MORTGAGE I've bookmark your site and furthermore include RSS. keep us refreshed all the time.
ReplyDeleteUse a good camera, do a pre-record sound test, and learn some simple editing skills if you can’t afford to higher a video editor. albanische hits 2022
ReplyDeleteRead file path is not working! How to do?
ReplyDeletePlease help me.
ReplyDeleteAfter I run to apk and I recheck source codes ,real Admob units are right units.
When I export to .aab and I recheck the source codes, real Admob units change to test units automatically .
How to fix this error?
Thank you.
melodyloops.com doubles as a fantastic resource for anyone who wants to download free music. The site is primarily aimed at new bands; you're not going to find tracks from the current chart-toppers.
ReplyDeleteI want to know how to create an appwidget with sketchware. Help me please
ReplyDelete