can not resolve method getActivity()が出ます。どうすればいいのでしょうか?
Serviceでこのコードを使用したいです。
java
1 private void setUpMediaRecorder() throws IOException { 2 3 mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); 4 mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); 5 mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); 6 if (mNextVideoAbsolutePath == null || mNextVideoAbsolutePath.isEmpty()) { 7 //この下のgetActivity())のところに、can not resolve method getActivity() 8 mNextVideoAbsolutePath = getVideoFilePath(getActivity()); 9 //この上のFilePathも直さないと 10 } 11 mMediaRecorder.setOutputFile(mNextVideoAbsolutePath); 12 mMediaRecorder.setVideoEncodingBitRate(10000000); 13 mMediaRecorder.setVideoFrameRate(30); 14 mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight()); 15 mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); 16 mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); 17 WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); 18 19 int rotation = windowManager.getDefaultDisplay().getRotation(); 20 switch (mSensorOrientation) { 21 case SENSOR_ORIENTATION_DEFAULT_DEGREES: 22 mMediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(rotation)); 23 break; 24 case SENSOR_ORIENTATION_INVERSE_DEGREES: 25 mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(rotation)); 26 break; 27 } 28 mMediaRecorder.prepare(); 29 }
CameraAPIだが、Serviceなので、参考にしているURL
上記2つのURLを組み合わせてアプリを作成しています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。