• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (C) 2021 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 { ErrorCallback, AsyncCallback, Callback } from './basic';
17
18/**
19 * @name media
20 * @since 6
21 * @import import media from '@ohos.multimedia.media'
22 */
23declare namespace media {
24  /**
25   * Creates an AudioPlayer instance.
26   * @since 6
27   * @syscap SystemCapability.Multimedia.Media.AudioPlayer
28   * @import import media from '@ohos.multimedia.media'
29   * @return Returns an AudioPlayer instance if the operation is successful; returns null otherwise.
30   */
31  function createAudioPlayer(): AudioPlayer;
32
33  /**
34   * Creates an AudioRecorder instance.
35   * @since 6
36   * @syscap SystemCapability.Multimedia.Media.AudioRecorder
37   * @import import media from '@ohos.multimedia.media'
38   * @return Returns an AudioRecorder instance if the operation is successful; returns null otherwise.
39   */
40  function createAudioRecorder(): AudioRecorder;
41
42  /**
43   * Creates an VideoPlayer instance.
44   * @since 8
45   * @syscap SystemCapability.Multimedia.Media.VideoPlayer
46   * @import import media from '@ohos.multimedia.media'
47   * @param callback Callback used to return AudioPlayer instance if the operation is successful; returns null otherwise.
48   */
49  function createVideoPlayer(callback: AsyncCallback<VideoPlayer>): void;
50  /**
51   * Creates an VideoPlayer instance.
52   * @since 8
53   * @syscap SystemCapability.Multimedia.Media.VideoPlayer
54   * @import import media from '@ohos.multimedia.media'
55   * @return A Promise instance used to return VideoPlayer instance if the operation is successful; returns null otherwise.
56   */
57  function createVideoPlayer() : Promise<VideoPlayer>;
58
59  /**
60   * Creates an VideoRecorder instance.
61   * @since 8
62   * @syscap SystemCapability.Multimedia.Media.VideoRecorder
63   * @import import media from '@ohos.multimedia.media'
64   * @param callback Callback used to return AudioPlayer instance if the operation is successful; returns null otherwise.
65   */
66  function createVideoRecorder(callback: AsyncCallback<VideoRecorder>): void;
67  /**
68   * Creates an VideoRecorder instance.
69   * @since 8
70   * @syscap SystemCapability.Multimedia.Media.VideoRecorder
71   * @import import media from '@ohos.multimedia.media'
72   * @return A Promise instance used to return VideoRecorder instance if the operation is successful; returns null otherwise.
73   */
74  function createVideoRecorder(): Promise<VideoRecorder>;
75
76  /**
77   * Enumerates ErrorCode types, return in BusinessError::code
78   * @since 8
79   * @syscap SystemCapability.Multimedia.Media.Core
80   * @import import media from '@ohos.multimedia.media'
81   */
82  enum MediaErrorCode {
83    /**
84     * operation success.
85     * @since 8
86     * @syscap SystemCapability.Multimedia.Media.Core
87     */
88    MSERR_OK = 0,
89
90    /**
91     * malloc or new memory failed. maybe system have no memory.
92     * @since 8
93     * @syscap SystemCapability.Multimedia.Media.Core
94     */
95    MSERR_NO_MEMORY = 1,
96
97    /**
98     * no permission for the operation.
99     * @since 8
100     * @syscap SystemCapability.Multimedia.Media.Core
101     */
102    MSERR_OPERATION_NOT_PERMIT = 2,
103
104    /**
105     * invalid argument.
106     * @since 8
107     * @syscap SystemCapability.Multimedia.Media.Core
108     */
109    MSERR_INVALID_VAL = 3,
110
111    /**
112     * an IO error occurred.
113     * @since 8
114     * @syscap SystemCapability.Multimedia.Media.Core
115     */
116    MSERR_IO = 4,
117
118    /**
119     * operation time out.
120     * @since 8
121     * @syscap SystemCapability.Multimedia.Media.Core
122     */
123    MSERR_TIMEOUT = 5,
124
125    /**
126     * unknown error.
127     * @since 8
128     * @syscap SystemCapability.Multimedia.Media.Core
129     */
130    MSERR_UNKNOWN = 6,
131
132    /**
133     * media service died.
134     * @since 8
135     * @syscap SystemCapability.Multimedia.Media.Core
136     */
137    MSERR_SERVICE_DIED = 7,
138
139    /**
140     * operation is not permit in current state.
141     * @since 8
142     * @syscap SystemCapability.Multimedia.Media.Core
143     */
144    MSERR_INVALID_STATE = 8,
145
146    /**
147     * operation is not supported in current version.
148     * @since 8
149     * @syscap SystemCapability.Multimedia.Media.Core
150     */
151    MSERR_UNSUPPORTED = 9,
152  }
153
154  /**
155   * Enumerates buffering info type, for network playback.
156   * @since 8
157   * @syscap SystemCapability.Multimedia.Media.Core
158   * @import import media from '@ohos.multimedia.media'
159   */
160  enum BufferingInfoType {
161    /**
162     * begin to buffering
163     * @since 8
164     * @syscap SystemCapability.Multimedia.Media.Core
165     */
166    BUFFERING_START = 1,
167
168    /**
169     * end to buffering
170     * @since 8
171     * @syscap SystemCapability.Multimedia.Media.Core
172     */
173    BUFFERING_END = 2,
174
175    /**
176     * buffering percent
177     * @since 8
178     * @syscap SystemCapability.Multimedia.Media.Core
179     */
180    BUFFERING_PERCENT = 3,
181
182    /**
183     * cached duration in milliseconds
184     * @since 8
185     * @syscap SystemCapability.Multimedia.Media.Core
186     */
187    CACHED_DURATION = 4,
188  }
189
190  /**
191   * Describes audio playback states.
192   * @since 6
193   * @syscap SystemCapability.Multimedia.Media.AudioPlayer
194   * @import import media from '@ohos.multimedia.media'
195   */
196  type AudioState = 'idle' | 'playing' | 'paused' | 'stopped' | 'error';
197
198  /**
199   * Manages and plays audio. Before calling an AudioPlayer method, you must use createAudioPlayer()
200   * to create an AudioPlayer instance.
201   * @since 6
202   * @syscap SystemCapability.Multimedia.Media.AudioPlayer
203   */
204  interface AudioPlayer {
205    /**
206     * Starts audio playback.
207     * @since 6
208     * @syscap SystemCapability.Multimedia.Media.AudioPlayer
209     */
210    play(): void;
211
212    /**
213     * Pauses audio playback.
214     * @since 6
215     * @syscap SystemCapability.Multimedia.Media.AudioPlayer
216     */
217    pause(): void;
218
219    /**
220     * Stops audio playback.
221     * @since 6
222     * @syscap SystemCapability.Multimedia.Media.AudioPlayer
223     */
224    stop(): void;
225
226    /**
227     * Resets audio playback.
228     * @since 7
229     * @syscap SystemCapability.Multimedia.Media.AudioPlayer
230     */
231     reset(): void;
232
233    /**
234     * Jumps to the specified playback position.
235     * @since 6
236     * @syscap SystemCapability.Multimedia.Media.AudioPlayer
237     * @param timeMs Playback position to jump
238     */
239    seek(timeMs: number): void;
240
241    /**
242     * Sets the volume.
243     * @since 6
244     * @syscap SystemCapability.Multimedia.Media.AudioPlayer
245     * @param vol Relative volume. The value ranges from 0.00 to 1.00. The value 1 indicates the maximum volume (100%).
246     */
247    setVolume(vol: number): void;
248
249    /**
250     * Releases resources used for audio playback.
251     * @since 6
252     * @syscap SystemCapability.Multimedia.Media.AudioPlayer
253     */
254    release(): void;
255    /**
256    * get all track infos in MediaDescription, should be called after data loaded callback.
257    * @since 8
258    * @syscap SystemCapability.Multimedia.Media.AudioPlayer
259    * @param callback async callback return track info in MediaDescription.
260    */
261    getTrackDescription(callback: AsyncCallback<Array<MediaDescription>>): void;
262
263    /**
264    * get all track infos in MediaDescription, should be called after data loaded callback..
265    * @since 8
266    * @syscap SystemCapability.Multimedia.Media.AudioPlayer
267    * @param index  track index.
268    * @return A Promise instance used to return the track info in MediaDescription.
269    */
270    getTrackDescription() : Promise<Array<MediaDescription>>;
271
272    /**
273     * Listens for audio playback buffering events.
274     * @since 8
275     * @syscap SystemCapability.Multimedia.Media.AudioPlayer
276     * @param type Type of the playback buffering update event to listen for.
277     * @param callback Callback used to listen for the buffering update event, return BufferingInfoType and the value.
278     */
279    on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: number) => void): void;
280    /**
281     * Audio media URI. Mainstream audio formats are supported.
282     * local:fd://XXX, network:http://xxx
283     * @since 6
284     * @syscap SystemCapability.Multimedia.Media.AudioPlayer
285     */
286    src: string;
287
288    /**
289     * Whether to loop audio playback. The value true means to loop playback.
290     * @since 6
291     * @syscap SystemCapability.Multimedia.Media.AudioPlayer
292     */
293    loop: boolean;
294
295    /**
296     * Current playback position.
297     * @since 6
298     * @syscap SystemCapability.Multimedia.Media.AudioPlayer
299     */
300    readonly currentTime: number;
301
302    /**
303     * Playback duration, When the data source does not support seek, it returns - 1, such as a live broadcast scenario.
304     * @since 6
305     * @syscap SystemCapability.Multimedia.Media.AudioPlayer
306     */
307    readonly duration: number;
308
309    /**
310     * Playback state.
311     * @since 6
312     * @syscap SystemCapability.Multimedia.Media.AudioPlayer
313     */
314    readonly state: AudioState;
315
316    /**
317     * Listens for audio playback events.
318     * @since 6
319     * @syscap SystemCapability.Multimedia.Media.AudioPlayer
320     * @param type Type of the playback event to listen for.
321     * @param callback Callback used to listen for the playback event.
322     */
323    on(type: 'play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeChange', callback: () => void): void;
324
325    /**
326     * Listens for audio playback events.
327     * @since 6
328     * @syscap SystemCapability.Multimedia.Media.AudioPlayer
329     * @param type Type of the playback event to listen for.
330     * @param callback Callback used to listen for the playback event.
331     */
332    on(type: 'timeUpdate', callback: Callback<number>): void;
333
334    /**
335     * Listens for playback error events.
336     * @since 6
337     * @syscap SystemCapability.Multimedia.Media.AudioPlayer
338     * @param type Type of the playback error event to listen for.
339     * @param callback Callback used to listen for the playback error event.
340     */
341    on(type: 'error', callback: ErrorCallback): void;
342  }
343
344  /**
345   * Enumerates audio encoding formats, it will be deprecated after API8, use @CodecMimeType to replace.
346   * @since 6
347   * @syscap SystemCapability.Multimedia.Media.AudioRecorder
348   * @import import media from '@ohos.multimedia.media'
349   * @deprecated since 8
350   */
351  enum AudioEncoder {
352    /**
353     * Default audio encoding format, which is AMR-NB.
354     * @since 6
355     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
356     */
357    DEFAULT = 0,
358
359    /**
360     * Indicates the AMR-NB audio encoding format.
361     * @since 6
362     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
363     */
364    AMR_NB = 1,
365
366    /**
367     * Indicates the AMR-WB audio encoding format.
368     * @since 6
369     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
370     */
371    AMR_WB = 2,
372
373    /**
374     * Advanced Audio Coding Low Complexity (AAC-LC).
375     * @since 6
376     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
377     */
378    AAC_LC = 3,
379
380    /**
381     * High-Efficiency Advanced Audio Coding (HE-AAC).
382     * @since 6
383     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
384     */
385    HE_AAC = 4
386  }
387
388  /**
389   * Enumerates audio output formats, it will be deprecated after API8, use @ContainerFormatType to replace.
390   * @since 6
391   * @syscap SystemCapability.Multimedia.Media.AudioRecorder
392   * @import import media from '@ohos.multimedia.media'
393   * @deprecated since 8
394   */
395  enum AudioOutputFormat {
396    /**
397     * Default audio output format, which is Moving Pictures Expert Group 4 (MPEG-4).
398     * @since 6
399     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
400     */
401    DEFAULT = 0,
402
403    /**
404     * Indicates the Moving Picture Experts Group-4 (MPEG4) media format.
405     * @since 6
406     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
407     */
408    MPEG_4 = 2,
409
410    /**
411     * Indicates the Adaptive Multi-Rate Narrowband (AMR-NB) media format.
412     * @since 6
413     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
414     */
415    AMR_NB = 3,
416
417    /**
418     * Indicates the Adaptive Multi-Rate Wideband (AMR-WB) media format.
419     * @since 6
420     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
421     */
422    AMR_WB = 4,
423
424    /**
425     * Audio Data Transport Stream (ADTS), a transmission stream format of Advanced Audio Coding (AAC) audio.
426     * @since 6
427     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
428     */
429    AAC_ADTS = 6
430  }
431
432  /**
433   * Provides the geographical location definitions for media resources.
434   * @since 6
435   * @syscap SystemCapability.Multimedia.Media.Core
436   */
437  interface Location {
438    /**
439     * Latitude.
440     * @since 6
441     * @syscap SystemCapability.Multimedia.Media.Core
442     */
443    latitude: number;
444
445    /**
446     * Longitude.
447     * @since 6
448     * @syscap SystemCapability.Multimedia.Media.Core
449     */
450    longitude: number;
451  }
452
453  /**
454   * Provides the audio recorder configuration definitions.
455   * @since 6
456   * @syscap SystemCapability.Multimedia.Media.AudioRecorder
457   */
458  interface AudioRecorderConfig {
459    /**
460     * Audio encoding format. The default value is DEFAULT, it will be deprecated after API8.
461     * use "audioEncoderMime" instead.
462     * @since 6
463     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
464     * @deprecated since 8
465     */
466    audioEncoder?: AudioEncoder;
467
468    /**
469     * Audio encoding bit rate.
470     * @since 6
471     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
472     */
473    audioEncodeBitRate?: number;
474
475    /**
476     * Audio sampling rate.
477     * @since 6
478     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
479     */
480    audioSampleRate?: number;
481
482    /**
483     * Number of audio channels.
484     * @since 6
485     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
486     */
487    numberOfChannels?: number;
488
489    /**
490     * Audio output format. The default value is DEFAULT, it will be deprecated after API8.
491     * it will be replaced with "fileFormat".
492     * @since 6
493     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
494     * @deprecated since 8
495     */
496    format?: AudioOutputFormat;
497
498    /**
499     * Audio output uri.support two kind of uri now.
500     * format like: scheme + "://" + "context".
501     * fd:    fd://fd
502     * @since 6
503     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
504     */
505    uri: string;
506
507    /**
508     * Geographical location information.
509     * @since 6
510     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
511     */
512    location?: Location;
513
514    /**
515     * audio encoding format MIME. it used to replace audioEncoder.
516     * @since 8
517     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
518     */
519    audioEncoderMime?: CodecMimeType;
520    /**
521     * output file format. see @ContainerFormatType , it used to replace "format".
522     * @since 8
523     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
524     */
525    fileFormat?: ContainerFormatType;
526  }
527
528  /**
529   * Manages and record audio. Before calling an AudioRecorder method, you must use createAudioRecorder()
530   * to create an AudioRecorder instance.
531   * @since 6
532   * @syscap SystemCapability.Multimedia.Media.AudioRecorder
533   */
534  interface AudioRecorder {
535    /**
536     * Prepares for recording.
537     * @since 6
538     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
539     * @param config Recording parameters.
540     */
541    prepare(config: AudioRecorderConfig): void;
542
543    /**
544     * Starts audio recording.
545     * @since 6
546     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
547     */
548    start(): void;
549
550    /**
551     * Pauses audio recording.
552     * @since 6
553     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
554     */
555    pause(): void;
556
557    /**
558     * Resumes audio recording.
559     * @since 6
560     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
561     */
562    resume(): void;
563
564    /**
565     * Stops audio recording.
566     * @since 6
567     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
568     */
569    stop(): void;
570
571    /**
572     * Releases resources used for audio recording.
573     * @since 6
574     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
575     */
576    release(): void;
577
578    /**
579     * Resets audio recording.
580     * Before resetting audio recording, you must call stop() to stop recording. After audio recording is reset,
581     * you must call prepare() to set the recording configurations for another recording.
582     * @since 6
583     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
584     */
585    reset(): void;
586
587    /**
588     * Listens for audio recording events.
589     * @since 6
590     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
591     * @param type Type of the audio recording event to listen for.
592     * @param callback Callback used to listen for the audio recording event.
593     */
594    on(type: 'prepare' | 'start' | 'pause' | 'resume' | 'stop' | 'release' | 'reset', callback: () => void): void;
595
596    /**
597     * Listens for audio recording error events.
598     * @since 6
599     * @syscap SystemCapability.Multimedia.Media.AudioRecorder
600     * @param type Type of the audio recording error event to listen for.
601     * @param callback Callback used to listen for the audio recording error event.
602     */
603    on(type: 'error', callback: ErrorCallback): void;
604  }
605
606  /**
607  * Describes video recorder states.
608  * @since 8
609  * @syscap SystemCapability.Multimedia.Media.VideoRecorder
610  */
611  type VideoRecordState = 'idle' | 'prepared' | 'playing' | 'paused' | 'stopped' | 'error';
612
613  /**
614   * Manages and record video. Before calling an VideoRecorder method, you must use createVideoRecorder()
615   * to create an VideoRecorder instance.
616   * @since 8
617   * @syscap SystemCapability.Multimedia.Media.VideoRecorder
618   */
619  interface VideoRecorder {
620    /**
621     * Prepares for recording.
622     * @since 8
623     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
624     * @param config Recording parameters.
625     * @param callback A callback instance used to return when prepare completed.
626     */
627    prepare(config: VideoRecorderConfig, callback: AsyncCallback<void>): void;
628    /**
629     * Prepares for recording.
630     * @since 8
631     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
632     * @param config Recording parameters.
633     * @return A Promise instance used to return when prepare completed.
634     */
635    prepare(config: VideoRecorderConfig): Promise<void>;
636    /**
637     * get input surface.it must be called between prepare completed and start.
638     * @since 8
639     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
640     * @param callback Callback used to return the input surface id in string.
641     */
642    getInputSurface(callback: AsyncCallback<string>): void;
643    /**
644     * get input surface. it must be called between prepare completed and start.
645     * @since 8
646     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
647     * @return A Promise instance used to return the input surface id in string.
648     */
649    getInputSurface(): Promise<string>;
650    /**
651     * Starts video recording.
652     * @since 8
653     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
654     * @param callback A callback instance used to return when start completed.
655     */
656    start(callback: AsyncCallback<void>): void;
657    /**
658     * Starts video recording.
659     * @since 8
660     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
661     * @return A Promise instance used to return when start completed.
662     */
663    start(): Promise<void>;
664    /**
665     * Pauses video recording.
666     * @since 8
667     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
668     * @param callback A callback instance used to return when pause completed.
669     */
670    pause(callback: AsyncCallback<void>): void;
671    /**
672     * Pauses video recording.
673     * @since 8
674     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
675     * @return A Promise instance used to return when pause completed.
676     */
677    pause(): Promise<void>;
678    /**
679     * Resumes video recording.
680     * @since 8
681     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
682     * @param callback A callback instance used to return when resume completed.
683     */
684    resume(callback: AsyncCallback<void>): void;
685    /**
686     * Resumes video recording.
687     * @since 8
688     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
689     * @return A Promise instance used to return when resume completed.
690     */
691    resume(): Promise<void>;
692    /**
693     * Stops video recording.
694     * @since 8
695     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
696     * @param callback A callback instance used to return when stop completed.
697     */
698    stop(callback: AsyncCallback<void>): void;
699    /**
700     * Stops video recording.
701     * @since 8
702     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
703     * @return A Promise instance used to return when stop completed.
704     */
705    stop(): Promise<void>;
706    /**
707     * Releases resources used for video recording.
708     * @since 8
709     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
710     * @param callback A callback instance used to return when release completed.
711     */
712    release(callback: AsyncCallback<void>): void;
713    /**
714      * Releases resources used for video recording.
715      * @since 8
716      * @syscap SystemCapability.Multimedia.Media.VideoRecorder
717      * @return A Promise instance used to return when release completed.
718      */
719    release(): Promise<void>;
720    /**
721     * Resets video recording.
722     * Before resetting video recording, you must call stop() to stop recording. After video recording is reset,
723     * you must call prepare() to set the recording configurations for another recording.
724     * @since 8
725     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
726     * @param callback A callback instance used to return when reset completed.
727     */
728    reset(callback: AsyncCallback<void>): void;
729     /**
730      * Resets video recording.
731      * Before resetting video recording, you must call stop() to stop recording. After video recording is reset,
732      * you must call prepare() to set the recording configurations for another recording.
733      * @since 8
734      * @syscap SystemCapability.Multimedia.Media.VideoRecorder
735      * @return A Promise instance used to return when reset completed.
736      */
737    reset(): Promise<void>;
738    /**
739     * Listens for video recording error events.
740     * @since 8
741     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
742     * @param type Type of the video recording error event to listen for.
743     * @param callback Callback used to listen for the video recording error event.
744     */
745    on(type: 'error', callback: ErrorCallback): void;
746
747    /**
748     * video recorder state.
749     * @since 8
750     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
751     */
752     readonly state: VideoRecordState;
753  }
754
755  /**
756   * Describes video playback states.
757   * @since 8
758   * @syscap SystemCapability.Multimedia.Media.VideoPlayer
759   */
760  type VideoPlayState = 'idle' | 'prepared' | 'playing' | 'paused' | 'stopped' | 'error';
761
762  /**
763   * Enumerates playback speed.
764   * @since 8
765   * @syscap SystemCapability.Multimedia.Media.VideoPlayer
766   */
767  enum PlaybackSpeed {
768    /**
769     * playback at 0.75x normal speed
770     * @since 8
771     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
772     */
773    SPEED_FORWARD_0_75_X = 0,
774    /**
775     * playback at normal speed
776     * @since 8
777     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
778     */
779    SPEED_FORWARD_1_00_X = 1,
780    /**
781     * playback at 1.25x normal speed
782     * @since 8
783     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
784     */
785    SPEED_FORWARD_1_25_X = 2,
786    /**
787     * playback at 1.75x normal speed
788     * @since 8
789     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
790     */
791    SPEED_FORWARD_1_75_X = 3,
792    /**
793     * playback at 2.0x normal speed
794     * @since 8
795     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
796     */
797    SPEED_FORWARD_2_00_X = 4,
798  }
799
800  /**
801   * Manages and plays video. Before calling an video method, you must use createVideoPlayer() to create an VideoPlayer
802   * instance.
803   * @since 8
804   * @syscap SystemCapability.Multimedia.Media.VideoPlayer
805   * @import import media from '@ohos.multimedia.media'
806   */
807 interface VideoPlayer {
808    /**
809     * set display surface.
810     * @since 8
811     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
812     * @param surfaceId surface id, video player will use this id get a surface instance.
813     * @return A Promise instance used to return when release output buffer completed.
814     */
815    setDisplaySurface(surfaceId: string, callback: AsyncCallback<void>): void;
816    /**
817    * set display surface.
818    * @since 8
819    * @syscap SystemCapability.Multimedia.Media.VideoPlayer
820    * @param surfaceId surface id, video player will use this id get a surface instance.
821    * @return A Promise instance used to return when release output buffer completed.
822    */
823    setDisplaySurface(surfaceId: string): Promise<void>;
824    /**
825     * prepare video playback, it will request resource for playing.
826     * @since 8
827     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
828     * @param callback A callback instance used to return when prepare completed.
829     */
830    prepare(callback: AsyncCallback<void>): void;
831     /**
832      * prepare video playback, it will request resource for playing.
833      * @since 8
834      * @syscap SystemCapability.Multimedia.Media.VideoPlayer
835      * @return A Promise instance used to return when prepare completed.
836      */
837    prepare(): Promise<void>;
838    /**
839     * Starts video playback.
840     * @since 8
841     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
842     * @param callback A callback instance used to return when start completed.
843     */
844    play(callback: AsyncCallback<void>): void;
845     /**
846      * Starts video playback.
847      * @since 8
848      * @syscap SystemCapability.Multimedia.Media.VideoPlayer
849      * @return A Promise instance used to return when start completed.
850      */
851    play(): Promise<void>;
852    /**
853     * Pauses video playback.
854     * @since 8
855     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
856     * @param callback A callback instance used to return when pause completed.
857     */
858    pause(callback: AsyncCallback<void>): void;
859     /**
860      * Pauses video playback.
861      * @since 8
862      * @syscap SystemCapability.Multimedia.Media.VideoPlayer
863      * @return A Promise instance used to return when pause completed.
864      */
865    pause(): Promise<void>;
866    /**
867     * Stops video playback.
868     * @since 8
869     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
870     * @param callback A callback instance used to return when stop completed.
871     */
872    stop(callback: AsyncCallback<void>): void;
873     /**
874      * Stops video playback.
875      * @since 8
876      * @syscap SystemCapability.Multimedia.Media.VideoPlayer
877      * @return A Promise instance used to return when stop completed.
878      */
879    stop(): Promise<void>;
880    /**
881     * Resets video playback, it will release the resource.
882     * @since 8
883     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
884     * @param callback A callback instance used to return when reset completed.
885     */
886    reset(callback: AsyncCallback<void>): void;
887     /**
888      * Resets video playback, it will release the resource.
889      * @since 8
890      * @syscap SystemCapability.Multimedia.Media.VideoPlayer
891      * @return A Promise instance used to return when reset completed.
892      */
893    reset(): Promise<void>;
894    /**
895     * Jumps to the specified playback position by default SeekMode(SEEK_CLOSEST),
896     * the performance may be not the best.
897     * @since 8
898     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
899     * @param timeMs Playback position to jump
900     * @param callback A callback instance used to return when seek completed
901     * and return the seeking position result.
902     */
903    seek(timeMs: number, callback: AsyncCallback<number>): void;
904    /**
905     * Jumps to the specified playback position.
906     * @since 8
907     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
908     * @param timeMs Playback position to jump
909     * @param mode seek mode, see @SeekMode .
910     * @param callback A callback instance used to return when seek completed
911     * and return the seeking position result.
912     */
913     seek(timeMs: number, mode:SeekMode, callback: AsyncCallback<number>): void;
914     /**
915      * Jumps to the specified playback position.
916      * @since 8
917      * @syscap SystemCapability.Multimedia.Media.VideoPlayer
918      * @param timeMs Playback position to jump
919      * @param mode seek mode, see @SeekMode .
920      * @return A Promise instance used to return when seek completed
921      * and return the seeking position result.
922      */
923    seek(timeMs: number, mode?:SeekMode): Promise<number>;
924    /**
925     * Sets the volume.
926     * @since 8
927     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
928     * @param vol Relative volume. The value ranges from 0.00 to 1.00. The value 1 indicates the maximum volume (100%).
929     * @param callback A callback instance used to return when set volume completed.
930     */
931    setVolume(vol: number, callback: AsyncCallback<void>): void;
932     /**
933      * Sets the volume.
934      * @since 8
935      * @syscap SystemCapability.Multimedia.Media.VideoPlayer
936      * @param vol Relative volume. The value ranges from 0.00 to 1.00. The value 1 indicates the maximum volume (100%).
937      * @return A Promise instance used to return when set volume completed.
938      */
939    setVolume(vol: number): Promise<void>;
940    /**
941     * Releases resources used for video playback.
942     * @since 8
943     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
944     * @param callback A callback instance used to return when release completed.
945     */
946    release(callback: AsyncCallback<void>): void;
947     /**
948      * Releases resources used for video playback.
949      * @since 8
950      * @syscap SystemCapability.Multimedia.Media.VideoPlayer
951      * @return A Promise instance used to return when release completed.
952      */
953    release(): Promise<void>;
954    /**
955    * get all track infos in MediaDescription, should be called after data loaded callback.
956    * @since 8
957    * @syscap SystemCapability.Multimedia.Media.VideoPlayer
958    * @param callback async callback return track info in MediaDescription.
959    */
960    getTrackDescription(callback: AsyncCallback<Array<MediaDescription>>): void;
961
962    /**
963    * get all track infos in MediaDescription, should be called after data loaded callback..
964    * @since 8
965    * @syscap SystemCapability.Multimedia.Media.VideoPlayer
966    * @param index  track index.
967    * @return A Promise instance used to return the track info in MediaDescription.
968    */
969    getTrackDescription() : Promise<Array<MediaDescription>>;
970
971    /**
972     * media url. Mainstream video formats are supported.
973     * local:fd://XXX, network:http://xxx
974     * @since 8
975     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
976     */
977    url: string;
978
979    /**
980     * Whether to loop video playback. The value true means to loop playback.
981     * @since 8
982     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
983     */
984    loop: boolean;
985
986    /**
987     * Current playback position.
988     * @since 8
989     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
990     */
991    readonly currentTime: number;
992
993    /**
994     * Playback duration, if -1 means cannot seek.
995     * @since 8
996     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
997     */
998    readonly duration: number;
999
1000    /**
1001     * Playback state.
1002     * @since 8
1003     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
1004     */
1005    readonly state: VideoPlayState;
1006
1007    /**
1008     * video width, valid after prepared.
1009     * @since 8
1010     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
1011     */
1012    readonly width: number;
1013
1014    /**
1015     * video height, valid after prepared.
1016     * @since 8
1017     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
1018     */
1019    readonly height: number;
1020
1021    /**
1022     * set payback speed.
1023     * @since 8
1024     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
1025     * @param speed playback speed, see @PlaybackSpeed .
1026     * @param callback Callback used to return actually speed.
1027     */
1028    setSpeed(speed:number, callback: AsyncCallback<number>): void;
1029    /**
1030     * set output surface.
1031     * @since 8
1032     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
1033     * @param speed playback speed, see @PlaybackSpeed .
1034     * @return A Promise instance used to return actually speed.
1035     */
1036    setSpeed(speed:number): Promise<number>;
1037
1038    /**
1039     * Listens for video playback completed events.
1040     * @since 8
1041     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
1042     * @param type Type of the playback event to listen for.
1043     * @param callback Callback used to listen for the playback event return .
1044     */
1045    on(type: 'playbackCompleted', callback: Callback<void>): void;
1046
1047    /**
1048     * Listens for video playback buffering events.
1049     * @since 8
1050     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
1051     * @param type Type of the playback buffering update event to listen for.
1052     * @param callback Callback used to listen for the buffering update event, return BufferingInfoType and the value.
1053     */
1054    on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: number) => void): void;
1055
1056    /**
1057     * Listens for start render video frame events.
1058     * @since 8
1059     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
1060     * @param type Type of the playback event to listen for.
1061     * @param callback Callback used to listen for the playback event return .
1062     */
1063    on(type: 'startRenderFrame', callback: Callback<void>): void;
1064
1065    /**
1066     * Listens for video size changed event.
1067     * @since 8
1068     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
1069     * @param type Type of the playback event to listen for.
1070     * @param callback Callback used to listen for the playback event return video size.
1071     */
1072    on(type: 'videoSizeChanged', callback: (width: number, height: number) => void): void;
1073
1074    /**
1075     * Listens for playback error events.
1076     * @since 8
1077     * @syscap SystemCapability.Multimedia.Media.VideoPlayer
1078     * @param type Type of the playback error event to listen for.
1079     * @param callback Callback used to listen for the playback error event.
1080     */
1081    on(type: 'error', callback: ErrorCallback): void;
1082  }
1083
1084  /**
1085   * Enumerates container format type(The abbreviation for 'container format type' is CFT).
1086   * @since 8
1087   * @syscap SystemCapability.Multimedia.Media.Core
1088   * @import import media from '@ohos.multimedia.media'
1089   */
1090  enum ContainerFormatType {
1091    /**
1092     * A video container format type mp4.
1093     * @since 8
1094     * @syscap SystemCapability.Multimedia.Media.Core
1095     */
1096    CFT_MPEG_4 = "mp4",
1097
1098    /**
1099     * A audio container format type m4a.
1100     * @since 8
1101     * @syscap SystemCapability.Multimedia.Media.Core
1102     */
1103    CFT_MPEG_4A = "m4a",
1104  }
1105
1106  /**
1107   * Enumerates media data type.
1108   * @since 8
1109   * @syscap SystemCapability.Multimedia.Media.Core
1110   * @import import media from '@ohos.multimedia.media'
1111   */
1112  enum MediaType {
1113    /**
1114     * track is audio.
1115     * @since 8
1116     * @syscap SystemCapability.Multimedia.Media.Core
1117     */
1118    MEDIA_TYPE_AUD = 0,
1119    /**
1120     * track is video.
1121     * @since 8
1122     * @syscap SystemCapability.Multimedia.Media.Core
1123     */
1124    MEDIA_TYPE_VID = 1,
1125  }
1126
1127  /**
1128   * Enumerates media description key.
1129   * @since 8
1130   * @syscap SystemCapability.Multimedia.Media.Core
1131   * @import import media from '@ohos.multimedia.media'
1132   */
1133  enum MediaDescriptionKey {
1134    /**
1135     * key for track index, value type is number.
1136     * @since 8
1137     * @syscap SystemCapability.Multimedia.Media.Core
1138     */
1139    MD_KEY_TRACK_INDEX = "track_index",
1140
1141    /**
1142     * key for track type, value type is number, see @MediaType.
1143     * @since 8
1144     * @syscap SystemCapability.Multimedia.Media.Core
1145     */
1146    MD_KEY_TRACK_TYPE = "track_type",
1147
1148    /**
1149     * key for codec mime type, value type is string.
1150     * @since 8
1151     * @syscap SystemCapability.Multimedia.Media.Core
1152     */
1153    MD_KEY_CODEC_MIME = "codec_mime",
1154
1155    /**
1156     * key for duration, value type is number.
1157     * @since 8
1158     * @syscap SystemCapability.Multimedia.Media.Core
1159     */
1160    MD_KEY_DURATION = "duration",
1161
1162    /**
1163     * key for bitrate, value type is number.
1164     * @since 8
1165     * @syscap SystemCapability.Multimedia.Media.Core
1166     */
1167    MD_KEY_BITRATE = "bitrate",
1168
1169    /**
1170     * key for video width, value type is number.
1171     * @since 8
1172     * @syscap SystemCapability.Multimedia.Media.Core
1173     */
1174    MD_KEY_WIDTH = "width",
1175
1176    /**
1177     * key for video height, value type is number.
1178     * @since 8
1179     * @syscap SystemCapability.Multimedia.Media.Core
1180     */
1181    MD_KEY_HEIGHT = "height",
1182
1183    /**
1184     * key for video frame rate, value type is number.
1185     * @since 8
1186     * @syscap SystemCapability.Multimedia.Media.Core
1187     */
1188    MD_KEY_FRAME_RATE = "frame_rate",
1189
1190    /**
1191     * key for audio channel count, value type is number
1192     * @since 8
1193     * @syscap SystemCapability.Multimedia.Media.Core
1194     */
1195    MD_KEY_AUD_CHANNEL_COUNT = "channel_count",
1196
1197    /**
1198     * key for audio sample rate, value type is number
1199     * @since 8
1200     * @syscap SystemCapability.Multimedia.Media.Core
1201     */
1202    MD_KEY_AUD_SAMPLE_RATE = "sample_rate",
1203  }
1204
1205  /**
1206   * Provides the video recorder profile definitions.
1207   * @since 8
1208   * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1209   */
1210  interface VideoRecorderProfile {
1211    /**
1212     * Indicates the audio bit rate.
1213     * @since 8
1214     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1215     */
1216    readonly audioBitrate: number;
1217
1218    /**
1219     * Indicates the number of audio channels.
1220     * @since 8
1221     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1222     */
1223    readonly audioChannels: number;
1224
1225    /**
1226     * Indicates the audio encoding format.
1227     * @since 8
1228     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1229     */
1230    readonly audioCodec: CodecMimeType;
1231
1232    /**
1233     * Indicates the audio sampling rate.
1234     * @since 8
1235     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1236     */
1237    readonly audioSampleRate: number;
1238
1239    /**
1240     * Indicates the output file format.
1241     * @since 8
1242     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1243     */
1244    readonly fileFormat: ContainerFormatType;
1245
1246    /**
1247     * Indicates the video bit rate.
1248     * @since 8
1249     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1250     */
1251    readonly videoBitrate: number;
1252
1253    /**
1254     * Indicates the video encoding format.
1255     * @since 8
1256     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1257     */
1258    readonly videoCodec: CodecMimeType;
1259
1260    /**
1261     * Indicates the video width.
1262     * @since 8
1263     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1264     */
1265    readonly videoFrameWidth: number;
1266
1267    /**
1268     * Indicates the video height.
1269     * @since 8
1270     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1271     */
1272    readonly videoFrameHeight: number;
1273
1274    /**
1275     * Indicates the video frame rate.
1276     * @since 8
1277     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1278     */
1279    readonly videoFrameRate: number;
1280  }
1281
1282  /**
1283   * Enumerates audio source type for recorder.
1284   * @since 8
1285   * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1286   * @import import media from '@ohos.multimedia.media'
1287   */
1288  enum AudioSourceType {
1289    /**
1290     * default audio source type.
1291     * @since 8
1292     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1293    */
1294    AUDIO_SOURCE_TYPE_DEFAULT = 0,
1295    /**
1296     * source type mic.
1297     * @since 8
1298     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1299    */
1300    AUDIO_SOURCE_TYPE_MIC = 1,
1301  }
1302
1303  /**
1304   * Enumerates video source type for recorder.
1305   * @since 8
1306   * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1307   * @import import media from '@ohos.multimedia.media'
1308   */
1309  enum VideoSourceType {
1310    /**
1311     * surface raw data.
1312     * @since 8
1313     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1314     */
1315    VIDEO_SOURCE_TYPE_SURFACE_YUV = 0,
1316    /**
1317     * surface ES data.
1318     * @since 8
1319     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1320    */
1321    VIDEO_SOURCE_TYPE_SURFACE_ES = 1,
1322  }
1323
1324  /**
1325   * Provides the video recorder configuration definitions.
1326   * @since 8
1327   * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1328   */
1329  interface VideoRecorderConfig {
1330    /**
1331     * audio source type, details see @AudioSourceType .
1332     * @since 8
1333     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1334     */
1335    audioSourceType: AudioSourceType;
1336    /**
1337     * video source type, details see @VideoSourceType .
1338     * @since 8
1339     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1340     */
1341    videoSourceType: VideoSourceType;
1342    /**
1343     * video recorder profile, can get by "getVideoRecorderProfile", details see @VideoRecorderProfile .
1344     * @since 8
1345     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1346     */
1347    profile:VideoRecorderProfile;
1348    /**
1349     * video output uri.support two kind of uri now.
1350     * format like: scheme + "://" + "context".
1351     * fd:    fd://fd
1352     * @since 8
1353     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1354     */
1355    url: string;
1356    /**
1357     * Sets the video rotation angle in output file, and for the file to playback. mp4 support.
1358     * the range of rotation angle should be {0, 90, 180, 270}, default is 0.
1359     * @since 8
1360     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1361     */
1362    rotation?: number;
1363    /**
1364     * geographical location information.
1365     * @since 8
1366     * @syscap SystemCapability.Multimedia.Media.VideoRecorder
1367     */
1368    location?: Location;
1369  }
1370
1371  /**
1372   * Provides the container definition for media description key-value pairs.
1373   * @since 8
1374   * @syscap SystemCapability.Multimedia.Media.Core
1375   */
1376  interface MediaDescription {
1377    /**
1378     * key:value pair, key see @MediaDescriptionKey .
1379     * @since 8
1380     * @syscap SystemCapability.Multimedia.Media.Core
1381     */
1382    [key : string]: Object;
1383  }
1384
1385  /**
1386   * Enumerates seek mode.
1387   * @since 8
1388   * @syscap SystemCapability.Multimedia.Media.Core
1389   * @import import media from '@ohos.multimedia.media'
1390   */
1391  enum SeekMode {
1392    /**
1393     * seek to the next sync frame of the given timestamp
1394     * @since 8
1395     * @syscap SystemCapability.Multimedia.Media.Core
1396     */
1397    SEEK_NEXT_SYNC = 0,
1398    /**
1399     * seek to the previous sync frame of the given timestamp
1400     * @since 8
1401     * @syscap SystemCapability.Multimedia.Media.Core
1402     */
1403    SEEK_PREV_SYNC = 1,
1404  }
1405
1406  /**
1407   * Enumerates Codec MIME types.
1408   * @since 8
1409   * @syscap SystemCapability.Multimedia.Media.Core
1410   * @import import media from '@ohos.multimedia.media'
1411   */
1412   enum CodecMimeType {
1413    /**
1414     * H.263 codec MIME type.
1415     * @since 8
1416     * @syscap SystemCapability.Multimedia.Media.Core
1417     */
1418    VIDEO_H263 = 'video/h263',
1419    /**
1420     * H.264 codec MIME type.
1421     * @since 8
1422     * @syscap SystemCapability.Multimedia.Media.Core
1423     */
1424    VIDEO_AVC = 'video/avc',
1425    /**
1426     * MPEG2 codec MIME type.
1427     * @since 8
1428     * @syscap SystemCapability.Multimedia.Media.Core
1429     */
1430    VIDEO_MPEG2 = 'video/mpeg2',
1431    /**
1432     * MPEG4 codec MIME type
1433     * @since 8
1434     * @syscap SystemCapability.Multimedia.Media.Core
1435     */
1436    VIDEO_MPEG4 = 'video/mp4v-es',
1437
1438    /**
1439     * VP8 codec MIME type
1440     * @since 8
1441     * @syscap SystemCapability.Multimedia.Media.Core
1442     */
1443    VIDEO_VP8 = 'video/x-vnd.on2.vp8',
1444
1445    /**
1446     * AAC codec MIME type.
1447     * @since 8
1448     * @syscap SystemCapability.Multimedia.Media.Core
1449     */
1450    AUDIO_AAC = 'audio/mp4a-latm',
1451
1452    /**
1453     * vorbis codec MIME type.
1454     * @since 8
1455     * @syscap SystemCapability.Multimedia.Media.Core
1456     */
1457    AUDIO_VORBIS = 'audio/vorbis',
1458
1459    /**
1460     * flac codec MIME type.
1461     * @since 8
1462     * @syscap SystemCapability.Multimedia.Media.Core
1463     */
1464    AUDIO_FLAC = 'audio/flac',
1465  }
1466}
1467export default media;
1468