In my application, I am using openTok for audio and video calling functionality. Attached is the image I am creating for video calling purposes to rotate camera view there is a camera rotate icon.
Before publishing stream, this icon to rotare camera comes as in position, but as soon as stream is published this gets vanished. It is happening because due to z-order. The code to publish stream as mentioned below:
private void startPublisherStreaming() {
mPublisher = new Publisher.Builder(getContext())
.resolution(Publisher.CameraCaptureResolution.LOW)
.frameRate(Publisher.CameraCaptureFrameRate.FPS_7)
.name(name)
.build();
mPublisher.setPublisherListener(VideoCallFragment.this);
mPublisher.setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE, BaseVideoRenderer.STYLE_VIDEO_FILL);
mPublisher.setPublishAudio(true);
mPublisher.setPublishVideo(true);
flSubStream.addView(mPublisher.getView());
if (mPublisher.getView() instanceof GLSurfaceView) {
((GLSurfaceView) mPublisher.getView()).setZOrderOnTop(true);
}
ivFlipCamera.bringToFront();
mSession.publish(mPublisher);
}
As soon as glsurface gets renderend it comes up on top and rotate icon gets back. To bring the icon back, I am using bringtoFront() but this is not working. Below is the xml for layout.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cl_frag_audio_call"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/main_bg">
<FrameLayout
android:id="@+id/container_main_streaming"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_call_time"
style="@style/NormalTextView"
android:layout_width="0dp"
android:layout_height="@dimen/height_call_timer"
android:layout_marginTop="4dp"
android:background="@color/colorTransBlack"
android:gravity="center"
android:text="@string/dummy_call_duration"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:padding="@dimen/default_app_margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/default_quarter_app_margin"
android:background="@color/colorTransBlack"
app:layout_constraintBottom_toTopOf="@+id/group"
app:layout_constraintStart_toStartOf="parent">
<RelativeLayout
android:id="@+id/container_stream"
android:layout_width="@dimen/sub_streaming_size"
android:layout_height="@dimen/sub_streaming_size"
app:layout_constraintBottom_toTopOf="@+id/tv_stream_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</RelativeLayout>
<ImageView
android:id="@+id/iv_flip_camera"
android:layout_width="@dimen/camera_flip_size"
android:layout_height="@dimen/camera_flip_size"
android:src="@drawable/call_camera_flip_ico"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_stream_name"
style="@style/SmallTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/default_half_app_margin"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/group"
android:layout_width="match_parent"
android:layout_height="@dimen/calling_options_group_height"
android:background="@color/colorTransBlack"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:tag="1"
android:id="@+id/iv_video_switch"
android:layout_width="@dimen/calling_option_size"
android:layout_height="@dimen/calling_option_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/iv_speaker"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/call_vid_ico" />
<ImageView
android:id="@+id/iv_mic"
android:layout_width="@dimen/calling_option_size"
android:layout_height="@dimen/calling_option_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/iv_chat"
app:layout_constraintStart_toEndOf="@+id/iv_speaker"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/call_mic_ico" />
<ImageView
android:id="@+id/iv_chat"
android:layout_width="@dimen/calling_option_size"
android:layout_height="@dimen/calling_option_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/iv_add_user"
app:layout_constraintStart_toEndOf="@+id/iv_mic"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/call_chat_dis_ico" />
<ImageView
android:id="@+id/iv_add_user"
android:layout_width="@dimen/calling_option_size"
android:layout_height="@dimen/calling_option_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/iv_end_call"
app:layout_constraintStart_toEndOf="@+id/iv_chat"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/call_adduser_off_ico" />
<ImageView
android:id="@+id/iv_end_call"
android:layout_width="@dimen/calling_option_size"
android:layout_height="@dimen/calling_option_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/iv_add_user"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/call_incoming_reject_ico" />
<ImageView
android:id="@+id/iv_speaker"
android:layout_width="@dimen/calling_option_size"
android:layout_height="@dimen/calling_option_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/iv_mic"
app:layout_constraintStart_toEndOf="@+id/iv_video_switch"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/call_speaker_ico_enable" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Any idea how can I bring rotate icon on top of GLsurfaceview?
One option is to switch to use TextureView instead of GLSurfaceView, in general view composing is much easier when using TextureView instead of GLSurfaceView.
You can enable TextureView by doing this when building a Session
Session builder = new Session.Builder(this, apiKey, sessionId)
.sessionOptions(new Session.SessionOptions() {
@Override
public boolean useTextureViews() {
return true;
}
}).build();
For more info read: https://tokbox.com/developer/sdks/android/reference/com/opentok/android/Session.SessionOptions.html#useTextureViews--