搜索插件、代码仓与 APP 分类

floating 封面
插件详情v6.0.0

floating

适用于 Flutter 的画中画模式管理。仅适用于 Android。

Android
近 30 天下载
2.3万
喜欢数
270
Pub 分数
160

安装插件

flutter pub add floating

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

浮动包为Flutter应用程序中的画中画(PiP)模式管理提供了支持,专用于Android。它允许开发者将媒体播放无缝转换为可移动和可调整大小的小型浮动窗口,同时用户可以与其他应用进行交互。这对于需要在后台持续播放的视频或音频内容特别有用。该包直接集成Android的PiP API,提供了一个简单直观的接口来控制PiP行为。它支持需要持续播放但无需完全聚焦应用的视频和音频用例。

适合场景

  • 背景视频播放
  • 画中画模式下的音频流
  • 需要连续播放的媒体应用
  • Android 上的多任务处理支持
  • 视频通话中的最小化视图

主要特点

  • 仅限 Android 的画中画支持
  • PiP 激活的简单 API
  • 自动画中画状态处理
  • 可自定义画中画大小和位置
  • 与 Android 的画中画 API 集成

适合对象

  • 视频播放器应用
  • 音频流媒体应用
  • 带有媒体内容的教育类应用程序
  • 需要多任务功能的应用程序
  • 针对Android设备的开发者

使用建议

  • 仅在 Android 上可用
  • 需要 Android 8.0+(API 26)
  • 仅限媒体播放场景
  • 无 iOS 支持
  • 必须正确处理画中画生命周期事件

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

floating

codecov

Picture in Picture management for Flutter. Android only

Picture in picture demo

App configuration

Add android:supportsPictureInPicture="true" line to the <activity> tag in android/src/main/AndroidManifest.xml:

<manifest>
   <application>
        <activity
            android:name=".MainActivity"
            android:supportsPictureInPicture="true"
            ...

Widget

This package provides a helper PiPSwitcher widget for switching the displayed widgets according to current PiP status. Use it like so:

PiPSwitcher(
    childWhenDisabled: Scaffold(...),
    childWhenEnabled: JustVideo(), 
)

API

PiP mode in desired mode is available only in Android so iOS and web support is not planned until the platforms adds native support for such feature.

Create a Floating instance
final floating = Floating();
Check if PiP is available
final canUsePiP = await floating.isPipAvailable;

PiP may be unavailable because of system settings managed by admin or device manufacturer. Also, the device may have Android version that was released without this feature.

Check if app is in PiP mode
final currentStatus = await floating.pipStatus;

Possible statuses:

Status Description Will enable() have an effect?
disabled PiP is available to use but currently disabled. Yes
enabled PiP is enabled. The app can display content but will not receive user inputs until the user decides to bring the app to it's full size. No
automatic PiP will be enabled automatically by the OS. Yes
unavailable PiP is disabled on given device. No
Enable PiP mode

Enable PiP right away:

final statusAfterEnabling = await floating.enable(ImmediatePiP());

Enable PiP when the app gets minimized via system gesture:

final statusAfterEnabling = await floating.enable(OnLeavePiP());

To later cancel, use .cancelOnLeavePiP().

When enabled, PiP mode can be toggled off by the user via system UI.

Arguments
aspectRatio:

The default 16/9 aspect ratio can be overridden with custom Rational. Eg. to make PiP square use: .enable(aspectRatio: Rational(1, 1)) or .enable(aspectRatio: Rational.square()).

sourceRectHint:

By default, system will simply use fade animation to tween between full app and PiP. Switching animation can be smoother by using source rect hint (example animation).

Check the example project to see an example of usage.

所属分类

源码仓库

使用此插件的项目