1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit ArkUI 19 */ 20 21import type BaseContext from './application/BaseContext'; 22 23/** 24 * Picture In Picture Window Manager 25 * 26 * @namespace PiPWindow 27 * @syscap SystemCapability.Window.SessionManager 28 * @since 11 29 */ 30declare namespace PiPWindow { 31 /** 32 * If picture-in-picture enabled in current OS. 33 * 34 * @returns { boolean } true if PictureInPicture enabled, otherwise false 35 * @syscap SystemCapability.Window.SessionManager 36 * @since 11 37 */ 38 function isPiPEnabled(): boolean; 39 40 /** 41 * Create picture-in-picture controller 42 * 43 * @param { PiPConfiguration } config - Params for picture-in-picture controller creation 44 * @returns { Promise<PiPController> } - The promise returned by the function 45 * @throws { BusinessError } 401 - Params error, invalid or illegal parameter in PiPConfiguration 46 * @throws { BusinessError } 801 - Capability not supported 47 * @syscap SystemCapability.Window.SessionManager 48 * @since 11 49 */ 50 function create(config: PiPConfiguration): Promise<PiPController>; 51 52 /** 53 * PiPConfiguration 54 * 55 * @interface PiPConfiguration 56 * @syscap SystemCapability.Window.SessionManager 57 * @since 11 58 */ 59 interface PiPConfiguration { 60 /** 61 * Indicates window context. 62 * 63 * @type { BaseContext } 64 * @syscap SystemCapability.Window.SessionManager 65 * @since 11 66 */ 67 context: BaseContext; 68 69 /** 70 * Indicates the origin XComponentController. 71 * 72 * @type { XComponentController } 73 * @syscap SystemCapability.Window.SessionManager 74 * @since 11 75 */ 76 componentController: XComponentController; 77 78 /** 79 * Indicates navigation ID. 80 * 81 * @type { ?string } 82 * @syscap SystemCapability.Window.SessionManager 83 * @since 11 84 */ 85 navigationId?: string; 86 87 /** 88 * Picture-in-picture template type. 89 * 90 * @type { ?PiPTemplateType } 91 * @syscap SystemCapability.Window.SessionManager 92 * @since 11 93 */ 94 templateType?: PiPTemplateType; 95 96 /** 97 * Describes the width of content to be displayed in PiP window. For adjusting PiP window aspect ratio. 98 * 99 * @type { ?number } 100 * @syscap SystemCapability.Window.SessionManager 101 * @since 11 102 */ 103 contentWidth?: number; 104 105 /** 106 * Describes the height of content to be displayed in PiP window. For adjusting PiP window aspect ratio. 107 * 108 * @type { ?number } 109 * @syscap SystemCapability.Window.SessionManager 110 * @since 11 111 */ 112 contentHeight?: number; 113 } 114 115 /** 116 * Describe the type of picture-in-picture. 117 * 118 * @enum { number }. 119 * @syscap SystemCapability.Window.SessionManager 120 * @since 11 121 */ 122 enum PiPTemplateType { 123 /** 124 * Indicates the content to show in picture-in-picture window is video play 125 * @syscap SystemCapability.Window.SessionManager 126 * @since 11 127 */ 128 VIDEO_PLAY, 129 130 /** 131 * Indicates the content to show in picture-in-picture window is video call 132 * @syscap SystemCapability.Window.SessionManager 133 * @since 11 134 */ 135 VIDEO_CALL, 136 137 /** 138 * Indicates the content to show in picture-in-picture window is video meeting 139 * @syscap SystemCapability.Window.SessionManager 140 * @since 11 141 */ 142 VIDEO_MEETING, 143 144 /** 145 * Indicates the content to show in picture-in-picture window is video live 146 * @syscap SystemCapability.Window.SessionManager 147 * @since 11 148 */ 149 VIDEO_LIVE, 150 } 151 152 /** 153 * Enum for PiP window callback event type. 154 * 155 * @enum { number }. 156 * @syscap SystemCapability.Window.SessionManager 157 * @since 11 158 */ 159 enum PiPState { 160 /** 161 * PiP window is about to start. 162 * 163 * @syscap SystemCapability.Window.SessionManager 164 * @since 11 165 */ 166 ABOUT_TO_START = 1, 167 168 /** 169 * PiP window started. 170 * 171 * @syscap SystemCapability.Window.SessionManager 172 * @since 11 173 */ 174 STARTED = 2, 175 176 /** 177 * PiP window is about to stop. 178 * 179 * @syscap SystemCapability.Window.SessionManager 180 * @since 11 181 */ 182 ABOUT_TO_STOP = 3, 183 184 /** 185 * PiP window stopped. 186 * 187 * @syscap SystemCapability.Window.SessionManager 188 * @since 11 189 */ 190 STOPPED = 4, 191 192 /** 193 * Restore the original page from PiP window 194 * 195 * @syscap SystemCapability.Window.SessionManager 196 * @since 11 197 */ 198 ABOUT_TO_RESTORE = 5, 199 200 /** 201 * Error message during start/stop. 202 * 203 * @syscap SystemCapability.Window.SessionManager 204 * @since 11 205 */ 206 ERROR = 6, 207 } 208 209 /** 210 * Describe picture-in-picture action event type. 211 * 212 * @syscap SystemCapability.Window.SessionManager 213 * @since 11 214 */ 215 type PiPActionEventType = PiPVideoActionEvent | PiPCallActionEvent | PiPMeetingActionEvent | PiPLiveActionEvent; 216 217 /** 218 * Describe picture-in-picture video template action event type. 219 * 220 * @syscap SystemCapability.Window.SessionManager 221 * @since 11 222 */ 223 type PiPVideoActionEvent = 'playbackStateChanged' | 'nextVideo' | 'previousVideo'; 224 225 /** 226 * Describe picture-in-picture call template action event type. 227 * 228 * @syscap SystemCapability.Window.SessionManager 229 * @since 11 230 */ 231 type PiPCallActionEvent = 'hangUp' | 'micStateChanged' | 'videoStateChanged'; 232 233 /** 234 * Describe picture-in-picture meeting template action event type. 235 * 236 * @syscap SystemCapability.Window.SessionManager 237 * @since 11 238 */ 239 type PiPMeetingActionEvent = 'hangUp' | 'voiceStateChanged' | 'videoStateChanged'; 240 241 /** 242 * Describe picture-in-picture live template action event type. 243 * 244 * @syscap SystemCapability.Window.SessionManager 245 * @since 11 246 */ 247 type PiPLiveActionEvent = 'playbackStateChanged'; 248 249 /** 250 * PiPController 251 * 252 * @interface PiPController 253 * @syscap SystemCapability.Window.SessionManager 254 * @since 11 255 */ 256 interface PiPController { 257 258 /** 259 * Start picture-in-picture 260 * @returns { Promise<void> } - The promise returned by the function 261 * @throws { BusinessError } 1300012 - If PiP window state is abnormal. 262 * @throws { BusinessError } 1300013 - Create PiP window failed. 263 * @throws { BusinessError } 1300014 - Error when load PiP window content or show PiP window 264 * @throws { BusinessError } 1300015 - If window has created 265 * @syscap SystemCapability.Window.SessionManager 266 * @since 11 267 */ 268 startPiP(): Promise<void>; 269 270 /** 271 * Stop picture-in-picture. 272 * @returns { Promise<void> } - The promise returned by the function. 273 * @throws { BusinessError } 1300011 - Stop PiP window failed. 274 * @throws { BusinessError } 1300012 - If PiP window state is abnormal. 275 * @throws { BusinessError } 1300015 - If window is stopping 276 * @syscap SystemCapability.Window.SessionManager 277 * @since 11 278 */ 279 stopPiP(): Promise<void>; 280 281 /** 282 * Set if auto start picture-in-picture when back home 283 * @param { boolean } enable - Enable auto start picture-in-picture when back home 284 * @syscap SystemCapability.Window.SessionManager 285 * @since 11 286 */ 287 setAutoStartEnabled(enable: boolean): void; 288 289 /** 290 * Update source content size to adjust PiP window aspect ratio. 291 * @param { number } width - Indicates the width of the content. 292 * @param { number } height - Indicates the height of the content. 293 * @throws { BusinessError } 401 - Params error, invalid width or height. 294 * @syscap SystemCapability.Window.SessionManager 295 * @since 11 296 */ 297 updateContentSize(width: number, height: number): void; 298 299 /** 300 * Register picture-in-picture control event listener. 301 * @param { 'stateChange' } type - Registration type, PiP lifecycle state change, 'stateChange' 302 * @param { function } callback - Used to handle {'stateChange'} command 303 * @syscap SystemCapability.Window.SessionManager 304 * @since 11 305 */ 306 on(type: 'stateChange', callback: (state: PiPState, reason: string) => void): void; 307 308 /** 309 * Unregister picture-in-picture lifecycle event listener. 310 * @param { 'stateChange' } type - Used to unregister listener for {'stateChange'} command 311 * @syscap SystemCapability.Window.SessionManager 312 * @since 11 313 */ 314 off(type: 'stateChange'): void; 315 316 /** 317 * Register picture-in-picture control event listener. 318 * @param { 'controlPanelActionEvent' } type - Registration type, user action event, 'controlPanelActionEvent' 319 * @param { function } callback - Used to handle {'controlPanelActionEvent'} command 320 * @syscap SystemCapability.Window.SessionManager 321 * @since 11 322 */ 323 on(type: 'controlPanelActionEvent', callback: (event: PiPActionEventType) => void): void; 324 325 /** 326 * Unregister picture-in-picture lifecycle event listener 327 * @param { 'controlPanelActionEvent' } type - Used to unregister listener for {'controlPanelActionEvent'} command 328 * @syscap SystemCapability.Window.SessionManager 329 * @since 11 330 */ 331 off(type: 'controlPanelActionEvent'): void; 332 } 333} 334 335export default PiPWindow;