I only need to record a video in Android device with some specifications. However, i'm really disappointed because everything that i try some weird system issue appeared and i go back to beginning. So i need a more experienced developer to guide me.
Specifications
I need the following:
- Basic video interface (user seeing what is recorded).
- Video time cannot exceed 20s (Max:20s after that recording stops).
- Only Landscape mode is enable. Block user somehow so he can't record in portrait mode.
- Configuration button should be enabled. Setting button that allow user to change video resolution
- Front and back camera button should be enabled.
- As many as possible, devices must be compatible with my application.
What i already tried
The below code was my first try. I was happy because it works, but it can't block portrait recording videos. So i read from some other question here that i should use camera2 android API for that.
Uri videoUri = FileProvider.getUriForFile(this, "com.my.myapplication.fileprovider", videofile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, VIDEO_DURATION);
intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); // this won't work
intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_LOCKED); // neither this
startActivityForResult(intent, REQUEST_VIDEO_CAPTURE);
So i got my 2nd try. I changed my code to this camera2 API just to know that most of Samsung devices don't support it. Here is my source to that information. Of course, i just discovered that after some weird mistakes appeared in my code.
I followed this code: androidwave code
And this code: lytcom/Camera2Kit
And this code: googlearchive/android-Camera2Video
Which are pretty most the same.
Since devices aren't compatible with camera2 API, they won't return good camera video size. I know that my device has a 1920x1080 resolution camera but the return from system method is
E/Camera2VideoFragment: Width: 1440 Height 1080
E/Camera2VideoFragment: Width: 1088 Height 1088
E/Camera2VideoFragment: Width: 1472 Height 720
E/Camera2VideoFragment: Width: 1280 Height 720
E/Camera2VideoFragment: Width: 1056 Height 864
E/Camera2VideoFragment: Width: 960 Height 720
My third try. I was using the library JeroenMols/LandscapeVideoCamera that gives me exactly what i need, including this beautiful picture that shows user to rotate device before recording. However this library won't work for API>22, source.
Currently
NOW, i don't know what to do. Whatever i tried didn't work. And most answer around just used those libraries. So can please somebody lend me a hand? Please Java language. I can't handle Kotlin.