I have been successfully streaming video from the Theta V (firmware version 2.50.1) using camera.getLivePreview
. However, the only way I have been able to stop the stream has been by starting and then stopping a video recording.
According to the API documentation “data acquisition stops when the camera is operated, shooting is started, or the shooting mode is changed.” However I have found this is not the case. I have tested changing the shooting mode by setting captureMode
to all the other values, and the stream has not stopped (I can even observe the mode changing by watching the indicator lamp on the device). I have also tried capturing an image using camera.takePicture
. This approach works for a second (the stream freezes, but then it resumes after the image was taken.
The only way I have found to stop the stream is to start and then stop a video recording. Here is the code I am using. Warning, it is really sloppy and gross right now, since I am a JS novice and was struggling to get an implementation using promises working.
function stopThetaLivePreview() {
// Start a capture
console.log("Stop the Theta live preview");
var endpoint = "/osc/commands/execute";
var url = CORS_ANYWHERE + "/" + settings.theta_ip + endpoint;
var startRequest = new digestAuthRequest('POST', url, settings.theta_user,
settings.theta_pass);
var startData = {
"name": "camera.startCapture",
};
startRequest.request(function(data) {
console.log(data);
},function(errorCode) {
throw errorCode;
}, startData);
// SUPER grimey way to make sure we stop recording
// TODO: use async, since this method doesn't wait for the prev req to fail
var maxIters = 10;
var iterNum = 0;
const stopRecording = function () {
var result;
iterNum = iterNum + 1;
console.log("Trying to stop the stream (attempt " + iterNum + ")");
var stopRequest = new digestAuthRequest('POST', url, settings.theta_user,
settings.theta_pass);
var stopData = {
"name": "camera.stopCapture",
};
// make the request
stopRequest.request(function(data) {
console.log(data);
clearInterval(retryIntervalId); // stop attempting to stop
thetaStatus.streaming = false; // stop getThetaLivePreview()
var stopEvent = new Event(STREAM_STOPPED_EVENT);
document.dispatchEvent(stopEvent);
},function(errorCode) {
throw errorCode;
}, stopData);
// Stop retrying if we are at max tries
if (iterNum >= maxIters) {
clearInterval(retryIntervalId);
}
};
var retryIntervalId = setInterval(stopRecording, 500);
}
The class digestAuthRequest
is from this repo which allows for basic digest auth requests without a bunch of other boiler plate being used for each call you make. I strongly recommend it.
Has anyone else had any experience with this? Could it be that in order for the other stopping methods to work you have to be in certain shooting modes? Currently every time I want to stop streaming I have to record a ~3s video, which is sot of a PITA.