update media api Signed-off-by: huang-xl<huangxiaolong1@huawei.com>

This commit is contained in:
黑眼圈 2021-12-17 09:46:03 +00:00 committed by Gitee
parent 500b65c5b2
commit a78ac01d11
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -13,116 +13,363 @@
* limitations under the License. * limitations under the License.
*/ */
import {ErrorCallback, AsyncCallback, Callback} from './basic'; import { ErrorCallback, AsyncCallback, Callback } from './basic';
/** /**
* @name media * @name media
* @sysCap SystemCapability.Multimedia.Media * @since 6
* @import import media from '@ohos.multimedia.media'; * @SysCap SystemCapability.Multimedia.Media
* This part of the function is temporarily unavailable due to permission issues in the standard system, * @import import media from '@ohos.multimedia.media'
* waiting for update * @devices phone, tablet, tv, wearable
*/ */
declare namespace media { 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 {
/** /**
* Create the AudioPlayer instance to manage audio play * Starts audio playback.
* @sysCap SystemCapability.Multimedia.Media * @devices phone, tablet, tv, wearable
* @since 6
* @SysCap SystemCapability.Multimedia.Media
*/ */
function createAudioPlayer(): AudioPlayer; play(): void;
/** /**
* Audio playback state * Pauses audio playback.
* @devices phone, tablet, tv, wearable
* @since 6
* @SysCap SystemCapability.Multimedia.Media
*/ */
type AudioState = 'playing' | 'paused' | 'stopped'; pause(): void;
interface AudioPlayer { /**
/** * Stops audio playback.
* start to play audio resource * @devices phone, tablet, tv, wearable
* @devices phone * @since 6
* @sysCap SystemCapability.Multimedia.Media * @SysCap SystemCapability.Multimedia.Media
*/ */
play(): void; stop(): void;
/** /**
* pause playing * Resets audio playback.
* @devices phone * @devices phone, tablet, tv, wearable
* @sysCap SystemCapability.Multimedia.Media * @since 7
*/ * @SysCap SystemCapability.Multimedia.Media
pause(): void; */
reset(): void;
/** /**
* stop playing * Jumps to the specified playback position.
* @devices phone * @devices phone, tablet, tv, wearable
* @sysCap SystemCapability.Multimedia.Media * @since 6
*/ * @SysCap SystemCapability.Multimedia.Media
stop(): void; * @param timeMs Playback position to jump
*/
seek(timeMs: number): void;
/** /**
* jump to a specified location * Sets the volume.
* @devices phone * @devices phone, tablet, tv, wearable
* @sysCap SystemCapability.Multimedia.Media * @since 6
* @param time position to seek * @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%).
seek(timeMs: number):void; */
setVolume(vol: number): void;
/** /**
* change the audioplayer volume * Releases resources used for audio playback.
* @devices phone * @devices phone, tablet, tv, wearable
* @sysCap SystemCapability.Multimedia.Media * @since 6
* @param volume to set * @SysCap SystemCapability.Multimedia.Media
*/ */
setVolume(vol: number): void; release(): void;
/** /**
* release audio resource * Audio media URI. Mainstream audio formats are supported.
* @devices phone * @devices phone, tablet, tv, wearable
* @sysCap SystemCapability.Multimedia.Media * @since 6
*/ * @SysCap SystemCapability.Multimedia.Media
release(): void; */
src: string;
/** /**
* audio resource URI * Whether to loop audio playback. The value true means to loop playback.
* @devices phone * @devices phone, tablet, tv, wearable
* @sysCap SystemCapability.Multimedia.Media * @since 6
*/ * @SysCap SystemCapability.Multimedia.Media
src: string; */
loop: boolean;
/** /**
* whether audio is single looping * Current playback position.
* @devices phone * @devices phone, tablet, tv, wearable
* @sysCap SystemCapability.Multimedia.Media * @since 6
* @option true "The audio looping function is enabled." * @SysCap SystemCapability.Multimedia.Media
* @option false "The audio looping function is disabled." */
*/ readonly currentTime: number;
loop: boolean;
/** /**
* audio property of current progress * Playback duration. When the data source does not support seek, it returns - 1, such as a live broadcast scenario.
* @devices phone * @devices phone, tablet, tv, wearable
* @sysCap SystemCapability.Multimedia.Media * @since 6
*/ * @SysCap SystemCapability.Multimedia.Media
readonly currentTime: number; */
readonly duration: number;
/** /**
* audio property of audio playback duration * Playback state.
* @devices phone * @devices phone, tablet, tv, wearable
* @sysCap SystemCapability.Multimedia.Media * @since 6
*/ * @SysCap SystemCapability.Multimedia.Media
readonly duration: number; */
readonly state: AudioState;
/** /**
* audio property of playback status * Listens for audio playback events.
* @devices phone * @devices phone, tablet, tv, wearable
* @sysCap SystemCapability.Multimedia.Media * @since 6
*/ * @SysCap SystemCapability.Multimedia.Media
readonly state: AudioState; * @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;
/** /**
* audio callback function for listening to event * Listens for audio playback events.
* @devices phone * @devices phone, tablet, tv, wearable
* @sysCap SystemCapability.Multimedia.Media * @since 6
*/ * @SysCap SystemCapability.Multimedia.Media
on(type: 'play' | 'pause' | 'stop' | 'dataLoad' | 'finish' | 'volumeChange' | 'timeUpdate', callback: ()=>{}):void; * @param type Type of the playback event to listen for.
on(type:'error', callback: ErrorCallback):void; * @param callback Callback used to listen for the playback event.
} */
on(type: 'timeUpdate', callback: Callback<number>): 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;
/**
* 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;