UNPKG

4.82 kBTypeScriptView Raw
1export interface MediaError {
2 code: number;
3 message: string;
4}
5/**
6 * @name MediaPlugin
7 * @description
8 * @usage
9 * ```typescript
10 * import { MediaPlugin } from 'ionic-native';
11 *
12 *
13 *
14 * // Create a MediaPlugin instance. Expects path to file or url as argument
15 * // We can optionally pass a second argument to track the status of the media
16 *
17 * const onStatusUpdate = (status) => console.log(status);
18 *
19 * const file = new MediaPlugin('path/to/file.mp3', onStatusUpdate);
20 *
21 * // Catch the Success & Error Output
22 * // Platform Quirks
23 * // iOS calls success on completion of playback only
24 * // Android calls success on completion of playback AND on release()
25 * file.init.then(() => {
26 * console.log('Playback Finished');
27 * }, (err) => {
28 * console.log('somthing went wrong! error code: ' + err.code + ' message: ' + err.message);
29 * });
30 *
31 * // play the file
32 * file.play();
33 *
34 * // pause the file
35 * file.pause();
36 *
37 * // get current playback position
38 * file.getCurrentPosition().then((position) => {
39 * console.log(position);
40 * });
41 *
42 * // get file duration
43 * file.getDuration();
44 *
45 * // skip to 10 seconds (expects int value in ms)
46 * file.seekTo(10000);
47 *
48 * // stop playing the file
49 * file.stop();
50 *
51 * // release the native audio resource
52 * // Platform Quirks:
53 * // iOS simply create a new instance and the old one will be overwritten
54 * // Android you must call release() to destroy instances of media when you are done
55 * file.release();
56 *
57 * // Recording to a file
58 * var newFile = new MediaPlugin('path/to/file.mp3');
59 * newFile.startRecord();
60 *
61 * newFile.stopRecord();
62 *
63 *
64 *
65 * ```
66 */
67export declare class MediaPlugin {
68 /**
69 * @private
70 */
71 static MEDIA_NONE: number;
72 /**
73 * @private
74 */
75 static MEDIA_STARTING: number;
76 /**
77 * @private
78 */
79 static MEDIA_RUNNING: number;
80 /**
81 * @private
82 */
83 static MEDIA_PAUSED: number;
84 /**
85 * @private
86 */
87 static MEDIA_STOPPED: number;
88 /**
89 * @private
90 */
91 static MEDIA_ERR_ABORTED: number;
92 /**
93 * @private
94 */
95 static MEDIA_ERR_NETWORK: number;
96 /**
97 * @private
98 */
99 static MEDIA_ERR_DECODE: number;
100 /**
101 * @private
102 */
103 static MEDIA_ERR_NONE_SUPPORTED: number;
104 private _objectInstance;
105 init: Promise<any>;
106 /**
107 * Open a media file
108 * @param src {string} A URI containing the audio content.
109 * @param onStatusUpdate {Function} A callback function to be invoked when the status of the file changes
110 */
111 constructor(src: string, onStatusUpdate?: Function);
112 /**
113 * Get the current amplitude of the current recording.
114 * @returns {Promise<any>} Returns a promise with the amplitude of the current recording
115 */
116 getCurrentAmplitude(): Promise<any>;
117 /**
118 * Get the current position within an audio file. Also updates the Media object's position parameter.
119 * @returns {Promise<any>} Returns a promise with the position of the current recording
120 */
121 getCurrentPosition(): Promise<any>;
122 /**
123 * Get the duration of an audio file in seconds. If the duration is unknown, it returns a value of -1.
124 * @returns {number} Returns a promise with the duration of the current recording
125 */
126 getDuration(): number;
127 /**
128 * Starts or resumes playing an audio file.
129 */
130 play(iosOptions?: {
131 numberOfLoops?: number;
132 playAudioWhenScreenIsLocked?: boolean;
133 }): void;
134 /**
135 * Pauses playing an audio file.
136 */
137 pause(): void;
138 /**
139 * Releases the underlying operating system's audio resources. This is particularly important for Android, since there are a finite amount of OpenCore instances for media playback. Applications should call the release function for any Media resource that is no longer needed.
140 */
141 release(): void;
142 /**
143 * Sets the current position within an audio file.
144 * @param {number} milliseconds The time position you want to set for the current audio file
145 */
146 seekTo(milliseconds: number): void;
147 /**
148 * Set the volume for an audio file.
149 * @param volume {number} The volume to set for playback. The value must be within the range of 0.0 to 1.0.
150 */
151 setVolume(volume: number): void;
152 /**
153 * Starts recording an audio file.
154 */
155 startRecord(): void;
156 /**
157 * Stops recording
158 */
159 stopRecord(): void;
160 /**
161 * Pauses recording
162 */
163 pauseRecord(): void;
164 /**
165 * Resumes recording
166 */
167 resumeRecord(): void;
168 /**
169 * Stops playing an audio file.
170 */
171 stop(): void;
172}