Skip to content

a plugin can show floating window on Android and picture in picture on iOS for flutter

License

Notifications You must be signed in to change notification settings

student9128/flutter_float_window

Repository files navigation

flutter_float_window

A Flutter plugin show float window on Android and show picture in picture on iOS.

How to use

if you have the permission show float window

Map<String, String> params = {"videoUrl":''};
FlutterFloatWindow.initFloatWindow(params);

FlutterFloatWindow.showFloatWindow();

FlutterFloatWindow.hideFloatWindow();

FlutterFloatWindow.play();

FlutterFloatWindow.pause();

FlutterFloatWindow.stop();

if you have no permission show flot window

if (await FlutterFloatWindow.canShowFloatWindow()) {
    FlutterFloatWindow.showFloatWindow();
} else {
    FlutterFloatWindow.openSetting();
}

setVideoUrl

Map<String, String> params = {"videoUrl":""};
FlutterFloatWindow.setVideoUrl(params);

isPlayWhenScreenOff

FlutterFloatWindow.isPlayWhenScreenOff(true);

some native actions send to flutter

 var channel = FlutterFloatWindow.channel;
    channel.setMethodCallHandler((call) async{
      switch (call.method) {
        case "onFullScreenClick":
          debugPrint('onFullScreenClick');
          break;
        case "onCloseClick":
          debugPrint('onCloseClick');
         break;
        case "onPlayClick":
          debugPrint('onPlayClick,${call.arguments}');
          break;
      }
    });

setBackgroundColor

FlutterFloatWindow.setBackgroundColor("#5c3317");

setGravity

 FlutterFloatWindow.setGravity(FloatWindowGravity.CENTER);

setWidthAndHeight

var map = {
"width": int.parse(width),
"height": int.parse(height)};
FlutterFloatWindow.setWidthAndHeight(map);

setAspectRatio

 FlutterFloatWindow.setAspectRatio(0.7);

live float window

///init and show live float window
await FlutterFloatWindow.initFloatLive(_mAppId,_token, _channelName, _mOptionalUid);

///hide live float window and leave channel
FlutterFloatWindow.leaveChannel();

for iOS

//video player
FlutterVideoPlayerView()

//agora
FlutterAgoraLiveView()

init video player

  FlutterFloatWindow.initVideoPlayerIOS(
          url: dataSource,
          title: title,
          artist: artist,
          coverUrl: cover,
          position: 0,
          speed: 1.0);
      FlutterVideoPlayerEngine playerEngine = FlutterVideoPlayerEngine.create();
      playerEngine.setVideoPlayerEventHandler(FlutterVideoPlayerEventHandler(
          onInitialized: () {
      }, onVideoProgress: (double position, double duration,
              double bufferedStart, double bufferedEnd) {
      }, onVideoPlayPaused: () {
      }, onVideoPlayEnd: () {
      }, onVideoInterruptionBegan: () {
      }, onVideoInterruptionEnded: () {
      }, onVideoPipCloseClicked: (){
      }, onVideoPipFullScreenClicked:(){}));
      FlutterFloatWindow.initVideoPlayerListener(playerEngine.mHandler!);

init agora

  FlutterAgoraLiveEngine live = FlutterAgoraLiveEngine.create();
      live.setAgoraLiveEventHandler(FlutterAgoraLiveEventHandler(
          onConnectionChanged: (state, reason) {
          },onJoinChannelSuccess: (uid) {
          },onUserJoined: (uid) {
          },onUserOffline: (uid, reason) {
          },onFirstRemoteVideoFrame: (uid) { 
          },onFirstRemoteVideoDecoded: (uid) {
          },onRemoteVideoMuted: (uid) {
          },onRemoteVideoStateChanged: (uid) {
          },onLeaveChannel: () {
          },onLivePipCloseClicked:(){
          },onLivePipFullScreenClicked:(){}));
      FlutterFloatWindow.initAgora(_, _, _, _,title:title, artist: artist, coverUrl:cover);

use picture in picture

FlutterFloatWindow.startPipIOS();
FlutterFloatWindow.stopPipIOS();

FlutterFloatWindow.startPipVideoIOS();
FlutterFloatWindow.stopPipVideoIOS();