Android 8.0中如何实现视频通话的画中画模式的示例

  

Android 8.0当中允许Activiy以画中画模式展现。这是一种多窗口模式的改进加强,在视频类应用中用处非常大,有了这种模式,就可以在视频通话或者观看直播的过程当中打开另外的应用而不用退出当前视频。更详细的就不再累述了,大家去阅读官方文档就行

  

这里以集市SDK为例来给大家展示下该特性,实际上不用集市SDK做任何修改。

  

<强>准备环境

  
      <李> Android 8.0或以上版本手机李   <李>集市SDK 1.14.0或以上版本李   <李> Android Studio 3.0或以上版本(非必需)   
  

<>强如何实现画中画模式

  

默认应用是不支持画中画模式的,需要给视频所在的活动做些配置,如下在AndroidManifest。xml加上属性resizeableActivity/supportsPictureInPicture并均设置为真正的

        android: resizeableActivity=" true "   android: supportsPictureInPicture=" true "   android: configChanges="拉| smallestScreenSize | screenLayout |取向”      

为了进入画中画模式,den必需要用enterPictureInPictureMode (PictureInPictureParams params)方法,非常的简单,但是为了告诉系统进入画中画模式之后,活动界面在整个屏幕当中的布局,我们需要设置一些参数。我们这里简单设置下,具体在使用的时候需要根据屏幕的分辨率动态取设置,更多信息参考官方文档。

        PictureInPictureParams params=new PictureInPictureParams.Builder ()   16).setAspectRatio(新理性(10)    .build ();      

当然需要在程序当中控制自己界面当中的内容,比如我们可以隐藏自己本地的预览画面,隐藏不需要的按钮信息等等,这个实现也非常简单。

        @Override   公共空间>   包com.example.myapplication;      进口android.annotation.TargetApi;   进口android.app.PictureInPictureParams;   进口android.content.res.Configuration;   进口android.os.Build;   进口android.os.Bundle;   进口android.support.annotation.Nullable;   进口android.support.v7.app.AppCompatActivity;   进口android.util.Log;   进口android.util.Rational;   进口android.view.Gravity;   进口android.view.View;   进口android.view.ViewGroup;   进口android.widget.FrameLayout;   进口android.widget.TextView;/* *   *画中画   */公开课TestPIPActivity延伸AppCompatActivity {   私有静态最终字符串标签=癟estPIPActivity”;   私人PictureInPictureParams。Builder mPictureInPictureParamsBuilder;      @TargetApi (Build.VERSION_CODES.O)   @Override   保护无效onCreate (@Nullable包savedInstanceState) {   super.onCreate (savedInstanceState);   FrameLayout内容=new FrameLayout(这个);   setContentView(内容、新ViewGroup.LayoutParams (   ViewGroup.LayoutParams。MATCH_PARENT ViewGroup.LayoutParams.MATCH_PARENT));      如果(Build.VERSION。SDK_INT==Build.VERSION_CODES.O) {   mPictureInPictureParamsBuilder=new PictureInPictureParams.Builder ();      最后一个TextView TextView=new TextView(这个);   textView。setText(“测试脉冲”);   textView.setTextSize (20);   FrameLayout。LayoutParams fl=new FrameLayout.LayoutParams (   ViewGroup.LayoutParams。WRAP_CONTENT ViewGroup.LayoutParams.WRAP_CONTENT);   fl.gravity=重力。中心;   textView。setOnClickListener(新View.OnClickListener () {      @Override   公共空间onClick(查看v){//主要操作   理性aspectRatio=new理性(10,10);   mPictureInPictureParamsBuilder.setAspectRatio (aspectRatio) .build ();   enterPictureInPictureMode (mPictureInPictureParamsBuilder.build ());   }   });   content.addView (textView fl);      其他}{   TextView descTv=new TextView(这个);   descTv.setText(“当前版本不支持…”);   descTv.setTextSize (20);   FrameLayout。LayoutParams Tvfl=new FrameLayout.LayoutParams (   ViewGroup.LayoutParams。WRAP_CONTENT ViewGroup.LayoutParams.WRAP_CONTENT);   Tvfl。重力=重力。中心;   content.addView (descTv Tvfl);   }      }            @Override   公共空间onPictureInPictureModeChanged(布尔isInPictureInPictureMode配置newConfig) {   超级。onPictureInPictureModeChanged (isInPictureInPictureMode newConfig);   Log.d(标签,String.valueOf (isInPictureInPictureMode));   }   之前      

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

Android 8.0中如何实现视频通话的画中画模式的示例