Flutter上线项目实战——防止录屏

Posted callme大帅

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flutter上线项目实战——防止录屏相关的知识,希望对你有一定的参考价值。

1.Setup

flutter_forbidshot: 0.0.1

2.Usage

ios API

  1. Get the current recording screen state (获取到当前是否在录屏)
bool isCapture = await FlutterForbidshot.iosIsCaptured;
  1. Screen recording status changes will call back (录屏状态变化会回调)
StreamSubscription<void> subscription = FlutterForbidshot.iosShotChange.listen((event) {});

android API

  1. Turn on the forbid screen (开启禁止录屏)
FlutterForbidshot.setAndroidForbidOn();
  1. Turn off the forbid screen (取消禁止录屏)
FlutterForbidshot.setAndroidForbidOff();

3.Example

class _MyAppState extends State<MyApp> {
  bool isCaptured = false;
  StreamSubscription<void> subscription;

  @override
  void initState() {
    super.initState();
    init();
  }

  init() async {
    bool isCapture = await FlutterForbidshot.iosIsCaptured;
    setState(() {
      isCaptured = isCapture;
    });
    subscription = FlutterForbidshot.iosShotChange.listen((event) {
      setState(() {
        isCaptured = !isCaptured;
      });
    });
    
  }
  
  @override
  void dispose() {
    super.dispose();
    subscription?.cancel();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('flutter_borbidshot example app'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              Text('IOS:isCaptured:${isCaptured}'),
              RaisedButton(
                child: Text('Android forbidshot on'),
                onPressed: () {
                  FlutterForbidshot.setAndroidForbidOn();
                },
              ),
              RaisedButton(
                child: Text('Android forbidshot off'),
                onPressed: () {
                  FlutterForbidshot.setAndroidForbidOff();
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

4.Tip

1.使用ios api可以在应用内做监听后暂停视频播放;

2.测试android api在小米手机只能拦截截屏,在三星手机可以拦截截屏,录屏后视频内容变成黑色;


完结,撒花🎉

以上是关于Flutter上线项目实战——防止录屏的主要内容,如果未能解决你的问题,请参考以下文章

Flutter上线项目实战——即时通讯端对端加密(E2E)

Flutter上线项目实战——即时通讯端对端加密(E2E)

Flutter上线项目实战——图片视频预览

Flutter上线项目实战——图片视频预览

Flutter上线项目实战——腾讯点播直播下载

Flutter上线项目实战——腾讯点播直播下载