Android實(shí)現(xiàn)簡(jiǎn)單畫(huà)中畫(huà)功能
Android 8.0推出了PictureInPicture(畫(huà)中畫(huà)功能),目前只有在8.0以上的系統(tǒng)上支持。對(duì)比IOS,IOS的Picture in Picture 模式是蘋(píng)果公司在 iOS 9 中加入的一項(xiàng)多任務(wù)功能。下面先看一下效果:
相信不少人在平時(shí)使用ios手機(jī)的app時(shí),已經(jīng)體驗(yàn)過(guò)了,很高興谷歌也推出了這項(xiàng)功能。
使用畫(huà)中畫(huà)模式注意點(diǎn):
1.要使用畫(huà)中畫(huà)模式的Activity需要在清單文件中添加屬性:
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation" android:supportsPictureInPicture="true"
2.需要使用PictureInPictureParams類(lèi):
PictureInPictureParams.Builder mPictureInPictureParamsBuilder = new PictureInPictureParams.Builder();
3.添加待決定的意圖
ArrayList<RemoteAction> actions = new ArrayList<>(); final PendingIntent intent = PendingIntent.getBroadcast( MainActivity.this, requestCode, new Intent(ACTION_MEDIA_CONTROL).putExtra(EXTRA_CONTROL_TYPE, controlType), 0); actions.add(new RemoteAction(icon, title, title, intent)); mPictureInPictureParamsBuilder.setActions(actions);
4.使用廣播接收各種意圖
private BroadcastReceiver mReceiver; mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent == null || !ACTION_MEDIA_CONTROL.equals(intent.getAction())) { return; } // This is where we are called back from Picture-in-Picture action items. //這就是我們從畫(huà)中畫(huà)模式的操作回調(diào)的地方 final int controlType = intent.getIntExtra(EXTRA_CONTROL_TYPE, 0); switch (controlType) { case CONTROL_TYPE_PLAY: mMovieView.play(); break; case CONTROL_TYPE_PAUSE: mMovieView.pause(); break; } } }; registerReceiver(mReceiver, new IntentFilter(ACTION_MEDIA_CONTROL));
5.配合自定義的MediaPlayer使用:
private MovieView mMovieView; //各種操作 mMovieView.showControls(); mMovieView.pause(); mMovieView.play(); mMovieView.hideControls(); mMovieView.setAdjustViewBounds(false);
通過(guò)廣播接收者接收各種操作意圖,對(duì)應(yīng)其操作
Demo地址:點(diǎn)擊查看
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android技巧一之啟動(dòng)屏+新功能左右導(dǎo)航邏輯
這篇文章主要介紹了Android技巧一之啟動(dòng)屏+新功能左右導(dǎo)航邏輯的相關(guān)資料,需要的朋友可以參考下2016-01-01Android Studio 升級(jí)到3.0后輸入法中文狀態(tài)下無(wú)法選詞的終極解決方案
這篇文章主要介紹了 AndroidStudio 升級(jí)到3.0后輸入法中文狀態(tài)下無(wú)法選詞的解決方案,需要的朋友可以參考下2017-11-11Android Studio 新手入門(mén)教程(一)基本設(shè)置圖解
這篇文章主要介紹了Android Studio 新手入門(mén)教程(一)基本設(shè)置圖解,需要的朋友可以參考下2017-12-12Android開(kāi)發(fā)實(shí)現(xiàn)日期時(shí)間控件選擇
這篇文章主要為大家詳細(xì)介紹了Android開(kāi)發(fā)實(shí)現(xiàn)日期時(shí)間控件選擇,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-09-09Android實(shí)現(xiàn)手勢(shì)滑動(dòng)(左滑和右滑)
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)手勢(shì)滑動(dòng),左滑和右滑效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-07-07Android用tabhost實(shí)現(xiàn) 界面切換,每個(gè)界面為一個(gè)獨(dú)立的activity操作
這篇文章主要介紹了Android用tabhost實(shí)現(xiàn) 界面切換,每個(gè)界面為一個(gè)獨(dú)立的activity操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09Android 自定義Button控件實(shí)現(xiàn)按鈕點(diǎn)擊變色
這篇文章給大家介紹了android 自定義Button控件實(shí)現(xiàn)按鈕點(diǎn)擊變色的代碼,本文給大家附有注釋?zhuān)浅2诲e(cuò),代碼簡(jiǎn)單易懂,對(duì)android按鈕點(diǎn)擊變色的實(shí)現(xiàn)感興趣的朋友參考下吧2016-11-11