温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android如何实现简单画中画功能

发布时间:2021-08-27 13:35:15 来源:亿速云 阅读:236 作者:小新 栏目:开发技术

这篇文章主要介绍了Android如何实现简单画中画功能,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

Android 8.0推出了PictureInPicture(画中画功能),目前只有在8.0以上的系统上支持。对比IOS,IOS的Picture in Picture 模式是苹果公司在 iOS 9 中加入的一项多任务功能。下面先看一下效果:

Android如何实现简单画中画功能

相信不少人在平时使用ios手机的app时,已经体验过了,很高兴谷歌也推出了这项功能。

使用画中画模式注意点:

1.要使用画中画模式的Activity需要在清单文件中添加属性:

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

2.需要使用PictureInPictureParams类:

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.
                            //这就是我们从画中画模式的操作回调的地方
                            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);

通过广播接收者接收各种操作意图,对应其操作

感谢你能够认真阅读完这篇文章,希望小编分享的“Android如何实现简单画中画功能”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI