iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android实现简单画中画功能
  • 180
分享到

Android实现简单画中画功能

2024-04-02 19:04:59 180人浏览 薄情痞子
摘要

Android 8.0推出了PictureInPicture(画中画功能),目前只有在8.0以上的系统上支持。对比iOS,ioS的Picture in Picture 模式是苹果公司

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

相信不少人在平时使用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);

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

Demo地址:点击查看

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

--结束END--

本文标题: Android实现简单画中画功能

本文链接: https://www.lsjlt.com/news/133781.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作