The Floating Window feature allows hosts and viewers to enter Small Window Mode without exiting the live streaming room. The small window floats on the screen and can be freely dragged to a suitable position. The Floating Window can display the live broadcast screen. In Floating Window Mode, the app can switch to other scenarios or the background, and clicking the Floating Window can also restore the normal full-screen live streaming interface.
Use Instructions
Overview
The principle of the Floating Window is to add a custom view on the WindowManager as the content of the Floating Window. In Android 6.0 and above, it is necessary to request Floating Window permission.
In Android 6.0 and above, you need to request Floating Window Permission. You can also implement the logic to request Floating Window Permission yourself, as long as you call the show method of FloatWindow after obtaining the Floating Window Permission.
Usually, the Floating Window mode and Normal mode need to switch between each other. The steps are as follows:
Switch from Normal mode to Floating Window mode
Switch from Floating Window mode to Normal mode
Request Floating Window Permission (if permission is granted, no application is needed);
Create Content View and set it for the Floating Window;
Exit Activity, but retain relevant data and status of the business.
Pop up the Floating Window.
Listen for Floating Window Events;
Upon receiving the onClickWindow notification, close the Floating Window, then return to the original Activity and restore the relevant business data and status.
Note:
The Floating Window feature only requires you to provide a Content View and has no association with your business logic.
The process of mode switching requires saving/restoring related business data and status. This feature depends on your code architecture and specific business, so you need to implement it yourself.
In the live streaming scenario, during the mode switching process, you need to use the same LiveCoreView object to display the live content in both modes. This not only allows sharing the view but also sharing live streaming data and status.
As shown in the figure, the normal mode is the LiveActivity scene, and the floating window mode is the LiveFloatWindow scene. During the mode transition, the same LiveCoreView object can be used to ensure the live broadcast proceeds smoothly. Since the LiveCoreView needs to be used in the LiveFloatWindow after being destroyed in the LiveActivity, the context used when creating the LiveCoreView is the ApplicationContext rather than an Activity.