diff --git a/api/@ohos.multimedia.media.d.ts b/api/@ohos.multimedia.media.d.ts index e55930a0c0bc2954247d44fabe8b9abd447cc173..54d94dab6c71cec42212e1888ce1a2992b574c6e 100755 --- a/api/@ohos.multimedia.media.d.ts +++ b/api/@ohos.multimedia.media.d.ts @@ -13,116 +13,363 @@ * limitations under the License. */ -import {ErrorCallback, AsyncCallback, Callback} from './basic'; +import { ErrorCallback, AsyncCallback, Callback } from './basic'; /** * @name media - * @sysCap SystemCapability.Multimedia.Media - * @import import media from '@ohos.multimedia.media'; - * This part of the function is temporarily unavailable due to permission issues in the standard system, - * waiting for update + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + * @import import media from '@ohos.multimedia.media' + * @devices phone, tablet, tv, wearable */ declare namespace media { + /** + * Creates an AudioPlayer instance. + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + * @import import media from '@ohos.multimedia.media' + * @return Returns an AudioPlayer instance if the operation is successful; returns null otherwise. + */ + function createAudioPlayer(): AudioPlayer; + + /** + * Creates an AudioRecorder instance. + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + * @import import media from '@ohos.multimedia.media' + * @return Returns an AudioRecorder instance if the operation is successful; returns null otherwise. + */ + function createAudioRecorder(): AudioRecorder; + + /** + * Describes audio playback states. + */ + type AudioState = 'idle' | 'playing' | 'paused' | 'stopped'; + + /** + * Manages and plays audio. Before calling an AudioPlayer method, you must use createAudioPlayer() to create an AudioPlayer instance. + */ + interface AudioPlayer { + /** + * Starts audio playback. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + play(): void; + + /** + * Pauses audio playback. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + pause(): void; + + /** + * Stops audio playback. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + stop(): void; + + /** + * Resets audio playback. + * @devices phone, tablet, tv, wearable + * @since 7 + * @SysCap SystemCapability.Multimedia.Media + */ + reset(): void; + + /** + * Jumps to the specified playback position. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + * @param timeMs Playback position to jump + */ + seek(timeMs: number): void; + + /** + * Sets the volume. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + * @param vol Relative volume. The value ranges from 0.00 to 1.00. The value 1 indicates the maximum volume (100%). + */ + setVolume(vol: number): void; + + /** + * Releases resources used for audio playback. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + release(): void; + + /** + * Audio media URI. Mainstream audio formats are supported. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + src: string; + + /** + * Whether to loop audio playback. The value true means to loop playback. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + loop: boolean; + + /** + * Current playback position. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + readonly currentTime: number; + + /** + * Playback duration. When the data source does not support seek, it returns - 1, such as a live broadcast scenario. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + readonly duration: number; + + /** + * Playback state. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + readonly state: AudioState; + + /** + * Listens for audio playback events. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + * @param type Type of the playback event to listen for. + * @param callback Callback used to listen for the playback event. + */ + on(type: 'play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeChange', callback: () => void): void; + + /** + * Listens for audio playback events. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + * @param type Type of the playback event to listen for. + * @param callback Callback used to listen for the playback event. + */ + on(type: 'timeUpdate', callback: Callback): void; + + /** + * Listens for playback error events. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + * @param type Type of the playback error event to listen for. + * @param callback Callback used to listen for the playback error event. + */ + on(type: 'error', callback: ErrorCallback): void; + } + + /** + * Enumerates audio encoding formats. + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + * @import import media from '@ohos.multimedia.media' + * @devices phone, tablet, tv, wearable + */ + enum AudioEncoder { + /** + * Advanced Audio Coding Low Complexity (AAC-LC). + */ + AAC_LC = 3, + } + + /** + * Enumerates audio output formats. + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + * @import import media from '@ohos.multimedia.media' + * @devices phone, tablet, tv, wearable + */ + enum AudioOutputFormat { + /** + * Indicates the Moving Picture Experts Group-4 (MPEG4) media format. + */ + MPEG_4 = 2, + + /** + * Audio Data Transport Stream (ADTS), a transmission stream format of Advanced Audio Coding (AAC) audio. + */ + AAC_ADTS = 6 + } + + interface Location { + /** + * Latitude. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + latitude: number; + + /** + * Longitude. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + longitude: number; + } + + interface AudioRecorderConfig { + /** + * Audio encoding format. The default value is DEFAULT. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + audioEncoder?: AudioEncoder; + + /** + * Audio encoding bit rate. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + audioEncodeBitRate?: number; + /** - * Create the AudioPlayer instance to manage audio play - * @sysCap SystemCapability.Multimedia.Media - */ - function createAudioPlayer(): AudioPlayer; - - /** - * Audio playback state - */ - type AudioState = 'playing' | 'paused' | 'stopped'; - - interface AudioPlayer { - /** - * start to play audio resource - * @devices phone - * @sysCap SystemCapability.Multimedia.Media - */ - play(): void; - - /** - * pause playing - * @devices phone - * @sysCap SystemCapability.Multimedia.Media - */ - pause(): void; - - /** - * stop playing - * @devices phone - * @sysCap SystemCapability.Multimedia.Media - */ - stop(): void; - - /** - * jump to a specified location - * @devices phone - * @sysCap SystemCapability.Multimedia.Media - * @param time position to seek - */ - seek(timeMs: number):void; - - /** - * change the audioplayer volume - * @devices phone - * @sysCap SystemCapability.Multimedia.Media - * @param volume to set - */ - setVolume(vol: number): void; - - /** - * release audio resource - * @devices phone - * @sysCap SystemCapability.Multimedia.Media - */ - release(): void; - - /** - * audio resource URI - * @devices phone - * @sysCap SystemCapability.Multimedia.Media - */ - src: string; - - /** - * whether audio is single looping - * @devices phone - * @sysCap SystemCapability.Multimedia.Media - * @option true "The audio looping function is enabled." - * @option false "The audio looping function is disabled." - */ - loop: boolean; - - /** - * audio property of current progress - * @devices phone - * @sysCap SystemCapability.Multimedia.Media - */ - readonly currentTime: number; - - /** - * audio property of audio playback duration - * @devices phone - * @sysCap SystemCapability.Multimedia.Media - */ - readonly duration: number; - - /** - * audio property of playback status - * @devices phone - * @sysCap SystemCapability.Multimedia.Media - */ - readonly state: AudioState; - - /** - * audio callback function for listening to event - * @devices phone - * @sysCap SystemCapability.Multimedia.Media - */ - on(type: 'play' | 'pause' | 'stop' | 'dataLoad' | 'finish' | 'volumeChange' | 'timeUpdate', callback: ()=>{}):void; - on(type:'error', callback: ErrorCallback):void; - } + * Audio sampling rate. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + audioSampleRate?: number; + + /** + * Number of audio channels. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + numberOfChannels?: number; + + /** + * Audio output format. The default value is DEFAULT. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + format?: AudioOutputFormat; + + /** + * Audio output uri.support two kind of uri now. + * format like: scheme + "://" + "context". + * file: file://path + * fd: fd://fd + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + uri: string; + + /** + * Geographical location information. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + location?: Location; + } + + interface AudioRecorder { + /** + * Prepares for recording. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + * @param config Recording parameters. + */ + prepare(config: AudioRecorderConfig): void; + + /** + * Starts audio recording. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + start(): void; + + /** + * Pauses audio recording. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + pause(): void; + + /** + * Resumes audio recording. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + resume(): void; + + /** + * Stops audio recording. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + stop(): void; + + /** + * Releases resources used for audio recording. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + release(): void; + + /** + * Resets audio recording. + * Before resetting audio recording, you must call stop() to stop recording. After audio recording is reset, you must call prepare() to set the recording configurations for another recording. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + */ + reset(): void; + + /** + * Listens for audio recording events. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + * @param type Type of the audio recording event to listen for. + * @param callback Callback used to listen for the audio recording event. + */ + on(type: 'prepare' | 'start' | 'pause' | 'resume' | 'stop' | 'release' | 'reset', callback: () => void): void; + + /** + * Listens for audio recording error events. + * @devices phone, tablet, tv, wearable + * @since 6 + * @SysCap SystemCapability.Multimedia.Media + * @param type Type of the audio recording error event to listen for. + * @param callback Callback used to listen for the audio recording error event. + */ + on(type: 'error', callback: ErrorCallback): void; + } } -export default media; + +export default media; \ No newline at end of file