最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 8.0 中如何實現(xiàn)視頻通話的畫中畫模式的示例

 更新時間:2017年11月15日 14:17:14   作者:Agora  
本篇文章介紹了Android 8.0 中如何實現(xiàn)視頻通話的畫中畫模式的示例,具有一定的參考價值,感興趣的小伙伴們可以參考一下

Android 8.0 當中允許 Activiy 以畫中畫模式展現(xiàn)。這是一種多窗口模式的改進加強,在視頻類應(yīng)用中用處非常大,有了這種模式,就可以在視頻通話或者觀看直播的過程當中打開另外的應(yīng)用而不用退出當前視頻。更詳細的就不再累述了,大家去閱讀官方文檔 就行

這里以 Agora SDK 為例來給大家展示下該特性,實際上不用 Agora SDK 做任何修改。

準備環(huán)境

  1. Android 8.0 或以上版本手機
  2. Agora SDK 1.14.0 或以上 版本
  3. Android Studio 3.0 或以上版本(非必需)

如何實現(xiàn)畫中畫模式

默認應(yīng)用是不支持畫中畫模式的,需要給視頻所在的 Activity 做些配置,如下在 AndroidManifest.xml 加上屬性 resizeableActivity/supportsPictureInPicture 并均設(shè)置為 true

android:resizeableActivity="true"
android:supportsPictureInPicture="true"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"

為了進入畫中畫模式,Activty 必需要用 enterPictureInPictureMode(PictureInPictureParams params) 方法,非常的簡單,但是為了告訴系統(tǒng)進入畫中畫模式之后,Activity 界面在整個屏幕當中的布局,我們需要設(shè)置一些參數(shù)。我們這里簡單設(shè)置下,具體在使用的時候需要根據(jù)屏幕的分辨率動態(tài)取設(shè)置,更多信息參考官方文檔。

PictureInPictureParams params = new PictureInPictureParams.Builder()
   .setAspectRatio(new Rational(10, 16))
   .build();

當然需要在程序當中控制 Acticity 界面當中的內(nèi)容,比如我們可以隱藏自己本地的預(yù)覽畫面,隱藏不需要的按鈕信息等等,這個實現(xiàn)也非常簡單。

@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
  super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
  FrameLayout container = findViewById(R.id.local_video_view_container);
  SurfaceView surfaceView = (SurfaceView) container.getChildAt(0);
  surfaceView.setZOrderMediaOverlay(!isInPictureInPictureMode);
  surfaceView.setVisibility(isInPictureInPictureMode ? View.GONE : View.VISIBLE);
  container.setVisibility(isInPictureInPictureMode ? View.GONE : View.VISIBLE);
}

另外值得一說的是,進入畫中畫模式,系統(tǒng)會觸發(fā)生命周期的方法 onPause/onResume 方法,我們需要根據(jù)需要適當?shù)淖鲂┎僮?,比如是畫中畫模式的話,就不做任何操作,音視頻流繼續(xù),否則的話,就關(guān)閉視頻流,反正在后臺也看不見視頻。

另外Android 8.0 畫中畫demo

記錄一下簡單的demo ,方便以后用到:

package com.example.myapplication;

import android.annotation.TargetApi;
import android.app.PictureInPictureParams;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.util.Rational;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

/**
 * 畫中畫
 */

public class TestPIPActivity extends AppCompatActivity {
  private static final String TAG = "TestPIPActivity";
  private PictureInPictureParams.Builder mPictureInPictureParamsBuilder;

  @TargetApi(Build.VERSION_CODES.O)
  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FrameLayout content = new FrameLayout(this);
    setContentView(content,new ViewGroup.LayoutParams(
        ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

    if(Build.VERSION.SDK_INT == Build.VERSION_CODES.O){
      mPictureInPictureParamsBuilder = new PictureInPictureParams.Builder();

      final TextView textView = new TextView(this);
      textView.setText("test PIP");
      textView.setTextSize(20);
      FrameLayout.LayoutParams fl = new FrameLayout.LayoutParams(
          ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
      fl.gravity = Gravity.CENTER ;
      textView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {//主要操作
          Rational aspectRatio = new Rational(10,10);
          mPictureInPictureParamsBuilder.setAspectRatio(aspectRatio).build();
          enterPictureInPictureMode(mPictureInPictureParamsBuilder.build());
        }
      });
      content.addView(textView,fl);

    }else{
      TextView descTv = new TextView(this);
      descTv.setText("當前版本不支持...");
      descTv.setTextSize(20);
      FrameLayout.LayoutParams Tvfl = new FrameLayout.LayoutParams(
          ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
      Tvfl.gravity = Gravity.CENTER ;
      content.addView(descTv,Tvfl);
    }

  }



  @Override
  public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
    super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
    Log.d(TAG,String.valueOf(isInPictureInPictureMode));
  }

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

资兴市| 龙山县| 麦盖提县| 平湖市| 左贡县| 赤城县| 太白县| 房山区| 潜山县| 济南市| 厦门市| 若尔盖县| 旬阳县| 玉溪市| 拉萨市| 巴楚县| 和硕县| 金堂县| 饶平县| 安顺市| 布拖县| 滨海县| 大化| 泸水县| 永康市| 武强县| 临夏县| 昌乐县| 涿州市| 梓潼县| 香港| 堆龙德庆县| 依兰县| 桃园市| 长宁县| 南丰县| 沙河市| 开封县| 息烽县| 宁安市| 鄱阳县|