Our first person video is working on our Anafi 4k, but not our thermal. I am putting our onStart() and startVideoStream() methods below, but I believe they’re pretty direct copies of the examples (converted to java). Any help would be appreciated. Thank you.
protected void onStart() {
super.onStart();
// Monitor the auto connection facility
groundSdk.<AutoConnection>getFacility(AutoConnection.class, new Observer<AutoConnection>() {
// Called when the auto connection facility is available and when it changes
@Override
public void onChanged(@Nullable AutoConnection autoConnection) {
LogRAR.i("onChanged callback");
if (autoConnection != null) {
LogRAR.i("autoConnection != null");
// Start auto connection
if (autoConnection.getStatus() != AutoConnection.Status.STARTED) {
autoConnection.start();
}
// Check if the drone has changed
// NOTE: the following four lines emulate the Kotlin line:
// if (drone?.uid != it.drone?.uid)
// Kotlin handles null pointer exceptions (NPE) much better than Java.
// The ternary operator is used to define drone3 helps with null pointers.
// A ternary operator is also used as the second argument in Intrinsics.areEqual
Drone drone1 = drone;
String drone3 = drone1 != null ? drone1.getUid() : null;
Drone drone2 = autoConnection.getDrone();
if (Intrinsics.areEqual(drone3, drone2 != null ? drone2.getUid() : null) ^ true) {
if (drone != null) {
stopDroneMonitors();
resetDroneUi();
}
// Monitor a new drone
drone = autoConnection.getDrone();
if (drone != null) {
startDroneMonitors();
}
}
// Check if the remote control has changed
// NOTE: the following four lines emulate the Kotlin line:
// if (rc?.uid != it.remoteControl?.uid)
RemoteControl rc1 = rc;
drone3 = rc1 != null ? rc1.getUid() : null;
RemoteControl rc2 = autoConnection.getRemoteControl();
if (Intrinsics.areEqual(drone3, rc2 != null ? rc2.getUid() : null) ^ true) {
if (rc != null) {
stopRcMonitors();
resetRcUi();
}
// Monitor new remote
rc = autoConnection.getRemoteControl();
if (rc != null) {
startRcMonitors();
}
}
}
}
});
}
private final void startVideoStream() {
try {
if (drone != null) {
// Monitor the stream server
this.streamServerRef = drone.getPeripheral(StreamServer.class, new Observer<StreamServer>() {
@Override
public void onChanged(@Nullable StreamServer streamServer) {
if (streamServer != null) {
// Enable streaming
if (!streamServer.streamingEnabled()) {
streamServer.enableStreaming(true);
}
// Monitor the live stream
if (ActivityFly.this.liveStreamRef == null) {
ActivityFly.this.liveStreamRef = streamServer.live(new Observer<CameraLive>() {
// Called when the live stream is available and when it changes
@Override
public void onChanged(@Nullable CameraLive liveStream) {
if (liveStream != null) {
// It is a new live stream.
// Set the live stream as the stream
// to be render by the stream view.
if (ActivityFly.this.liveStream == null) {
streamView.setStream((Stream) liveStream);
}
// Play the live stream.
if (liveStream.playState() != CameraLive.PlayState.PLAYING) {
liveStream.play();
}
} else {
// Stop rendering the stream
LogRAR.i("line 570");
streamView.setStream((Stream) null);
}
// Keep the live stream to know if it is a new one or not.
ActivityFly.this.liveStream = liveStream;
//TODO
//if (sinkStarted == false) {
//System.out.println("rDebug starting sink");
//Sink.Config sinkConfig = YUVSink.config(Looper.getMainLooper(), cb);
// Start YUV Sink -
//YUVSink.Config sinkConfig = YUVSink.config(Looper.getMainLooper(), cb);
//liveStream.openSink(sinkConfig);
//sinkStarted = true;
//};
}
});
}
} else {
if (liveStreamRef != null) {
LogRAR.i("line 591");
// Stop monitoring the live stream
if (liveStreamRef != null) {
liveStreamRef.close();
}
liveStreamRef = null;
// Stop rendering the stream
streamView.setStream(null);
}
}
}
});
}
}
catch (Exception e) {
LogRAR.i ("\nError thrown went starting video stream. \n" + e.getMessage() + "\n" + e.getStackTrace() +"\n\n");
}
}