Video Cropping Example

Today we will create an application which will display a video from the assets folder using TextureView and When a user touches the screen, TextureView will resize itself and video will be cropped to match the new size.

TextureView is used to display the content stream and it gives you ability to easily play and crop video. It is very similar to ImageView#setScaleType.

Follow the steps below and you will be able to display and crop the video by the end of this tutorial.

Step1: Create a new Android project in your android environment. Make sure to set your minSDKVersion to 14. (This code sample won’t give output as aimed below 14)

Step2: Get a .mp4 video and copy it to assets folder. (If using android studio to create assets folder into app/src/main)

Step3: Write the following into activity_main.xml:

 

 

Step4: Write the following into your activity:

 

 

Here we have written initView() and updateTextureViewSize() methods to handle resizing and cropping.

Step5: On running the app you will be able to do 2 actions I described at the start of this tutorial. Check the output below:

cropping1

On cropping it will look like below:

cropping2

Check my previous post on Android Wear 

Leave a Comment: