I'm working on an app which records video. It's mostly complete but i'm having a strange issue with an older Samsung Galaxy S1 (australian model) running 2.3.3 (API 10).
When I try setting orientation via mMediaRecorder.setOrientationHint(90);
it throws an exception :
05-28 10:46:53.628: E/AndroidRuntime(6373): java.lang.RuntimeException: setParameter failed.
along with :
05-28 10:46:53.593: E/MediaRecorder(6373): setParameters(video-param-rotation-angle-degrees=90) failed: -2147483648
What's strange is other devices running 3.2.2 (API 10) work perfectly it is only this Samsung galaxy s1 which appears to have a bastardised custom OS which is not supporting setOrientation() as expected.
I'm currently using a try {} catch() {}
around setOrientation()
. Its not an elegant way to deal with this right? Is it better to preemptively check if setOrientation()
is supported by the device THEN try setting? I can't find any way of checking for this support.
I've checked (http://developer.android.com/reference/android/media/MediaRecorder.html) and can't find help apart from API level 9, which I'm already using. ie, only attempt set orientation if API level 9 or greater
Here is entire exception:
05-28 10:46:53.593: E/MediaRecorder(6373): setParameters(video-param-rotation-angle-degrees=90) failed: -2147483648
05-28 10:46:53.593: W/dalvikvm(6373): threadid=1: thread exiting with uncaught exception (group=0x40015578)
05-28 10:46:53.628: E/AndroidRuntime(6373): FATAL EXCEPTION: main
05-28 10:46:53.628: E/AndroidRuntime(6373): java.lang.RuntimeException: setParameter failed.
05-28 10:46:53.628: E/AndroidRuntime(6373): at android.media.MediaRecorder.setParameter(Native Method)
05-28 10:46:53.628: E/AndroidRuntime(6373): at android.media.MediaRecorder.setOrientationHint(MediaRecorder.java:341)
05-28 10:46:53.628: E/AndroidRuntime(6373): at com.on3x.emergency.Recorder.prepareVideoRecorder(Recorder.java:223)
05-28 10:46:53.628: E/AndroidRuntime(6373): at com.on3x.emergency.Recorder.startRecording(Recorder.java:104)
05-28 10:46:53.628: E/AndroidRuntime(6373): at com.on3x.emergency.GUI.RecordActivity$1.onClick(RecordActivity.java:111)
05-28 10:46:53.628: E/AndroidRuntime(6373): at android.view.View.performClick(View.java:2538)
05-28 10:46:53.628: E/AndroidRuntime(6373): at android.view.View$PerformClick.run(View.java:9152)
05-28 10:46:53.628: E/AndroidRuntime(6373): at android.os.Handler.handleCallback(Handler.java:587)
05-28 10:46:53.628: E/AndroidRuntime(6373): at android.os.Handler.dispatchMessage(Handler.java:92)
05-28 10:46:53.628: E/AndroidRuntime(6373): at android.os.Looper.loop(Looper.java:123)
05-28 10:46:53.628: E/AndroidRuntime(6373): at android.app.ActivityThread.main(ActivityThread.java:3687)
05-28 10:46:53.628: E/AndroidRuntime(6373): at java.lang.reflect.Method.invokeNative(Native Method)
05-28 10:46:53.628: E/AndroidRuntime(6373): at java.lang.reflect.Method.invoke(Method.java:507)
05-28 10:46:53.628: E/AndroidRuntime(6373): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
05-28 10:46:53.628: E/AndroidRuntime(6373): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
05-28 10:46:53.628: E/AndroidRuntime(6373): at dalvik.system.NativeStart.main(Native Method)
And here is the actual set code :
...
if (android.os.Build.VERSION.SDK_INT>=9) {
// attempt to rotate the video 90 degrees.
try {
mMediaRecorder.setOrientationHint(90);
Utils.logLine("orientation rotated 90", this, Utils.LOG_TYPE_DEBUG);
} catch (Exception e) {
Utils.logLine("error trying setOrientationHint"+ e.getMessage(), this, Utils.LOG_TYPE_ERROR, e);
}
} else {
Utils.logLine("orientation set skipped ", this, Utils.LOG_TYPE_DEBUG);
}
...
If you are confident that only a limited number of devices have customize with this command, you can preemptive check by checking their type of device. Otherwise try
catch
block is the only way to handle it.