{"id":347425,"date":"2023-05-14T08:26:57","date_gmt":"2023-05-14T08:26:57","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=347425"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=347425","title":{"rendered":"<span>Picture in Picture Mode \u0432 android. \u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432\u0438\u0434\u0435\u043e \u0432 \u043c\u0438\u043d\u0438-\u043e\u043a\u043d\u0435<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f5b\/42d\/d05\/f5b42dd052880a4a27096681ccf993cc.png\" alt=\"\u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u0444\u043e\u0442\u043e (\u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 \u0441\u0432\u043e\u0435)\" title=\"\u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u0444\u043e\u0442\u043e (\u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 \u0441\u0432\u043e\u0435)\" width=\"3537\" height=\"2131\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f5b\/42d\/d05\/f5b42dd052880a4a27096681ccf993cc.png\"\/><\/p>\n<div><figcaption>\u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u0444\u043e\u0442\u043e (\u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 \u0441\u0432\u043e\u0435)<\/figcaption><\/div>\n<\/figure>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430<\/h2>\n<p>\u042f \u043f\u0440\u043e\u043f\u0443\u0449\u0443 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u0441\u0430\u043c\u043e\u0433\u043e \u0432\u0438\u0434\u0435\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e \u043b\u0438\u0448\u043d\u0435\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439.<br \/>\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u0432\u0438\u0434\u0435\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/github.com\/n-shvedov27\/PictureInPictureMode\/tree\/video_player_added\" rel=\"noopener noreferrer nofollow\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a> (\u0432\u0435\u0442\u043a\u0430 <em>video_player_added<\/em>)<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/864\/018\/9b0\/8640189b0da1800c2187db6af576aa8e.png\" alt=\"\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u044d\u0442\u043e\u0433\u043e\" title=\"\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u044d\u0442\u043e\u0433\u043e\" width=\"250\" height=\"528\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/864\/018\/9b0\/8640189b0da1800c2187db6af576aa8e.png\"\/><\/p>\n<div><figcaption>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u044d\u0442\u043e\u0433\u043e<\/figcaption><\/div>\n<\/figure>\n<h2>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f<\/h2>\n<p>Picture in Picture (PiP) mode \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0432 android 8.0 (api level 26). \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code>(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)<\/code><\/pre>\n<p>\u041d\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u0441 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u043c \u043e\u0431\u044a\u0435\u043c\u043e\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043a\u0438 <em>PiP-mode<\/em> \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d. \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c <em>PiP-mode<\/em> \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code>context.packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)<\/code><\/pre>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 activity<\/h2>\n<p>\u0412\u043d\u0435\u0441\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 <em>AndroidManifest.xml<\/em><\/p>\n<pre><code>&lt;activity     ...     android:supportsPictureInPicture=\"true\"     android:configChanges=\"screenSize|smallestScreenSize|screenLayout|orientation\"><\/code><\/pre>\n<p><code>android:supportsPictureInPicture<\/code> &#8212; \u0444\u043b\u0430\u0433, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0447\u0442\u043e activity \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 PiP-mode<br \/><code>android:configChanges<\/code> &#8212; \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u0438\u043f\u043e\u0432 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 <em>activity<\/em> \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u0430\u043c\u0430. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, <em>activity<\/em> \u043f\u0435\u0440\u0435\u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043c\u0435\u043d\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u044b <em>configChanges<\/em>, \u0442\u043e \u0443 <em>activity<\/em> \u043b\u0438\u0448\u044c \u0432\u044b\u0437\u043e\u0432\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>Activity.onConfigurationChanged()<\/code> \u0438 \u043e\u043d\u0430 \u043f\u0435\u0440\u0435\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.<\/p>\n<h2>\u041f\u0435\u0440\u0435\u0445\u043e\u0434 \u0432 PiP-mode<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434 <em>activity<\/em> \u0432 PiP-mode \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 <code>Activity.enterPictureInPictureMode(PictureInPictureParams params)<\/code> <\/p>\n<p>\u0415\u0441\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u0432 PiP-mode:<\/p>\n<ul>\n<li>\n<p>\u0412\u044b\u0437\u043e\u0432 <code>enterPictureInPictureMode()<\/code> \u0432 <em>OnClickListener<\/em> \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u043a\u043d\u043e\u043f\u043a\u0438<\/p>\n<\/li>\n<\/ul>\n<pre><code>enterPipButton.setOnClickListener {     enterPictureInPictureMode(params) }<\/code><\/pre>\n<ul>\n<li>\n<p>\u0412\u044b\u0437\u043e\u0432 <code>enterPictureInPictureMode()<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 <code>Activity.onUserLeaveHint()<\/code><em><br \/><\/em><code>onUserLeaveHint()<\/code> &#8212; \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u0433\u0434\u0430 <em>activity<\/em> \u0443\u0445\u043e\u0434\u0438\u0442 \u0432 \u0444\u043e\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437-\u0437\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<br \/>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0430\u0436\u0430\u043b \u043a\u043d\u043e\u043f\u043a\u0443 Home, \u0442\u043e <code>onUserLeaveHint()<\/code> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d. \u041d\u043e \u0435\u0441\u043b\u0438 \u043d\u0430\u0448\u0443 <em>activity<\/em> \u043f\u0435\u0440\u0435\u043a\u0440\u043e\u0435\u0442 \u044d\u043a\u0440\u0430\u043d \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0437\u0432\u043e\u043d\u043a\u0430, \u0442\u043e <code>onUserLeaveHint()<\/code> \u0432\u044b\u0437\u0432\u0430\u043d \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.<\/p>\n<\/li>\n<\/ul>\n<pre><code>override fun onUserLeaveHint() {     super.onUserLeaveHint()      enterPictureInPictureMode(params) }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 android 12 (api level 31) \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0444\u043b\u0430\u0433 <code>PictureInPictureParams.setAutoEnterEnabled<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u044c activity \u0432 PiP-mode \u043f\u0440\u0438 \u0435\u0435 \u0441\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0438.<\/p>\n<h2>PiP-mode \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b<\/h2>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 PiP-mode \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 <em>PictureInPictureParams.<\/em><br \/>\u0412\u043e\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li>\n<p>setAspectRatio(aspectRatio) &#8212; \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d (\u0448\u0438\u0440\u0438\u043d\u0430\/\u0432\u044b\u0441\u043e\u0442\u0430)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0c0\/2c4\/20e\/0c02c420eb3f12e187d60d019d266d31.webp\" alt=\"\u041f\u0440\u0438\u043c\u0435\u0440\u044b aspect ratio\" title=\"\u041f\u0440\u0438\u043c\u0435\u0440\u044b aspect ratio\" width=\"1920\" height=\"1080\"\/><\/p>\n<div><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440\u044b aspect ratio<\/figcaption><\/div>\n<\/figure>\n<ul>\n<li>\n<p>setSourceRectHint(sourceRectHint) &#8212; \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u0438\u0434\u0435\u043d \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u0432 PiP-mode. \u0414\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0430 sourceRectHint \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c aspectRatio.<br \/><strong>\u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435!<\/strong> \u041f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u0432 PiP-mode \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0441\u0447\u0438\u0442\u0430\u043d\u044b \u043e\u0442 \u0432\u0435\u0440\u0445\u043d\u0435\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u044b <em>activity <\/em>\u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 aspectRatio.   <\/p>\n<\/li>\n<li>\n<p>setAutoEnterEnabled(true) &#8212; \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u0444\u043b\u0430\u0433, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u0441\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0438 activity \u0435\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432 PiP-mode. \u0414\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0441 android 12 (api level 31)<\/p>\n<\/li>\n<li>\n<p>setActions(actions) &#8212; \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043d\u043e\u043f\u043a\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 activity \u0432 PiP-mode. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u043d\u0438\u0436\u0435<\/p>\n<\/li>\n<\/ul>\n<h2>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 UI \u0432 PiP-mode<\/h2>\n<p>\u041a\u043e\u0433\u0434\u0430 <em>activity<\/em> \u043f\u0435\u0440\u0435\u0448\u043b\u043e \u0432 PiP-mode, \u0441 \u043d\u0435\u0439 \u0443\u0436\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c. \u041f\u043e \u0441\u0443\u0442\u0438 <em>activity<\/em> \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 <em>onPause().<\/em> \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043a\u0440\u044b\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u043a\u043d\u043e\u043f\u043a\u0438, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044b \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043c\u0435\u043b\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b (\u0438\u0445 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u0432\u0438\u0434\u043d\u043e)<\/p>\n<p>\u041f\u043e\u043d\u044f\u0442\u044c \u0447\u0442\u043e <em>activity <\/em>\u043f\u0435\u0440\u0435\u0448\u043b\u043e \u0432 PiP-mode \u043c\u043e\u0436\u043d\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430<code>Activity.onPictureInPictureModeChanged().<\/code> <\/p>\n<pre><code>override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean,                                            newConfig: Configuration) {     if (isInPictureInPictureMode) {         \/\/ \u0421\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043b\u0438\u0448\u043d\u0438\u0435 \u043a\u043d\u043e\u043f\u043a\u0438, \u043c\u0435\u043b\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0442\u0434     } else {         \/\/ \u0412\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0430\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 ui     } }<\/code><\/pre>\n<h2>\u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 activity \u0432 PiP-mode<\/h2>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/6458fb2efe348a00f4a7a92c\" data-style=\"\" id=\"6458fb2efe348a00f4a7a92c\" width=\"\"><\/div>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 <em>activity<\/em> \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>RemoteAction.<\/code> <\/p>\n<pre><code>val icon = Icon.createWithResource(context, R.drawable.play) val intent = PiPModeActionsReceiver.createPlayIntent(this)  \/\/\u041d\u0435 \u0431\u0443\u0434\u0443 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0442\u0435\u043c\u0435 PendingIntent, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e val pendingIntent = PendingIntent.getBroadcast(context, 1, intent, PendingIntent.FLAG_IMMUTABLE)  val action = RemoteAction(     icon,     \"Play\",     \"Play video\",     pendingIntent )<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043d\u0430 <code>RemoteAction<\/code> \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/developer.android.com\/guide\/components\/broadcasts\" rel=\"noopener noreferrer nofollow\">BroadcastReceiver<\/a>. <br \/>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e:<\/p>\n<pre><code>class PiPModeActionsReceiver(     private val pipModeActionsListener: PiPModeActionsListener ) : BroadcastReceiver() {      companion object {         private const val ACTION = \"pip_mode_action\"         private const val EXTRA_CONTROL_TYPE = \"control_type\"         private const val REQUEST_PLAY = 1         private const val REQUEST_PAUSE = 2          fun createPlayIntent(context: Context): Intent {             val intent = Intent(context, PiPModeActionsReceiver::class.java)             intent.putExtra(EXTRA_CONTROL_TYPE, REQUEST_PLAY)             return intent         }          fun createPauseIntent(context: Context): Intent {             val intent = Intent(context, PiPModeActionsReceiver::class.java)             intent.putExtra(EXTRA_CONTROL_TYPE, REQUEST_PAUSE)             return intent         }     }      override fun onReceive(context: Context, intent: Intent) {         when (intent.getIntExtra(EXTRA_CONTROL_TYPE, 0)) {             REQUEST_PAUSE -> pipModeActionsListener.onPauseClick()             REQUEST_PLAY -> pipModeActionsListener.onPlayClick()         }     } }<\/code><\/pre>\n<pre><code>interface PiPModeActionsListener {     fun onPlayClick()     fun onPauseClick() }<\/code><\/pre>\n<pre><code>class MainActivity : AppCompatActivity(), PiPModeActionsListener {    ...    override fun onPauseClick() {       playerControlView.player?.pause()       val params = paramsBuilder           .setActions(getPlayAction())           .build()       setPictureInPictureParams(params)   }   override fun onPlayClick() {       playerControlView.player?.play()       val params = paramsBuilder           .setActions(getPauseAction())           .build()       setPictureInPictureParams(params)   } }<\/code><\/pre>\n<h2>Activity lifecycle \u0432 PiP-mode<\/h2>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a6a\/9a5\/5df\/a6a9a55dfe504cc63df86b85ea5cbe00.png\" width=\"435\" height=\"488\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a6a\/9a5\/5df\/a6a9a55dfe504cc63df86b85ea5cbe00.png\"\/><\/figure>\n<h2>BackStack activity \u0432 PiP-mode<\/h2>\n<p>\u041a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, <code>enterPictureInPictureMode()<\/code> \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442 \u0432 PiP-mode \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043a\u0443\u0449\u0443\u044e <em>activity.<\/em> \u0415\u0441\u043b\u0438 \u0436\u0435 \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u043d\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0435 multi-activity, \u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0431\u0430\u0433\u0438 c <em>backstack&#8217;\u043e\u043c activity<\/em>.<br \/>\u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 PiP-mode <em>activity<\/em> \u043f\u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0432 \u043d\u043e\u0432\u043e\u043c <em>Task (<\/em><a href=\"https:\/\/developer.android.com\/guide\/components\/activities\/tasks-and-back-stack\" rel=\"noopener noreferrer nofollow\"><em>\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e activities task<\/em><\/a><em>). <\/em>\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 \u0432\u0438\u0434\u0435\u043e:<\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/6459ebf31a7f54fbab017dab\" data-style=\"\" id=\"6459ebf31a7f54fbab017dab\" width=\"\"><\/div>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043c <em>launchMode<\/em> \u043a \u043d\u0430\u0448\u0435\u0439 <em>activity<\/em> \u0432 <em>AndroidManifest.xml.<\/em><\/p>\n<pre><code>&lt;activity     ...     android:launchMode=\"singleTask\"><\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u043e, \u0442\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c <em>launchMode<\/em> \u0443 \u043d\u0430\u0441 \u0432 <em>task&#8217;\u0435<\/em> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0434\u0430\u043d\u043d\u043e\u0439 <em>activity (<\/em><a href=\"https:\/\/habr.com\/ru\/companies\/otus\/articles\/493802\/\" rel=\"noopener noreferrer nofollow\"><em>\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e launchMode<\/em><\/a><em>)<\/em><\/p>\n<h2>\u0412\u044b\u0445\u043e\u0434 \u0438\u0437 PiP-mode<\/h2>\n<p>\u041d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0442\u043e, \u0447\u0442\u043e activity \u0432 PiP-mode \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u043d\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u0442\u0441\u044f, \u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u0432\u0435\u0440\u043d\u0443\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 (onPause).<br \/>\u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<ul>\n<li>\n<p>\u0414\u043e android 5.0 (api level 21)<\/p>\n<\/li>\n<\/ul>\n<pre><code>class MainActivity : AppCompatActivity() {          ...      override fun onStop() {         super.onStop()         if (isInPictureInPictureMode) {             finish()         }     } }<\/code><\/pre>\n<pre><code>\/\/AndroidManifest.xml &lt;activity     ...     android:autoRemoveFromRecents=\"true\"><\/code><\/pre>\n<ul>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435 android 5.0 (api level 21)<\/p>\n<\/li>\n<\/ul>\n<pre><code>class MainActivity : AppCompatActivity() {          ...      override fun onStop() {         super.onStop()         if (isInPictureInPictureMode) {             finishAndRemoveTask()         }     } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/734890\/\"> https:\/\/habr.com\/ru\/articles\/734890\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\">\n<div><figcaption>\u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u0444\u043e\u0442\u043e (\u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430 \u0441\u0432\u043e\u0435)<\/figcaption><\/div>\n<\/figure>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430<\/h2>\n<p>\u042f \u043f\u0440\u043e\u043f\u0443\u0449\u0443 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u0441\u0430\u043c\u043e\u0433\u043e \u0432\u0438\u0434\u0435\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e \u043b\u0438\u0448\u043d\u0435\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439.<br \/>\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u0432\u0438\u0434\u0435\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/github.com\/n-shvedov27\/PictureInPictureMode\/tree\/video_player_added\" rel=\"noopener noreferrer nofollow\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a> (\u0432\u0435\u0442\u043a\u0430 <em>video_player_added<\/em>)<\/p>\n<figure class=\"\">\n<div><figcaption>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u044d\u0442\u043e\u0433\u043e<\/figcaption><\/div>\n<\/figure>\n<h2>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f<\/h2>\n<p>Picture in Picture (PiP) mode \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0432 android 8.0 (api level 26). \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u0435\u0440\u0441\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code>(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)<\/code><\/pre>\n<p>\u041d\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u0441 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u043c \u043e\u0431\u044a\u0435\u043c\u043e\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043a\u0438 <em>PiP-mode<\/em> \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d. \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c <em>PiP-mode<\/em> \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code>context.packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)<\/code><\/pre>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 activity<\/h2>\n<p>\u0412\u043d\u0435\u0441\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 <em>AndroidManifest.xml<\/em><\/p>\n<pre><code>&lt;activity     ...     android:supportsPictureInPicture=\"true\"     android:configChanges=\"screenSize|smallestScreenSize|screenLayout|orientation\"><\/code><\/pre>\n<p><code>android:supportsPictureInPicture<\/code> &#8212; \u0444\u043b\u0430\u0433, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0447\u0442\u043e activity \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 PiP-mode<br \/><code>android:configChanges<\/code> &#8212; \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u0438\u043f\u043e\u0432 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 <em>activity<\/em> \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u0430\u043c\u0430. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, <em>activity<\/em> \u043f\u0435\u0440\u0435\u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u043c\u0435\u043d\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u044b <em>configChanges<\/em>, \u0442\u043e \u0443 <em>activity<\/em> \u043b\u0438\u0448\u044c \u0432\u044b\u0437\u043e\u0432\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>Activity.onConfigurationChanged()<\/code> \u0438 \u043e\u043d\u0430 \u043f\u0435\u0440\u0435\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.<\/p>\n<h2>\u041f\u0435\u0440\u0435\u0445\u043e\u0434 \u0432 PiP-mode<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434 <em>activity<\/em> \u0432 PiP-mode \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 <code>Activity.enterPictureInPictureMode(PictureInPictureParams params)<\/code> <\/p>\n<p>\u0415\u0441\u0442\u044c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u0432 PiP-mode:<\/p>\n<ul>\n<li>\n<p>\u0412\u044b\u0437\u043e\u0432 <code>enterPictureInPictureMode()<\/code> \u0432 <em>OnClickListener<\/em> \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u043a\u043d\u043e\u043f\u043a\u0438<\/p>\n<\/li>\n<\/ul>\n<pre><code>enterPipButton.setOnClickListener {     enterPictureInPictureMode(params) }<\/code><\/pre>\n<ul>\n<li>\n<p>\u0412\u044b\u0437\u043e\u0432 <code>enterPictureInPictureMode()<\/code> \u0432\u043d\u0443\u0442\u0440\u0438 <code>Activity.onUserLeaveHint()<\/code><em><br \/><\/em><code>onUserLeaveHint()<\/code> &#8212; \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u0433\u0434\u0430 <em>activity<\/em> \u0443\u0445\u043e\u0434\u0438\u0442 \u0432 \u0444\u043e\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437-\u0437\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<br \/>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0430\u0436\u0430\u043b \u043a\u043d\u043e\u043f\u043a\u0443 Home, \u0442\u043e <code>onUserLeaveHint()<\/code> \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d. \u041d\u043e \u0435\u0441\u043b\u0438 \u043d\u0430\u0448\u0443 <em>activity<\/em> \u043f\u0435\u0440\u0435\u043a\u0440\u043e\u0435\u0442 \u044d\u043a\u0440\u0430\u043d \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0437\u0432\u043e\u043d\u043a\u0430, \u0442\u043e <code>onUserLeaveHint()<\/code> \u0432\u044b\u0437\u0432\u0430\u043d \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.<\/p>\n<\/li>\n<\/ul>\n<pre><code>override fun onUserLeaveHint() {     super.onUserLeaveHint()      enterPictureInPictureMode(params) }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 android 12 (api level 31) \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0444\u043b\u0430\u0433 <code>PictureInPictureParams.setAutoEnterEnabled<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u044c activity \u0432 PiP-mode \u043f\u0440\u0438 \u0435\u0435 \u0441\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0438.<\/p>\n<h2>PiP-mode \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b<\/h2>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 PiP-mode \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 <em>PictureInPictureParams.<\/em><br \/>\u0412\u043e\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li>\n<p>setAspectRatio(aspectRatio) &#8212; \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0441\u0442\u043e\u0440\u043e\u043d (\u0448\u0438\u0440\u0438\u043d\u0430\/\u0432\u044b\u0441\u043e\u0442\u0430)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\">\n<div><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440\u044b aspect ratio<\/figcaption><\/div>\n<\/figure>\n<ul>\n<li>\n<p>setSourceRectHint(sourceRectHint) &#8212; \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u0438\u0434\u0435\u043d \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u0432 PiP-mode. \u0414\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0430 sourceRectHint \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c aspectRatio.<br \/><strong>\u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435!<\/strong> \u041f\u0440\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u0432 PiP-mode \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0441\u0447\u0438\u0442\u0430\u043d\u044b \u043e\u0442 \u0432\u0435\u0440\u0445\u043d\u0435\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u044b <em>activity <\/em>\u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 aspectRatio.   <\/p>\n<\/li>\n<li>\n<p>setAutoEnterEnabled(true) &#8212; \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u0444\u043b\u0430\u0433, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u0441\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u0438 activity \u0435\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0432 PiP-mode. \u0414\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0441 android 12 (api level 31)<\/p>\n<\/li>\n<li>\n<p>setActions(actions) &#8212; \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043d\u043e\u043f\u043a\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 activity \u0432 PiP-mode. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u043d\u0438\u0436\u0435<\/p>\n<\/li>\n<\/ul>\n<h2>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 UI \u0432 PiP-mode<\/h2>\n<p>\u041a\u043e\u0433\u0434\u0430 <em>activity<\/em> \u043f\u0435\u0440\u0435\u0448\u043b\u043e \u0432 PiP-mode, \u0441 \u043d\u0435\u0439 \u0443\u0436\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c. \u041f\u043e \u0441\u0443\u0442\u0438 <em>activity<\/em> \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 <em>onPause().<\/em> \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043a\u0440\u044b\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u043a\u043d\u043e\u043f\u043a\u0438, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044b \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043c\u0435\u043b\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b (\u0438\u0445 \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u0432\u0438\u0434\u043d\u043e)<\/p>\n<p>\u041f\u043e\u043d\u044f\u0442\u044c \u0447\u0442\u043e <em>activity <\/em>\u043f\u0435\u0440\u0435\u0448\u043b\u043e \u0432 PiP-mode \u043c\u043e\u0436\u043d\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430<code>Activity.onPictureInPictureModeChanged().<\/code> <\/p>\n<pre><code>override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean,                                            newConfig: Configuration) {     if (isInPictureInPictureMode) {         \/\/ \u0421\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043b\u0438\u0448\u043d\u0438\u0435 \u043a\u043d\u043e\u043f\u043a\u0438, \u043c\u0435\u043b\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0438\u0442\u0434     } else {         \/\/ \u0412\u043e\u0441\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0430\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 ui     } }<\/code><\/pre>\n<h2>\u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 activity \u0432 PiP-mode<\/h2>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/6458fb2efe348a00f4a7a92c\" data-style=\"\" id=\"6458fb2efe348a00f4a7a92c\" width=\"\"><\/div>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 <em>activity<\/em> \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>RemoteAction.<\/code> <\/p>\n<pre><code>val icon = Icon.createWithResource(context, R.drawable.play) val intent = PiPModeActionsReceiver.createPlayIntent(this)  \/\/\u041d\u0435 \u0431\u0443\u0434\u0443 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0442\u0435\u043c\u0435 PendingIntent, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e val pendingIntent = PendingIntent.getBroadcast(context, 1, intent, PendingIntent.FLAG_IMMUTABLE)  val action = RemoteAction(     icon,     \"Play\",     \"Play video\",     pendingIntent )<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043d\u0430 <code>RemoteAction<\/code> \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/developer.android.com\/guide\/components\/broadcasts\" rel=\"noopener noreferrer nofollow\">BroadcastReceiver<\/a>. <br \/>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e:<\/p>\n<pre><code>class PiPModeActionsReceiver(     private val pipModeActionsListener: PiPModeActionsListener ) : BroadcastReceiver() {      companion object {         private const val ACTION = \"pip_mode_action\"         private const val EXTRA_CONTROL_TYPE = \"control_type\"         private const val REQUEST_PLAY = 1         private const val REQUEST_PAUSE = 2          fun createPlayIntent(context: Context): Intent {             val intent = Intent(context, PiPModeActionsReceiver::class.java)             intent.putExtra(EXTRA_CONTROL_TYPE, REQUEST_PLAY)             return intent         }          fun createPauseIntent(context: Context): Intent {             val intent = Intent(context, PiPModeActionsReceiver::class.java)             intent.putExtra(EXTRA_CONTROL_TYPE, REQUEST_PAUSE)             return intent         }     }      override fun onReceive(context: Context, intent: Intent) {         when (intent.getIntExtra(EXTRA_CONTROL_TYPE, 0)) {             REQUEST_PAUSE -> pipModeActionsListener.onPauseClick()             REQUEST_PLAY -> pipModeActionsListener.onPlayClick()         }     } }<\/code><\/pre>\n<pre><code>interface PiPModeActionsListener {     fun onPlayClick()     fun onPauseClick() }<\/code><\/pre>\n<pre><code>class MainActivity : AppCompatActivity(), PiPModeActionsListener {    ...    override fun onPauseClick() {       playerControlView.player?.pause()       val params = paramsBuilder           .setActions(getPlayAction())           .build()       setPictureInPictureParams(params)   }   override fun onPlayClick() {       playerControlView.player?.play()       val params = paramsBuilder           .setActions(getPauseAction())           .build()       setPictureInPictureParams(params)   } }<\/code><\/pre>\n<h2>Activity lifecycle \u0432 PiP-mode<\/h2>\n<figure class=\"\"><\/figure>\n<h2>BackStack activity \u0432 PiP-mode<\/h2>\n<p>\u041a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, <code>enterPictureInPictureMode()<\/code> \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442 \u0432 PiP-mode \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043a\u0443\u0449\u0443\u044e <em>activity.<\/em> \u0415\u0441\u043b\u0438 \u0436\u0435 \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u043d\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0435 multi-activity, \u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0431\u0430\u0433\u0438 c <em>backstack&#8217;\u043e\u043c activity<\/em>.<br \/>\u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0445\u043e\u0434\u0430 \u0438\u0437 PiP-mode <em>activity<\/em> \u043f\u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0432 \u043d\u043e\u0432\u043e\u043c <em>Task (<\/em><a href=\"https:\/\/developer.android.com\/guide\/components\/activities\/tasks-and-back-stack\" rel=\"noopener noreferrer nofollow\"><em>\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e activities task<\/em><\/a><em>). <\/em>\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 \u0432\u0438\u0434\u0435\u043e:<\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/6459ebf31a7f54fbab017dab\" data-style=\"\" id=\"6459ebf31a7f54fbab017dab\" width=\"\"><\/div>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043c <em>launchMode<\/em> \u043a \u043d\u0430\u0448\u0435\u0439 <em>activity<\/em> \u0432 <em>AndroidManifest.xml.<\/em><\/p>\n<pre><code>&lt;activity     ...     android:launchMode=\"singleTask\"><\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043a\u043e\u0440\u043e\u0442\u043a\u043e, \u0442\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c <em>launchMode<\/em> \u0443 \u043d\u0430\u0441 \u0432 <em>task&#8217;\u0435<\/em> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0434\u0430\u043d\u043d\u043e\u0439 <em>activity (<\/em><a href=\"https:\/\/habr.com\/ru\/companies\/otus\/articles\/493802\/\" rel=\"noopener noreferrer nofollow\"><em>\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e launchMode<\/em><\/a><em>)<\/em><\/p>\n<h2>\u0412\u044b\u0445\u043e\u0434 \u0438\u0437 PiP-mode<\/h2>\n<p>\u041d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u043c \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0442\u043e, \u0447\u0442\u043e activity \u0432 PiP-mode \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u043d\u0435 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u0442\u0441\u044f, \u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u0432\u0435\u0440\u043d\u0443\u0442\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 (onPause).<br \/>\u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<ul>\n<li>\n<p>\u0414\u043e android 5.0 (api level 21)<\/p>\n<\/li>\n<\/ul>\n<pre><code>class MainActivity : AppCompatActivity() {          ...      override fun onStop() {         super.onStop()         if (isInPictureInPictureMode) {             finish()         }     } }<\/code><\/pre>\n<pre><code>\/\/AndroidManifest.xml &lt;activity     ...     android:autoRemoveFromRecents=\"true\"><\/code><\/pre>\n<ul>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435 android 5.0 (api level 21)<\/p>\n<\/li>\n<\/ul>\n<pre><code>class MainActivity : AppCompatActivity() {          ...      override fun onStop() {         super.onStop()         if (isInPictureInPictureMode) {             finishAndRemoveTask()         }     } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/734890\/\"> https:\/\/habr.com\/ru\/articles\/734890\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-347425","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347425","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=347425"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347425\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=347425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=347425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=347425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}