国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

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

2019-12-12 01:40:57
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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

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

準(zhǔn)備環(huán)境

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

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

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

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

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

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

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

@Overridepublic 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);}

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

另外Android 8.0 畫(huà)中畫(huà)demo

記錄一下簡(jiǎn)單的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;/** * 畫(huà)中畫(huà) */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("當(dāng)前版本不支持...");      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));  }

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 盈江县| 玉环县| 淮北市| 郓城县| 新平| 许昌市| 泸州市| 靖宇县| 九龙坡区| 精河县| 宝山区| 西青区| 牟定县| 岱山县| 沛县| 翼城县| 丹巴县| 肃南| 鄯善县| 萍乡市| 盘山县| 台江县| 富宁县| 马龙县| 民丰县| 略阳县| 洪湖市| 无为县| 那坡县| 安阳市| 武安市| 龙口市| 嘉禾县| 自贡市| 江陵县| 雷波县| 和田市| 平顺县| 全州县| 昭通市| 庄浪县|