简体   繁体   中英

I am facing issue on kotlin picture in picture with flutter platform methodchannel

Videopip.kt This code is for Picture in Picture mode.

package com.example.tex

import android.app.PictureInPictureParams
import android.content.res.Configuration
import android.graphics.Point
import android.os.Build
import android.os.Bundle
import android.util.Rational
import androidx.appcompat.app.AppCompatActivity

@Suppress("DEPRECATION")
class Videopip : AppCompatActivity(){

override fun onCreate(savedInstanceState: Bundle?){
    print("Inner")
    super.onCreate(savedInstanceState)
    if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
        val mpipParams=PictureInPictureParams.Builder()
        val display=windowManager.defaultDisplay
        val point=Point()
        display.getRealSize(point)
        mpipParams.setAspectRatio(Rational(point.x,point.y))
        enterPictureInPictureMode(mpipParams.build())
    }
}

override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration?) {
    super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
    if (isInPictureInPictureMode){

    }else{

    }
}
}

MainActivity.kt This code is for mainActivity to call platform channel.

package com.example.tex

import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel

class MainActivity: FlutterActivity() {
  private val channel = "PictureinPicture"

override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
    super.configureFlutterEngine(flutterEngine)
    MethodChannel(flutterEngine.dartExecutor.binaryMessenger, 
   channel).setMethodCallHandler {
            call, result ->
        if (call.method=="pips"){
            Videopip()
            result.success("Hai")
    }
}
 }
 }

This code invoke methodcall This is flutter code to invoke method.

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class MyHomePage extends StatefulWidget {
 const MyHomePage({Key? key}) : super(key: key);

  @override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
static const pip = const MethodChannel('PictureinPicture');

Future<void> pips() async {
  String? pipoutput;
 try {
  var result = await pip.invokeMethod('pips');
  setState(() {
    pipoutput = result;
  });
} on PlatformException catch (e) {
  print(e.toString());
}
print(pipoutput!);

}

@override
Widget build(BuildContext context) {
return Container(
  child: ElevatedButton(
    child: Text('Click Me'),
    onPressed: pips,
  ),
   );
  }
 }

When the button is pressed. The app wants to go to pip mode. but it does not work. Even message "Hai" message is passed to flutter but pip mode does not work. I don't know where I made a mistake. please, someone, help to resolve this problem.

AndroidManifiest.XML

<application
    android:label="tex"
    android:icon="@mipmap/ic_launcher">
   <activity android:name=".Videopip"
   android:supportsPictureInPicture="true"
   android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
   />
       <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
       

 

github.com/januwA/flutter_android_pip这个链接可以帮助你在 pip [github.com/januwA/flutter_android_pip][1]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM