Complex Layout returned as PlatformView not showing and behaving correctly

Viewed 40

I am working on a Flutter project with the integration of Twilio Programmable Video. The integration happens in the native side.

I have a screen in Flutter and in the middle is a space for the PlatformView from the native Android (Java). The PlatformView returns a complex layout inflated from a layout file so it is not just returning a VideoView. Below is my PlatformView class:

public class RoomViewNative implements PlatformView, MethodChannel.MethodCallHandler {
    private final Context context;
    private final int id;
    final String TAG = "RoomViewNative";
    String accessToken = "";
    String participantId = "";
    String roomId = "";
    RoomViewService roomViewService;
    private final MethodChannel methodChannel;
    View myLayout;
    TextView tv;
    VideoTextureView videoView, videoView2;

    RoomViewNative(@NonNull Context context, int id, @Nullable Map<String, Object> creationParams, BinaryMessenger messenger) {
        this.id = id;
        this.context = context;
        methodChannel = new MethodChannel(messenger, "twilio/room_view_" + id);
        methodChannel.setMethodCallHandler(this);

        accessToken = creationParams.get("accessToken").toString();
        participantId = creationParams.get("participantId").toString();
        roomId = creationParams.get("roomId").toString();

        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        myLayout = inflater.inflate(R.layout.activity_main_min, null);


        roomViewService = new RoomViewService(accessToken, participantId, roomId, myLayout, this.context);
        Log.i(TAG, "constructor: " + id);
        roomViewService.init();
        roomViewService.createAudioAndVideoTracks();
        videoView = roomViewService.getVideoView();
        myLayout = roomViewService.getMainLayout();

    }

    @NonNull
    @Override
    public View getView() {
        Log.i(TAG, "getView: " + id);


        if(myLayout == null){
            myLayout = roomViewService.getMainLayout();
        }
//        if(videoView == null) videoView = roomViewService.getVideoView();
//        else return videoView;

//        FrameLayout baseFrameLayout = myLayout.findViewById(R.id.base_framelayout);
//        baseFrameLayout.addView(videoView);

//        LinearLayout layoutPrimaryVideo1 = myLayout.findViewById(R.id.layoutPrimaryVideo1);
//        layoutPrimaryVideo1.addView(videoView);

//        LinearLayout layoutPrimaryVideo2 = myLayout.findViewById(R.id.layoutPrimaryVideo2);
//        layoutPrimaryVideo2.addView(videoView2);

        return  myLayout;
    }

    @Override
    public void dispose() {}

    @Override
    public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
        switch (call.method) {
            case "init":
                init();
                break;
            case "endCall":
                roomViewService.disconnect();
                break;
            case "disableMic":
                roomViewService.muteClickListener(false);
                break;
            case "enableMic":
                roomViewService.muteClickListener(true);
                break;
            default:
                result.notImplemented();
        }
    }

    private void init() {
        //roomViewService.init();

    }
}

When I run the app, it always say about something like video view not initialized or already release. This is when I reference and use the VideoView inside my layout.

What is more interesting is that, when I dynamically create the VideoView in the getView() method, it is displaying correctly. But the problem is that I needed to add more VideoViews in the layout for multiple participants that are joining. When I try to add more views, the video feed stops working and the extra views are not added (shown).

I am using a class RoomViewService to create and connect to the room and handle the participants and the layout. The method getVideoView has the same exact process in displaying the localVideoTrack in the VideoView inside the layout, this one just returns a VideoView.

I just don't know if this is a known issue in Flutter > PlatformView. Before this, I also ran into problem like 1 view is only visible and returned from a layout with so many views. The root layout is a CoordinatorLayout and when I changed it to LinearLayout, the views are appearing already.

0 Answers
Related