সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
নিম্নলিখিত পরিস্থিতিতে আপনার অ্যাপের PiP মোডে প্রবেশ করা উচিত নয়:
ভিডিও বন্ধ বা পজ করা হলে।
আপনি যদি ভিডিও প্লেয়ারের চেয়ে অ্যাপের অন্য পৃষ্ঠায় থাকেন।
আপনার অ্যাপ কখন PiP মোডে প্রবেশ করে তা নিয়ন্ত্রণ করতে, একটি পরিবর্তনশীল যোগ করুন যা একটি mutableStateOf ব্যবহার করে ভিডিও প্লেয়ারের অবস্থা ট্র্যাক করে।
ভিডিও চলছে কিনা তার উপর ভিত্তি করে স্থিতি টগল করুন
ভিডিও প্লেয়ার বাজছে কিনা তার উপর ভিত্তি করে স্থিতি টগল করতে, ভিডিও প্লেয়ারে একজন শ্রোতা যোগ করুন। প্লেয়ার খেলছে কি না তার উপর ভিত্তি করে আপনার স্টেট ভেরিয়েবলের অবস্থা টগল করুন:
PiP মোড প্রবেশ করা হয়েছে কিনা তা নির্ধারণ করতে রাজ্য ব্যবহার করুন (প্রি-অ্যান্ড্রয়েড 12)
যেহেতু PiP প্রি-12 যোগ করার জন্য একটি DisposableEffect ব্যবহার করা হয়, তাই আপনাকে আপনার স্টেট ভেরিয়েবল হিসাবে newValue সেট করে rememberUpdatedState দ্বারা একটি নতুন ভেরিয়েবল তৈরি করতে হবে। এটি নিশ্চিত করবে যে আপডেট করা সংস্করণটি DisposableEffect মধ্যে ব্যবহার করা হয়েছে।
যখন OnUserLeaveHintListener ট্রিগার করা হয় তখন ল্যাম্বডা-তে আচরণ সংজ্ঞায়িত করে, enterPictureInPictureMode() এ কলের চারপাশে স্টেট ভেরিয়েবল সহ একটি if স্টেটমেন্ট যোগ করুন :
valcurrentShouldEnterPipModebyrememberUpdatedState(newValue=shouldEnterPipMode)if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O&&
Build.VERSION.SDK_INT < Build.VERSION_CODES.S){valcontext=LocalContext.currentDisposableEffect(context){valonUserLeaveBehavior:()->Unit={if(currentShouldEnterPipMode){context.findActivity().enterPictureInPictureMode(PictureInPictureParams.Builder().build())}}context.findActivity().addOnUserLeaveHintListener(onUserLeaveBehavior)onDispose{context.findActivity().removeOnUserLeaveHintListener(onUserLeaveBehavior)}}}else{Log.i("PiP info","API does not support PiP")}
PiP মোড প্রবেশ করা হয়েছে কিনা তা নির্ধারণ করতে রাষ্ট্র ব্যবহার করুন (অ্যান্ড্রয়েড 12-পরবর্তী)
আপনার স্টেট ভেরিয়েবলকে setAutoEnterEnabled এ পাস করুন যাতে আপনার অ্যাপ সঠিক সময়ে শুধুমাত্র PiP মোডে প্রবেশ করে:
valpipModifier=modifier.onGloballyPositioned{layoutCoordinates->
valbuilder=PictureInPictureParams.Builder()// Add autoEnterEnabled for versions S and upif(Build.VERSION.SDK_INT>=Build.VERSION_CODES.S){builder.setAutoEnterEnabled(shouldEnterPipMode)}context.findActivity().setPictureInPictureParams(builder.build())}VideoPlayer(pipModifier)
একটি মসৃণ অ্যানিমেশন বাস্তবায়ন করতে setSourceRectHint ব্যবহার করুন
setSourceRectHint API PiP মোডে প্রবেশ করার জন্য একটি মসৃণ অ্যানিমেশন তৈরি করে। Android 12+ এ, এটি PiP মোড থেকে বেরিয়ে আসার জন্য একটি মসৃণ অ্যানিমেশন তৈরি করে। PiP-এ রূপান্তরের পরে দৃশ্যমান কার্যকলাপের ক্ষেত্রটি নির্দেশ করতে PiP বিল্ডারে এই API যোগ করুন।
শুধুমাত্র buildersetSourceRectHint() যোগ করুন যদি রাজ্য সংজ্ঞায়িত করে যে অ্যাপটি PiP মোডে প্রবেশ করবে। যখন অ্যাপটিকে PiP-এ প্রবেশ করার প্রয়োজন হয় না তখন এটি sourceRect গণনা করা এড়িয়ে যায়।
sourceRect মান সেট করতে, মডিফায়ারে onGloballyPositioned ফাংশন থেকে দেওয়া layoutCoordinates ব্যবহার করুন।
buildersetSourceRectHint() কল করুন এবং sourceRect ভেরিয়েবলে পাস করুন।
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি Content License-এ বর্ণিত লাইসেন্সের অধীনস্থ। Java এবং OpenJDK হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-08-27 UTC-তে শেষবার আপডেট করা হয়েছে।
[[["সহজে বোঝা যায়","easyToUnderstand","thumb-up"],["আমার সমস্যার সমাধান হয়েছে","solvedMyProblem","thumb-up"],["অন্যান্য","otherUp","thumb-up"]],[["এতে আমার প্রয়োজনীয় তথ্য নেই","missingTheInformationINeed","thumb-down"],["খুব জটিল / অনেক ধাপ","tooComplicatedTooManySteps","thumb-down"],["পুরনো","outOfDate","thumb-down"],["অনুবাদ সংক্রান্ত সমস্যা","translationIssue","thumb-down"],["নমুনা / কোড সংক্রান্ত সমস্যা","samplesCodeIssue","thumb-down"],["অন্যান্য","otherDown","thumb-down"]],["2025-08-27 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["# Enter PiP at correct times\n\nYour app should not enter PiP mode in the following situations:\n\n- If the video is stopped or paused.\n- If you are on a different page of the app than the video player.\n\nTo control when your app enters PiP mode, add a variable that tracks the state\nof the video player using a [`mutableStateOf`](/reference/kotlin/androidx/compose/runtime/package-summary#mutableStateOf(kotlin.Any,androidx.compose.runtime.SnapshotMutationPolicy)).\n\nToggle state based on if video is playing\n-----------------------------------------\n\nTo toggle the state based on if the video player is playing, add a listener on\nthe video player. Toggle the state of your state variable based on if the player\nis playing or not:\n\n\n```kotlin\nplayer.addListener(object : Player.Listener {\n override fun onIsPlayingChanged(isPlaying: Boolean) {\n shouldEnterPipMode = isPlaying\n }\n})https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/pictureinpicture/PictureInPictureSnippets.kt#L171-L175\n```\n\n\u003cbr /\u003e\n\nToggle state based on if player is released\n-------------------------------------------\n\nWhen the player is released, set your state variable to `false`:\n\n\n```kotlin\nfun releasePlayer() {\n shouldEnterPipMode = false\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/pictureinpicture/PictureInPictureSnippets.kt#L180-L182\n```\n\n\u003cbr /\u003e\n\nUse state to define if PiP mode is entered (pre-Android 12)\n-----------------------------------------------------------\n\n1. Since adding PiP pre-12 uses a [`DisposableEffect`](/develop/ui/compose/side-effects#disposableeffect), you need to create a new variable by [`rememberUpdatedState`](/develop/ui/compose/side-effects#rememberupdatedstate) with `newValue` set as your state variable. This will ensure that the updated version is used within the `DisposableEffect`.\n2. In the lambda that defines the behavior when the `OnUserLeaveHintListener`\n is triggered, add an `if` statement with the state variable around the call to\n `enterPictureInPictureMode()`:\n\n\n ```kotlin\n val currentShouldEnterPipMode by rememberUpdatedState(newValue = shouldEnterPipMode)\n if (Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.O &&\n Build.VERSION.SDK_INT \u003c Build.VERSION_CODES.S\n ) {\n val context = LocalContext.current\n DisposableEffect(context) {\n val onUserLeaveBehavior: () -\u003e Unit = {\n if (currentShouldEnterPipMode) {\n context.findActivity()\n .enterPictureInPictureMode(PictureInPictureParams.Builder().build())\n }\n }\n context.findActivity().addOnUserLeaveHintListener(\n onUserLeaveBehavior\n )\n onDispose {\n context.findActivity().removeOnUserLeaveHintListener(\n onUserLeaveBehavior\n )\n }\n }\n } else {\n Log.i(\"PiP info\", \"API does not support PiP\")\n }https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/pictureinpicture/PictureInPictureSnippets.kt#L381-L404\n ```\n\n \u003cbr /\u003e\n\nUse state to define if PiP mode is entered (post-Android 12)\n------------------------------------------------------------\n\nPass your state variable into `setAutoEnterEnabled` so that your app only enters\nPiP mode at the right time:\n\n\n```kotlin\nval pipModifier = modifier.onGloballyPositioned { layoutCoordinates -\u003e\n val builder = PictureInPictureParams.Builder()\n\n // Add autoEnterEnabled for versions S and up\n if (Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.S) {\n builder.setAutoEnterEnabled(shouldEnterPipMode)\n }\n context.findActivity().setPictureInPictureParams(builder.build())\n}\n\nVideoPlayer(pipModifier)https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/pictureinpicture/PictureInPictureSnippets.kt#L194-L204\n```\n\n\u003cbr /\u003e\n\nUse `setSourceRectHint` to implement a smooth animation\n-------------------------------------------------------\n\nThe [`setSourceRectHint`](/reference/android/app/PictureInPictureParams.Builder#setSourceRectHint(android.graphics.Rect)) API creates a smoother animation for entering PiP\nmode. In Android 12+, it also creates a smoother animation for exiting PiP mode.\nAdd this API to the PiP builder to indicate the area of the activity that is\nvisible following the transition into PiP.\n\n1. Only add `setSourceRectHint()` to the `builder` if the state defines that the app should enter PiP mode. This avoids calculating `sourceRect` when the app does not need to enter PiP.\n2. To set the `sourceRect` value, use the `layoutCoordinates` that are given from the [`onGloballyPositioned`](/reference/kotlin/androidx/compose/ui/layout/OnGloballyPositionedModifier) function on the modifier.\n3. Call `setSourceRectHint()` on the `builder` and pass in the `sourceRect` variable.\n\n\n```kotlin\nval context = LocalContext.current\n\nval pipModifier = modifier.onGloballyPositioned { layoutCoordinates -\u003e\n val builder = PictureInPictureParams.Builder()\n if (shouldEnterPipMode) {\n val sourceRect = layoutCoordinates.boundsInWindow().toAndroidRectF().toRect()\n builder.setSourceRectHint(sourceRect)\n }\n\n if (Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.S) {\n builder.setAutoEnterEnabled(shouldEnterPipMode)\n }\n context.findActivity().setPictureInPictureParams(builder.build())\n}\n\nVideoPlayer(pipModifier)https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/pictureinpicture/PictureInPictureSnippets.kt#L218-L233\n```\n\n\u003cbr /\u003e\n\n| **Note:** Depending on the video player you are using, you may need to reference the documentation and choose the `sourceRectHint` that represents the actual video content instead of the full video player."]]