• 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 * @sysCap SystemCapability.Multimedia.Media
21 * @import import media from '@ohos.multimedia.media';
22 * This part of the function is temporarily unavailable due to permission issues in the standard system,
23 * waiting for update
24 */
25declare namespace media {
26    /**
27     * Create the AudioPlayer instance to manage audio play
28     * @sysCap SystemCapability.Multimedia.Media
29     */
30    function createAudioPlayer(): AudioPlayer;
31
32    /**
33     * Audio playback state
34     */
35    type AudioState = 'playing' | 'paused' | 'stopped';
36
37    interface AudioPlayer {
38        /**
39         * start to play audio resource
40         * @devices phone
41         * @sysCap SystemCapability.Multimedia.Media
42         */
43        play(): void;
44
45        /**
46         * pause playing
47         * @devices phone
48         * @sysCap SystemCapability.Multimedia.Media
49         */
50        pause(): void;
51
52        /**
53         * stop playing
54         * @devices phone
55         * @sysCap SystemCapability.Multimedia.Media
56         */
57        stop(): void;
58
59        /**
60         * jump to a specified location
61         * @devices phone
62         * @sysCap SystemCapability.Multimedia.Media
63         * @param time position to seek
64         */
65        seek(timeMs: number):void;
66
67        /**
68         * change the audioplayer volume
69         * @devices phone
70         * @sysCap SystemCapability.Multimedia.Media
71         * @param volume to set
72         */
73        setVolume(vol: number): void;
74
75        /**
76         * release audio resource
77         * @devices phone
78         * @sysCap SystemCapability.Multimedia.Media
79         */
80        release(): void;
81
82        /**
83         * audio resource URI
84         * @devices phone
85         * @sysCap SystemCapability.Multimedia.Media
86         */
87        src: string;
88
89        /**
90         * whether audio is single looping
91         * @devices phone
92         * @sysCap SystemCapability.Multimedia.Media
93         * @option true "The audio looping function is enabled."
94         * @option false "The audio looping function is disabled."
95         */
96        loop: boolean;
97
98         /**
99         * audio property of current progress
100         * @devices phone
101         * @sysCap SystemCapability.Multimedia.Media
102         */
103        readonly currentTime: number;
104
105         /**
106         * audio property of audio playback duration
107         * @devices phone
108         * @sysCap SystemCapability.Multimedia.Media
109         */
110        readonly duration: number;
111
112        /**
113         * audio property of playback status
114         * @devices phone
115         * @sysCap SystemCapability.Multimedia.Media
116         */
117        readonly state: AudioState;
118
119        /**
120         * audio callback function for listening to event
121         * @devices phone
122         * @sysCap SystemCapability.Multimedia.Media
123         */
124        on(type: 'play' | 'pause' | 'stop' | 'dataLoad' | 'finish' | 'volumeChange' | 'timeUpdate', callback: ()=>{}):void;
125        on(type:'error', callback: ErrorCallback):void;
126    }
127}
128export default media;
129