我正在开发一款录制视频的应用。它大部分都是完整的,但我遇到了一个奇怪的问题,旧的三星Galaxy S1(澳大利亚型号)运行2.3.3(API 10)。
当我尝试通过mMediaRecorder.setOrientationHint(90);
设置方向时,会抛出异常:
05-28 10:46:53.628: E/AndroidRuntime(6373): java.lang.RuntimeException: setParameter failed.
以及:
05-28 10:46:53.593: E/MediaRecorder(6373): setParameters(video-param-rotation-angle-degrees=90) failed: -2147483648
奇怪的是运行3.2.2(API 10)的其他设备完美运行只有这个三星galaxy s1似乎有一个卑鄙的自定义操作系统,不支持预期的setOrientation()。
我目前在try {} catch() {}
周围使用setOrientation()
。它不是一种处理这种权利的优雅方式吗?是否更好地预先检查设备是否支持setOrientation()
然后尝试设置?我找不到任何方法来检查这种支持。
我已经检查过(http://developer.android.com/reference/android/media/MediaRecorder.html)除了我已经使用的API级别9之外无法找到帮助。即,如果API级别为9或更高,则仅尝试设置方向
以下是完整的例外情况:
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)
这是实际的设定代码:
...
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);
}
...
答案 0 :(得分:0)
如果您确信只有少数设备可以使用此命令进行自定义,则可以checking their type of device进行抢先检查。否则try
catch
阻止是处理它的唯一方法。