• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) 2022 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
16import { AsyncCallback } from './basic';
17import { WantAgent } from '@ohos.wantAgent';
18import KeyEvent from './@ohos.multimodalInput.keyEvent';
19import { ElementName } from './bundle/elementName';
20import image from './@ohos.multimedia.image';
21import audio from './@ohos.multimedia.audio';
22
23/**
24 * @name avSession
25 * @syscap SystemCapability.Multimedia.AVSession.Core
26 * @import import avsession from '@ohos.multimedia.avsession';
27 * @since 9
28 */
29declare namespace avSession {
30  /**
31   * Create an AVSession instance. An ability can only create one AVSession
32   * @param context The context of application
33   * @param tag A user-defined name for this session
34   * @param type The type of session {@link AVSessionType}
35   * @param {AsyncCallback<AVSession>} [callback] - callback.
36   * @returns {void | Promise<AVSession>} no callback returns Promise otherwise returns void
37   * @throws {BusinessError} 401 - parameter check failed
38   * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
39   * @syscap SystemCapability.Multimedia.AVSession.Core
40   * @since 9
41   */
42  function createAVSession(context: Context, tag: string, type: AVSessionType, callback: AsyncCallback<AVSession>): void;
43  function createAVSession(context: Context, tag: string, type: AVSessionType): Promise<AVSession>;
44
45  /**
46   * Get all avsession descriptors of the system
47   * @permission ohos.permission.MANAGE_MEDIA_RESOURCES
48   * @returns The array of {@link AVSessionDescriptor}
49   * @throws {BusinessError} 201 - permission denied
50   * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
51   * @syscap SystemCapability.Multimedia.AVSession.Manager
52   * @systemapi
53   * @since 9
54   */
55  function getAllSessionDescriptors(callback: AsyncCallback<Array<Readonly<AVSessionDescriptor>>>): void;
56  function getAllSessionDescriptors(): Promise<Array<Readonly<AVSessionDescriptor>>>;
57
58  /**
59   * Create an avsession controller
60   * @permission ohos.permission.MANAGE_MEDIA_RESOURCES
61   * @param sessionId Specifies the sessionId to create the controller.
62   * If provided 'default', the system will create a default controller, Used to control the system default session
63   * @returns An instance of {@link AVSessionController}
64   * @throws {BusinessError} 201 - permission denied
65   * @throws {BusinessError} 401 - parameter check failed
66   * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
67   * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
68   * @syscap SystemCapability.Multimedia.AVSession.Manager
69   * @systemapi
70   * @since 9
71   */
72  function createController(sessionId: string, callback: AsyncCallback<AVSessionController>): void;
73  function createController(sessionId: string): Promise<AVSessionController>;
74
75  /**
76   * Cast Audio to the remote devices or cast back local device
77   * @permission ohos.permission.MANAGE_MEDIA_RESOURCES
78   * @param audioDevices Specifies the audio devices to cast.
79   * @param sessionId Specifies the sessionId which to send to remote.
80   * 'all' means cast all the media audio of this device to remote.
81   * @throws {BusinessError} 201 - permission denied
82   * @throws {BusinessError} 401 - parameter check failed
83   * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
84   * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
85   * @throws {BusinessError} {@link #ERR_CODE_REMOTE_CONNECTION_ERR} - remote connection error
86   * @syscap SystemCapability.Multimedia.AVSession.Manager
87   * @systemapi
88   * @since 9
89   */
90  function castAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDescriptor>, callback: AsyncCallback<void>): void;
91  function castAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDescriptor>): Promise<void>;
92
93  /**
94   * Session token. Used to judge the legitimacy of the session.
95   * @permission ohos.permission.MANAGE_MEDIA_RESOURCES
96   * @syscap SystemCapability.Multimedia.AVSession.Manager
97   * @systemapi
98   * @since 9
99   */
100  interface SessionToken {
101    /**
102     * session id
103     * @since 9
104     */
105    sessionId: string;
106    /**
107     * process id
108     * @since 9
109     */
110    pid: number;
111    /**
112     * user id
113     * @since 9
114     */
115    uid: number;
116  }
117  /**
118   * Register or unregister system session changed callback
119   * @permission ohos.permission.MANAGE_MEDIA_RESOURCES
120   * @param type Registration Type, session creation, deletion or top priority session changed
121   * @param callback Used to returns the descriptor of created or delete session
122   * @throws {BusinessError} 201 - permission denied
123   * @throws {BusinessError} 401 - parameter check failed
124   * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
125   * @syscap SystemCapability.Multimedia.AVSession.Manager
126   * @systemapi
127   * @since 9
128   */
129  function on(type: 'sessionCreate' | 'sessionDestroy' | 'topSessionChange', callback: (session: AVSessionDescriptor) => void): void;
130  function off(type: 'sessionCreate' | 'sessionDestroy' | 'topSessionChange', callback?: (session: AVSessionDescriptor) => void): void;
131
132  /**
133   * Register or unregister Session service death callback, notifying the application to clean up resources.
134   * @param type Registration Type
135   * @param callback Used to handle the session service death event.
136   * @throws {BusinessError} 201 - permission denied
137   * @throws {BusinessError} 401 - packagearameter check failed
138   * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
139   * @syscap SystemCapability.Multimedia.AVSession.Core
140   * @since 9
141   */
142  function on(type: 'sessionServiceDie', callback: () => void): void;
143  function off(type: 'sessionServiceDie', callback?: () => void): void;
144
145  /**
146   * Send system media key event.The system automatically selects the recipient.
147   * @permission ohos.permission.MANAGE_MEDIA_RESOURCES
148   * @param event The key event to be send
149   * @throws {BusinessError} 201 - permission denied
150   * @throws {BusinessError} 401 - parameter check failed
151   * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
152   * @throws {BusinessError} {@link #ERR_CODE_COMMAND_INVALID} - command not supported
153   * @syscap SystemCapability.Multimedia.AVSession.Manager
154   * @systemapi
155   * @since 9
156   */
157  function sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback<void>): void;
158  function sendSystemAVKeyEvent(event: KeyEvent): Promise<void>;
159
160  /**
161   * Send system control command.The system automatically selects the recipient.
162   * @permission ohos.permission.MANAGE_MEDIA_RESOURCES
163   * @param command The command to be send. See {@link AVControlCommand}
164   * @throws {BusinessError} 201 - permission denied
165   * @throws {BusinessError} 401 - parameter check failed
166   * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
167   * @throws {BusinessError} {@link #ERR_CODE_COMMAND_INVALID} - command not supported
168   * @throws {BusinessError} {@link #ERR_CODE_MESSAGE_OVERLOAD} - command or event overload
169   * @syscap SystemCapability.Multimedia.AVSession.Manager
170   * @systemapi
171   * @since 9
172   */
173  function sendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback<void>): void;
174  function sendSystemControlCommand(command: AVControlCommand): Promise<void>;
175
176  /**
177   * session type.
178   */
179  type AVSessionType = 'audio' | 'video';
180  /**
181   * AVSession object.
182   * @interface AVSession
183   * @syscap SystemCapability.Multimedia.AVSession.Core
184   * @since 9
185   */
186  interface AVSession {
187    /**
188     * unique session Id
189     * @syscap SystemCapability.Multimedia.AVSession.Core
190     * @since 9
191     */
192    readonly sessionId: string;
193
194    /**
195     * Set the metadata of this session.
196     * In addition to the required properties, users can fill in partially supported properties
197     * @param data {@link AVMetadata}
198     * @throws {BusinessError} 401 - parameter check failed
199     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
200     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
201     * @syscap SystemCapability.Multimedia.AVSession.Core
202     * @since 9
203     */
204    setAVMetadata(data: AVMetadata, callback: AsyncCallback<void>): void;
205    setAVMetadata(data: AVMetadata): Promise<void>;
206
207    /**
208     * Set the playback state of this session.
209     * @param state {@link AVPlaybackState}
210     * @throws {BusinessError} 401 - parameter check failed
211     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
212     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
213     * @syscap SystemCapability.Multimedia.AVSession.Core
214     * @since 9
215     */
216    setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback<void>): void;
217    setAVPlaybackState(state: AVPlaybackState): Promise<void>;
218
219    /**
220     * Set the ability to start the session corresponding to
221     * @param ability The WantAgent for launch the ability
222     * @since 9
223     * @syscap SystemCapability.Multimedia.AVSession.Core
224     * @throws {BusinessError} 401 - parameter check failed
225     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
226     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
227     */
228    setLaunchAbility(ability: WantAgent, callback: AsyncCallback<void>): void;
229    setLaunchAbility(ability: WantAgent): Promise<void>;
230
231    /**
232     * Set audio stream id. Identifies the audio streams controlled by this session.
233     * If multiple streams are set, these streams will be simultaneously cast to the remote during the casting operation.
234     * @param streamId The audio streams
235     * @throws {BusinessError} 401 - parameter check failed
236     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
237     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
238     * @syscap SystemCapability.Multimedia.AVSession.Core
239     * @since 10
240     */
241    setAudioStreamId(streamIds: Array<number>, callback: AsyncCallback<void>): void;
242    setAudioStreamId(streamIds: Array<number>): Promise<void>;
243
244    /**
245     * Get the current session's own controller
246     * @returns The instance of {@link AVSessionController}
247     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
248     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
249     * @syscap SystemCapability.Multimedia.AVSession.Core
250     * @since 9
251     */
252    getController(callback: AsyncCallback<AVSessionController>): void;
253    getController(): Promise<AVSessionController>;
254
255    /**
256     * Get output device information
257     * @returns The instance of {@link OutputDeviceInfo}
258     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
259     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
260     * @syscap SystemCapability.Multimedia.AVSession.Core
261     * @since 9
262     */
263    getOutputDevice(callback: AsyncCallback<OutputDeviceInfo>): void;
264    getOutputDevice(): Promise<OutputDeviceInfo>;
265
266    /**
267     * Register or unregister playback command callback.
268     * As long as it is registered, it means that the ability supports this command.
269     * If you cancel the callback, you need to call off {@link off}
270     * When canceling the callback, need to update the supported commands list.
271     * Each playback command only supports registering one callback,
272     * and the new callback will replace the previous one.
273     * @param type Command to register.
274     * @param callback Used to handle callback commands
275     * @throws {BusinessError} 401 - parameter check failed
276     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
277     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
278     * @syscap SystemCapability.Multimedia.AVSession.Core
279     * @since 9
280     */
281    on(type: 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind', callback: () => void): void;
282    off(type: 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind', callback?: () => void): void;
283
284    /**
285     * Register or unregister seek command callback
286     * @param type Registration Type 'seek'
287     * @param callback Used to handle seek command.The callback provide the seek time(ms)
288     * @throws {BusinessError} 401 - parameter check failed
289     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
290     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
291     * @syscap SystemCapability.Multimedia.AVSession.Core
292     * @since 9
293     */
294    on(type: 'seek', callback: (time: number) => void): void;
295    off(type: 'seek', callback?: (time: number) => void): void;
296
297    /**
298     * Register or unregister setSpeed command callback
299     * @param type Registration Type 'setSpeed'
300     * @param callback Used to handle setSpeed command.The callback provide the speed value
301     * @throws {BusinessError} 401 - parameter check failed
302     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
303     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
304     * @syscap SystemCapability.Multimedia.AVSession.Core
305     * @since 9
306     */
307    on(type: 'setSpeed', callback: (speed: number) => void): void;
308    off(type: 'setSpeed', callback?: (speed: number) => void): void;
309
310    /**
311     * Register or unregister setLoopMode command callback
312     * @param type Registration Type 'setLoopMode'
313     * @param callback Used to handle setLoopMode command.The callback provide the {@link LoopMode}
314     * @throws {BusinessError} 401 - parameter check failed
315     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
316     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
317     * @syscap SystemCapability.Multimedia.AVSession.Core
318     * @since 9
319     */
320    on(type: 'setLoopMode', callback: (mode: LoopMode) => void): void;
321    off(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void;
322
323    /**
324     * Register or unregister toggle favorite command callback
325     * @param type Registration Type 'toggleFavorite'
326     * @param callback Used to handle toggleFavorite command.The callback provide
327     * the assetId for which the favorite status needs to be switched.
328     * @throws {BusinessError} 401 - parameter check failed
329     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
330     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
331     * @syscap SystemCapability.Multimedia.AVSession.Core
332     * @since 9
333     */
334    on(type: 'toggleFavorite', callback: (assetId: string) => void): void;
335    off(type: 'toggleFavorite', callback?: (assetId: string) => void): void;
336
337    /**
338     * Register or unregister media key handling callback
339     * @param type Registration Type
340     * @param callback Used to handle key events.The callback provide the KeyEvent
341     * @throws {BusinessError} 401 - parameter check failed
342     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
343     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
344     * @syscap SystemCapability.Multimedia.AVSession.Core
345     * @since 9
346     */
347    on(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void;
348    off(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void;
349
350    /**
351     * Register or unregister session output device change callback
352     * @param type Registration Type
353     * @param callback Used to handle output device changed.
354     * The callback provide the new device info {@link OutputDeviceInfo}
355     * @throws {BusinessError} 401 - parameter check failed
356     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
357     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
358     * @syscap SystemCapability.Multimedia.AVSession.Core
359     * @since 9
360     */
361    on(type: 'outputDeviceChange', callback: (device: OutputDeviceInfo) => void): void;
362    off(type: 'outputDeviceChange', callback?: (device: OutputDeviceInfo) => void): void;
363
364    /**
365     * Activate the session, indicating that the session can accept control commands
366     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
367     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
368     * @syscap SystemCapability.Multimedia.AVSession.Core
369     * @since 9
370     */
371    activate(callback: AsyncCallback<void>): void;
372    activate(): Promise<void>;
373
374    /**
375     * Deactivate the session, indicating that the session not ready to accept control commands
376     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
377     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
378     * @syscap SystemCapability.Multimedia.AVSession.Core
379     * @since 9
380     */
381    deactivate(callback: AsyncCallback<void>): void;
382    deactivate(): Promise<void>;
383
384    /**
385     * Destroy this session, the server will clean up the session resources
386     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
387     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
388     * @syscap SystemCapability.Multimedia.AVSession.Core
389     * @since 9
390     */
391    destroy(callback: AsyncCallback<void>): void;
392    destroy(): Promise<void>;
393  }
394
395  /**
396   * The metadata of the current media.Used to set the properties of the current media file
397   * @interface AVMetadata
398   * @syscap SystemCapability.Multimedia.AVSession.Core
399   * @since 9
400   */
401  interface AVMetadata {
402    /**
403     * Unique ID used to represent this media.
404     * @syscap SystemCapability.Multimedia.AVSession.Core
405     * @since 9
406     */
407    assetId: string;
408    /**
409     * The title of this media, for display in media center.
410     * @syscap SystemCapability.Multimedia.AVSession.Core
411     * @since 9
412     */
413    title?: string;
414    /**
415     * The artist of this media
416     * @syscap SystemCapability.Multimedia.AVSession.Core
417     * @since 9
418     */
419    artist?: string;
420    /**
421     * The author of this media
422     * @syscap SystemCapability.Multimedia.AVSession.Core
423     * @since 9
424     */
425    author?: string;
426    /**
427     * The album of this media
428     * @syscap SystemCapability.Multimedia.AVSession.Core
429     * @since 9
430     */
431    album?: string;
432    /**
433     * The writer of this media
434     * @syscap SystemCapability.Multimedia.AVSession.Core
435     * @since 9
436     */
437    writer?: string;
438    /**
439     * The composer of this media
440     * @syscap SystemCapability.Multimedia.AVSession.Core
441     * @since 9
442     */
443    composer?: string;
444    /**
445     * The duration of this media, used to automatically calculate playback position
446     * @syscap SystemCapability.Multimedia.AVSession.Core
447     * @since 9
448     */
449    duration?: number;
450    /**
451     * The image of the media as a {@link PixelMap} or an uri formatted String,
452     * used to display in media center.
453     * @syscap SystemCapability.Multimedia.AVSession.Core
454     * @since 9
455     */
456    mediaImage?: image.PixelMap | string;
457    /**
458     * The publishDate of the media
459     * @syscap SystemCapability.Multimedia.AVSession.Core
460     * @since 9
461     */
462    publishDate?: Date;
463    /**
464     * The subtitle of the media, used for display
465     * @syscap SystemCapability.Multimedia.AVSession.Core
466     * @since 9
467     */
468    subtitle?: string;
469    /**
470     * The discription of the media, used for display
471     * @syscap SystemCapability.Multimedia.AVSession.Core
472     * @since 9
473     */
474    description?: string;
475    /**
476     * The lyric of the media, it should be in standard lyric format
477     * @syscap SystemCapability.Multimedia.AVSession.Core
478     * @since 9
479     */
480    lyric?: string;
481    /**
482     * The previous playable media id.
483     * Used to tell the controller if there is a previous playable media
484     * @syscap SystemCapability.Multimedia.AVSession.Core
485     * @since 9
486     */
487    previousAssetId?: string;
488    /**
489     * The next playable media id.
490     * Used to tell the controller if there is a next playable media
491     * @syscap SystemCapability.Multimedia.AVSession.Core
492     * @since 9
493     */
494    nextAssetId?: string;
495  }
496
497  /**
498   * Used to indicate the playback state of the current media.
499   * If the playback state of the media changes, it needs to be updated synchronously
500   * @interface AVPlaybackState
501   * @syscap SystemCapability.Multimedia.AVSession.Core
502   * @since 9
503   */
504  interface AVPlaybackState {
505    /**
506     * Current playback state. See {@link PlaybackState}
507     * @syscap SystemCapability.Multimedia.AVSession.Core
508     * @since 9
509     */
510    state?: PlaybackState;
511    /**
512     * Current playback speed
513     * @syscap SystemCapability.Multimedia.AVSession.Core
514     * @since 9
515     */
516    speed?: number;
517    /**
518     * Current playback position of this media. See {@link PlaybackPosition}
519     * @syscap SystemCapability.Multimedia.AVSession.Core
520     * @since 9
521     */
522    position?: PlaybackPosition;
523    /**
524     * The current buffered time, the maximum playable position
525     * @syscap SystemCapability.Multimedia.AVSession.Core
526     * @since 9
527     */
528    bufferedTime?: number;
529    /**
530     * Current playback loop mode. See {@link LoopMode}
531     * @syscap SystemCapability.Multimedia.AVSession.Core
532     * @since 9
533     */
534    loopMode?: LoopMode;
535    /**
536     * Current Favorite Status
537     * @syscap SystemCapability.Multimedia.AVSession.Core
538     * @since 9
539     */
540    isFavorite?: boolean;
541  }
542
543  /**
544   * Playback position defination
545   * @interface PlaybackPosition
546   * @syscap SystemCapability.Multimedia.AVSession.Core
547   * @since 9
548   */
549  interface PlaybackPosition {
550    /**
551     * Elapsed time(position) of this media set by the app.
552     * @syscap SystemCapability.Multimedia.AVSession.Core
553     * @since 9
554     */
555    elapsedTime: number;
556    /**
557     * Record the system time when elapsedTime is set.
558     * @syscap SystemCapability.Multimedia.AVSession.Core
559     * @since 9
560     */
561    updateTime: number;
562  }
563  /**
564   * Target Device Information Definition
565   * @interface OutputDeviceInfo
566   * @syscap SystemCapability.Multimedia.AVSession.Core
567   * @since 9
568   */
569  interface OutputDeviceInfo {
570    /**
571     * Whether the remote device
572     * @since 9
573     */
574    isRemote: boolean;
575    /**
576     * Audio device id.The length of the audioDeviceId array is greater than 1
577     * if output to multiple devices at the same time.
578     * @since 9
579     */
580    audioDeviceId: Array<number>;
581    /**
582     * Device name. The length of the deviceName array is greater than 1
583     * if output to multiple devices at the same time.
584     * @since 9
585     */
586    deviceName: Array<string>;
587  }
588  /**
589   * Loop Play Mode Definition
590   * @enum {number}
591   * @syscap SystemCapability.Multimedia.AVSession.Core
592   * @since 9
593   */
594  enum LoopMode {
595    /**
596     * The default mode is sequential playback
597     * @since 9
598     */
599    LOOP_MODE_SEQUENCE = 0,
600
601    /**
602     * Single loop mode
603     * @since 9
604     */
605    LOOP_MODE_SINGLE = 1,
606
607    /**
608     * List loop mode
609     * @since 9
610     */
611    LOOP_MODE_LIST = 2,
612
613    /**
614     * Shuffle playback mode
615     * @since 9
616     */
617    LOOP_MODE_SHUFFLE = 3,
618  }
619
620  /**
621   * Definition of current playback state
622   * @enum {number}
623   * @syscap SystemCapability.Multimedia.AVSession.Core
624   * @since 9
625   */
626  enum PlaybackState {
627    /**
628     * Initial state. The initial state of media file
629     * @since 9
630     */
631    PLAYBACK_STATE_INITIAL = 0,
632
633    /**
634     * Preparing state. Indicates that the media file is not ready to play,
635     * the media is loading or buffering
636     * @since 9
637     */
638    PLAYBACK_STATE_PREPARE = 1,
639
640    /**
641     * Playing state.
642     * @since 9
643     */
644    PLAYBACK_STATE_PLAY = 2,
645
646    /**
647     * Paused state.
648     * @since 9
649     */
650    PLAYBACK_STATE_PAUSE = 3,
651
652    /**
653     * Fast forwarding state.
654     * @since 9
655     */
656    PLAYBACK_STATE_FAST_FORWARD = 4,
657
658    /**
659     * Rewinding state.
660     * @since 9
661     */
662    PLAYBACK_STATE_REWIND = 5,
663
664    /**
665     * Stopped state.The server will clear the media playback position and other information.
666     * @since 9
667     */
668    PLAYBACK_STATE_STOP = 6,
669  }
670
671  /**
672   * The description of the session
673   * @interface AVSessionDescriptor
674   * @syscap SystemCapability.Multimedia.AVSession.Manager
675   * @systemapi
676   * @since 9
677   */
678  interface AVSessionDescriptor {
679    /**
680     * Unique ID of the session
681     * @since 9
682     */
683    sessionId: string;
684    /**
685     * Session type, currently supports audio or video
686     * @since 9
687     */
688    type: AVSessionType;
689    /**
690     * The session tag set by the application
691     * @since 9
692     */
693    sessionTag: string;
694    /**
695     * The elementName of the ability that created this session. See {@link ElementName} in bundle/elementName.d.ts
696     * @since 9
697     */
698    elementName: ElementName;
699    /**
700     * Session active state
701     * @since 9
702     */
703    isActive: boolean;
704    /**
705     * Is it the top priority session
706     * @since 9
707     */
708    isTopSession: boolean;
709    /**
710     * The current output device information.
711     * It will be undefined if this is a local session.
712     * @since 9
713     */
714    outputDevice: OutputDeviceInfo;
715  }
716
717  /**
718   * Session controller,used to control media playback and get media information
719   * @interface AVSessionController
720   * @syscap SystemCapability.Multimedia.AVSession.Core
721   * @since 9
722   */
723  interface AVSessionController {
724    /**
725     * Unique session Id
726     * @syscap SystemCapability.Multimedia.AVSession.Core
727     * @since 9
728     */
729    readonly sessionId: string;
730    /**
731     * Get the playback status of the current session
732     * @returns AVPlaybackState {@link AVPlaybackState}
733     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
734     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
735     * @throws {BusinessError} {@link #ERR_CODE_CONTROLLER_NOT_EXIST} - controller does not exist
736     * @since 9
737     */
738    getAVPlaybackState(callback: AsyncCallback<AVPlaybackState>): void;
739    getAVPlaybackState(): Promise<AVPlaybackState>;
740
741    /**
742     * Get the metadata of the current session
743     * @returns AVMetadata {@link AVMetadata}
744     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
745     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
746     * @throws {BusinessError} {@link #ERR_CODE_CONTROLLER_NOT_EXIST} - controller does not exist
747     * @since 9
748     */
749    getAVMetadata(callback: AsyncCallback<AVMetadata>): void;
750    getAVMetadata(): Promise<AVMetadata>;
751
752    /**
753     * Get output device information
754     * @returns The instance of {@link OutputDeviceInfo}
755     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
756     * @throws {BusinessError} {@link #ERR_CODE_CONTROLLER_NOT_EXIST} - controller does not exist
757     * @syscap SystemCapability.Multimedia.AVSession.Core
758     * @since 9
759     */
760    getOutputDevice(callback: AsyncCallback<OutputDeviceInfo>): void;
761    getOutputDevice(): Promise<OutputDeviceInfo>;
762
763    /**
764     * Send media key event to this session
765     * @param event The KeyEvent
766     * @throws {BusinessError} 401 - parameter check failed
767     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
768     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
769     * @throws {BusinessError} {@link #ERR_CODE_CONTROLLER_NOT_EXIST} - controller does not exist
770     * @throws {BusinessError} {@link #ERR_CODE_COMMAND_INVALID} - command not supported
771     * @throws {BusinessError} {@link #ERR_CODE_SESSION_INACTIVE} - session inactive
772     * @since 9
773     */
774    sendAVKeyEvent(event: KeyEvent, callback: AsyncCallback<void>): void;
775    sendAVKeyEvent(event: KeyEvent): Promise<void>;
776
777    /**
778     * Get the {@link WantAgent} of this session that can launch the session ability
779     * @returns WantAgent {@link WantAgent}
780     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
781     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
782     * @throws {BusinessError} {@link #ERR_CODE_CONTROLLER_NOT_EXIST} - controller does not exist
783     * @since 9
784     */
785    getLaunchAbility(callback: AsyncCallback<WantAgent>): void;
786    getLaunchAbility(): Promise<WantAgent>;
787
788    /**
789     * Get the adjusted playback position. The time automatically calculated by the system
790     * taking into account factors such as playback status, playback speed, and application update time.
791     * @returns current playback position in ms.Note that the returns value of each call will be different.
792     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
793     * @throws {BusinessError} {@link #ERR_CODE_CONTROLLER_NOT_EXIST} - controller does not exist
794     * @since 9
795     */
796    getRealPlaybackPositionSync(): number;
797
798    /**
799     * Check if the current session is active
800     * @returns the active state
801     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
802     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
803     * @throws {BusinessError} {@link #ERR_CODE_CONTROLLER_NOT_EXIST} - controller does not exist
804     * @since 9
805     */
806    isActive(callback: AsyncCallback<boolean>): void;
807    isActive(): Promise<boolean>;
808
809    /**
810     * Destroy the server controller
811     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
812     * @throws {BusinessError} {@link #ERR_CODE_CONTROLLER_NOT_EXIST} - controller does not exist
813     * @since 9
814     */
815    destroy(callback: AsyncCallback<void>): void;
816    destroy(): Promise<void>;
817
818    /**
819     * Get commands supported by the current session
820     * @returns An array of AVControlCommandType {@link AVControlCommandType}
821     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
822     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
823     * @throws {BusinessError} {@link #ERR_CODE_CONTROLLER_NOT_EXIST} - controller does not exist
824     * @since 9
825     */
826    getValidCommands(callback: AsyncCallback<Array<AVControlCommandType>>): void;
827    getValidCommands(): Promise<Array<AVControlCommandType>>;
828
829    /**
830     * Send control commands to this session
831     * @param command The command to be send. See {@link AVControlCommand}
832     * @throws {BusinessError} 401 - parameter check failed
833     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
834     * @throws {BusinessError} {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist
835     * @throws {BusinessError} {@link #ERR_CODE_CONTROLLER_NOT_EXIST} - controller does not exist
836     * @throws {BusinessError} {@link #ERR_CODE_COMMAND_INVALID} - command not supported
837     * @throws {BusinessError} {@link #ERR_CODE_SESSION_INACTIVE} - session inactive
838     * @throws {BusinessError} {@link #ERR_CODE_MESSAGE_OVERLOAD} - command or event overload
839     * @since 9
840     */
841    sendControlCommand(command: AVControlCommand, callback: AsyncCallback<void>): void;
842    sendControlCommand(command: AVControlCommand): Promise<void>;
843
844    /**
845     * Register or unregister metadata changed callback
846     * @param type 'metadataChange'
847     * @param filter The properties of {@link AVMetadata} that you cared about
848     * @param callback The callback used to handle metadata changed event.
849     * The callback function provides the {@link AVMetadata} parameter.
850     * It only contains the properties set in the filter.
851     * @throws {BusinessError} 401 - parameter check failed
852     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
853     * @throws {BusinessError} {@link #ERR_CODE_CONTROLLER_NOT_EXIST} - controller does not exist
854     * @since 9
855     */
856    on(type: 'metadataChange', filter: Array<keyof AVMetadata> | 'all', callback: (data: AVMetadata) => void);
857    off(type: 'metadataChange', callback?: (data: AVMetadata) => void);
858
859    /**
860     * Register or unregister playback state changed callback
861     * @param type 'playbackStateChange'
862     * @param filter The properties of {@link AVPlaybackState} that you cared about
863     * @param callback The callback used to handle playback state changed event.
864     * The callback function provides the {@link AVPlaybackState} parameter.
865     * @throws {BusinessError} 401 - parameter check failed
866     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
867     * @throws {BusinessError} {@link #ERR_CODE_CONTROLLER_NOT_EXIST} - controller does not exist
868     * @since 9
869     */
870    on(type: 'playbackStateChange', filter: Array<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void);
871    off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void);
872
873    /**
874     * Register or unregister current session destroyed callback
875     * @param type 'sessionDestroy'
876     * @param callback The callback used to handle current session destroyed event.
877     * @throws {BusinessError} 401 - parameter check failed
878     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
879     * @throws {BusinessError} {@link #ERR_CODE_CONTROLLER_NOT_EXIST} - controller does not exist
880     * @since 9
881     */
882    on(type: 'sessionDestroy', callback: () => void);
883    off(type: 'sessionDestroy', callback?: () => void);
884
885    /**
886     * Register or unregister the active state of this session changed callback
887     * @param type 'activeStateChange'
888     * @param callback The callback used to handle the active state of this session changed event.
889     * The callback function provides the changed session state.
890     * @throws {BusinessError} 401 - parameter check failed
891     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
892     * @throws {BusinessError} {@link #ERR_CODE_CONTROLLER_NOT_EXIST} - controller does not exist
893     * @since 9
894     */
895    on(type: 'activeStateChange', callback: (isActive: boolean) => void);
896    off(type: 'activeStateChange', callback?: (isActive: boolean) => void);
897
898    /**
899     * Register or unregister the valid commands of the session changed callback
900     * @param type 'validCommandChange'
901     * @param callback The callback used to handle the changes.
902     * The callback function provides an array of AVControlCommandType.
903     * @throws {BusinessError} 401 - parameter check failed
904     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
905     * @throws {BusinessError} {@link #ERR_CODE_CONTROLLER_NOT_EXIST} - controller does not exist
906     * @since 9
907     */
908    on(type: 'validCommandChange', callback: (commands: Array<AVControlCommandType>) => void);
909    off(type: 'validCommandChange', callback?: (commands: Array<AVControlCommandType>) => void);
910
911    /**
912     * Register or unregister session output device change callback
913     * @param type Registration Type
914     * @param callback Used to handle output device changed.
915     * The callback provide the new device info {@link OutputDeviceInfo}
916     * @throws {BusinessError} 401 - parameter check failed
917     * @throws {BusinessError} {@link #ERR_CODE_SERVICE_EXCEPTION} - server exception
918     * @throws {BusinessError} {@link #ERR_CODE_CONTROLLER_NOT_EXIST} - controller does not exist
919     * @syscap SystemCapability.Multimedia.AVSession.Core
920     * @since 9
921     */
922    on(type: 'outputDeviceChange', callback: (device: OutputDeviceInfo) => void): void;
923    off(type: 'outputDeviceChange', callback?: (device: OutputDeviceInfo) => void): void;
924  }
925
926  /**
927   * The type of control command
928   * @syscap SystemCapability.Multimedia.AVSession.Core
929   * @since 9
930   */
931  type AVControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' |
932                              'seek' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite';
933
934  /**
935   * The defination of command to be send to the session
936   * @interface AVControlCommand
937   * @syscap SystemCapability.Multimedia.AVSession.Core
938   * @since 9
939   */
940  interface AVControlCommand {
941    /**
942     * The command value {@link AVControlCommandType}
943     * @since 9
944     */
945    command: AVControlCommandType;
946    /**
947     * parameter of the command. Whether this command requires parameters, see {@link AVSessionCommand}
948     * seek command requires a number parameter
949     * setSpeed command requires a number parameter
950     * setLoopMode command requires a {@link LoopMode} parameter.
951     * toggleFavorite command requires assetId {@link AVMetadata.assetId} parameter
952     * other commands need no parameter
953     * @since 9
954     */
955    parameter?: LoopMode | string | number;
956  }
957
958  /**
959   * Enumerates ErrorCode types, returns in BusinessError.code.
960   * @enum {number}
961   * @syscap SystemCapability.Multimedia.AVSession.Core
962   * @since 9
963   */
964  enum AVSessionErrorCode {
965    /**
966     * Server exception
967     * @since 9
968     */
969    ERR_CODE_SERVICE_EXCEPTION = 6600101,
970
971    /**
972     * The session does not exist
973     * @since 9
974     */
975    ERR_CODE_SESSION_NOT_EXIST = 6600102,
976
977    /**
978     * The controller does not exist
979     * @since 9
980     */
981    ERR_CODE_CONTROLLER_NOT_EXIST = 6600103,
982
983    /**
984     * Remote connection error
985     * @since 9
986     */
987    ERR_CODE_REMOTE_CONNECTION_ERR = 6600104,
988
989    /**
990     * Command not supported
991     * @since 9
992     */
993    ERR_CODE_COMMAND_INVALID = 6600105,
994
995    /**
996     * Session inactive
997     * @since 9
998     */
999    ERR_CODE_SESSION_INACTIVE = 6600106,
1000
1001    /**
1002     * Command or event overload
1003     * @since 9
1004     */
1005    ERR_CODE_MESSAGE_OVERLOAD = 6600107,
1006  }
1007}
1008
1009export default avSession;
1010