@IBAction public void toggleRecording() { if (!movieFileOutput.isRecording()) { recordButton.setImage(UIImage.create("player_stop"), UIControlState.Normal); startRecording(); } else { recordButton.setImage(UIImage.create("player_record"), UIControlState.Normal); movieFileOutput.stopRecording(); if (timer.isValid()) { timer.invalidate(); } } }
private void startRecording() { try { setupTimer(); File tempFile = File.createTempFile("movie", ".mp4", new File(System.getenv("TMPDIR"))); if (tempFile.exists()) { tempFile.delete(); } NSURL outputFileUrl = new NSURL(tempFile.toURI()); movieFileOutput.startRecording( outputFileUrl, new AVCaptureFileOutputRecordingDelegateAdapter() { @Override public void didStartRecording( AVCaptureFileOutput captureOutput, NSURL fileURL, NSArray<AVCaptureConnection> connections) { System.err.println("didStartRecording"); } @Override public void didFinishRecording( AVCaptureFileOutput captureOutput, NSURL outputFileURL, NSArray<AVCaptureConnection> connections, NSError error) { System.err.println("didFinishRecording"); saveRecording(outputFileURL); } }); } catch (IOException e) { e.printStackTrace(); } }