我想使用官方 GoPro WSDK 访问 GoPro Hero 4 银牌,但是当我尝试使用 getMediaGateway() 访问它时出现运行时异常。我是 android 开发的新手,在 GoPro 开发人员文档中我读到你必须在后台线程中执行此操作,但我无法让它工作。我必须使用 .postDelayed() 来完成。这是另一个故事,目前并不重要。我以与 GoPro SDK 官方文档中描述的方式完全相同的方式完成了它,但我得到了您在我的代码片段之后看到的异常。简而言之:相机录制视频(带循环模式),3 秒后应访问 sd 卡。我发现问题是这个cameraresult-call,但无法修复它,即使我用.isSuccess()测试它。
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// [...]
// App shutter-button onClickListener
mBtnShutter.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(final View v) {
doCameraTasks(3,v);
}
});
}
// Press shutter after n seconds and extract both video-parts
private void doCameraTasks(int seconds, final View v) {
// On
getActivity().startService(C2Service.newToggleShutterCommand(v.getContext(),
mGoProCamera.getGuid()));
v.postDelayed(new Runnable() {
@Override
public void run() {
// Off after n seconds
getActivity().startService(C2Service.newToggleShutterCommand(v.getContext(),
mGoProCamera.getGuid()));
}
},seconds*1000);
v.postDelayed(new Runnable() {
@Override
public void run() {
CameraCommandResult<MediaResponse<GpCameraMedia>> cameraresult = mGoProCamera.getMediaGateway().getMediaList();
if(cameraresult.isSuccess()) {
MediaResponse<GpCameraMedia> mediaResponse = cameraresult.getData();
List<GpCameraMedia> myMediaList = mediaResponse.getMedia();
String cardID = mediaResponse.getSdCardGuid();
Log.d("sdcard_id",cardID);
}
}
},(seconds+2)*1000);
}
例外:
com.gopro.wsdksample E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.gopro.wsdksample, PID: 26823
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1148)
at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:249)
at libcore.io.IoBridge.recvfrom(IoBridge.java:553)
at java.net.PlainSocketImpl.read(PlainSocketImpl.java:549)
at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:42)
at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:253)
at com.android.okio.Okio$2.read(Okio.java:113)
at com.android.okio.RealBufferedSource.indexOf(RealBufferedSource.java:147)
at com.android.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:94)
at com.android.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:175)
at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:101)
at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:616)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:379)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:323)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:491)
at com.gopro.wsdk.domain.camera.SingleConnectionHttpClient.send(SingleConnectionHttpClient.java:60)
at com.gopro.wsdk.domain.camera.network.wifi.GpControlHttpCommandSender.send(GpControlHttpCommandSender.java:81)
at com.gopro.wsdk.domain.camera.operation.media.GetCameraMediaCommand.execute(GetCameraMediaCommand.java:64)
at com.gopro.wsdk.domain.camera.network.wifi.GpControlHttpCommandSender.process(GpControlHttpCommandSender.java:76)
at com.gopro.wsdk.domain.camera.sender.CommandSenderManager.process(CommandSenderManager.java:148)
at com.gopro.wsdk.domain.camera.GoProCamera.process(GoProCamera.java:426)
at com.gopro.wsdk.domain.camera.operation.media.GpMediaGateway.getMediaList(GpMediaGateway.java:85)
at com.gopro.wsdksample.features.ControlFragment$3.run(ControlFragment.java:112)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5306)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)