Solution 1 :
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–
Problem :
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?