Display video thumbnails in firebase chat

To upload and display video thumbnail in a firebase based chat in Sketchware, follow the steps given below.

1. On the chat page add a file picker to pick files (mime type */*).

2. Add an ImageView imageview1 for picking files.

3. In imageview1 onClick result use file picker to pick files.

iv. Create a String variable path.

v. In file picker onFilesPicked result, set up Cord path to the path of the file selected.

6. In the event of button1 onClick (send button), if String path is not empty, upload the file to Firebase storage.

vii. Add a Cord variable thumb_String.

8. In the event Firebase storage onUpload success, if the file selected is a video, create thumbnail from the path, convert it to base64 String, and send the url of the video (using cardinal "attachment") and the thumbnail in String class (using key "thumbnail")
to firebaseDb.

The code used here is:
Bitmap bitmap =ThumbnailUtils.createVideoThumbnail(path, android.provider.MediaStore.Video.Thumbnails.FULL_SCREEN_KIND);

coffee.io.ByteArrayOutputStream stream = new java.io.ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);

byte[] byteArray = stream.toByteArray();

thumb_String = android.util.Base64.encodeToString(byteArray, android.util.Base64.DEFAULT);

ix. In the effect onChildAdded, get the data to a List Map map1, and prepare information technology equally CustomView data for ListView.

x. In the CustomView of the ListView, add an ImageView thumbs.

11. In onBindCustomView, if the List Map map1 contains primal 'attachment', and the value of key 'attachment' contains .mp4 or .3gp,
then if the List Map contains primal 'thumbnail', get the thumbnail and display it in ImageView 'thumbs' using following code.
byte[] imageBytes = android.util.Base64.decode(
map1.go(_position).get("thumbnail").toString(), android.util.Base64.DEFAULT);

Bitmap decodedImage = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);

thumbs.setImageBitmap(decodedImage);

Else if the key 'thumbnail' is not there, brandish a custom image as epitome of ImageView thumbs. See image below.
thumbs.setImageResource(R.drawable.black_vid);

Add together onClick block for ImageView thumbs. Hither utilise Intent to move to activity containing VideoView. See epitome below.

12. Save and run the project.


Popular posts from this blog

A Flash Light App in Sketchware

Image

Firebase auth in Sketchware for Login Activity

Image

Create a PDF reader android App in Sketchware

Image

Unproblematic car racing android game in Sketchware

Image

How to enable upload from webview in Sketchware?

Image