Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(native-audio): Add native audio plugin #427

Merged
merged 1 commit into from
Aug 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {Keyboard} from './plugins/keyboard';
import {LaunchNavigator} from './plugins/launchnavigator';
import {LocalNotifications} from './plugins/localnotifications';
import {MediaCapture} from './plugins/media-capture';
import {NativeAudio} from './plugins/native-audio';
import {NativeStorage} from './plugins/nativestorage';
import {MediaPlugin} from './plugins/media';
import {Network} from './plugins/network';
Expand Down Expand Up @@ -146,6 +147,7 @@ export {
Hotspot,
Insomnia,
Keyboard,
NativeAudio,
NativeStorage,
Network,
OneSignal,
Expand Down Expand Up @@ -220,6 +222,7 @@ window['IonicNative'] = {
LocalNotifications: LocalNotifications,
MediaCapture: MediaCapture,
MediaPlugin: MediaPlugin,
NativeAudio: NativeAudio,
NativeStorage: NativeStorage,
Network: Network,
Printer: Printer,
Expand Down
91 changes: 91 additions & 0 deletions src/plugins/native-audio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import {Plugin, Cordova} from './plugin';
/**
* @name NativeAudio
* @description Native Audio Playback
* @usage
* ```typescript
* import {NativeAudio} from 'ionic-native';
*
* NativeAudio.preloadSimple('uniqueId1', 'path/to/file.mp3').then(onSuccess, onError);
* NativeAudio.preloadComplex('uniqueId2', 'path/to/file2.mp3', 1, 1, 0).then(onSuccess, onError);
*
* NativeAudio.play('uniqueId1').then(onSuccess, onError);
* NativeAudio.loop('uniqueId2').then(onSuccess, onError);
*
* NativeAudio.setVolumeForComplexAsset('uniqueId2', 0.6).then(onSuccess,onError);
*
* NativeAudio.stop('uniqueId1').then(onSuccess,onError);
*
* NativeAudio.unload('uniqueId1').then(onSuccess,onError);
*
* ```
*/
@Plugin({
plugin: 'cordova-plugin-nativeaudio',
pluginRef: 'NativeAudio',
repo: 'https://github.com/floatinghotpot/cordova-plugin-nativeaudio'
})
export class NativeAudio {
/**
* Loads an audio file into memory. Optimized for short clips / single shots (up to five seconds). Cannot be stopped / looped.
* @param id {string} unique ID for the audio file
* @param assetPath {string} the relative path or absolute URL (inluding http://) to the audio asset.
* @returns {Promise<any>}
*/
@Cordova()
static preloadSimple(id: string, assetPath: string): Promise<any> {return; }

/**
* Loads an audio file into memory. Optimized for background music / ambient sound. Uses highlevel native APIs with a larger footprint. (iOS: AVAudioPlayer). Can be stopped / looped and used with multiple voices. Can be faded in and out using the delay parameter.
* @param id {string} unique ID for the audio file
* @param assetPath {string} the relative path or absolute URL (inluding http://) to the audio asset.
* @param volume {number} the volume of the preloaded sound (0.1 to 1.0)
* @param voices {number} the number of multichannel voices available
* @param delay {number}
* @returns {Promise<any>}
*/
@Cordova()
static preloadComplex(id: string, assetPath: string, volume: number, voices: number, delay: number): Promise<any> {return; }

/**
* Plays an audio asset
* @param id {string} unique ID for the audio file
* @param completeCallback {Function} callback to be invoked when audio is done playing
*/
@Cordova({
successIndex: 1,
errorIndex: 2
})
static play(id: string, completeCallback: Function): Promise<any> {return; }

/**
* Stops playing an audio
* @param id {string} unique ID for the audio file
*/
@Cordova()
static stop(id: string): Promise<any> {return; }

/**
* Loops an audio asset infinitely, this only works for complex assets
* @param id {string} unique ID for the audio file
* @return {Promise<any>}
*/
@Cordova()
static loop(id: string): Promise<any> {return; }

/**
* Unloads an audio file from memory
* @param id {string} unique ID for the audio file
*/
@Cordova()
static unload(id: string): Promise<any> {return; }

/**
* Changes the volume for preloaded complex assets.
* @param id {string} unique ID for the audio file
* @param volume {number} the volume of the audio asset (0.1 to 1.0)
*/
@Cordova()
static setVolumeForComplexAsset(id: string, volume: number): Promise<any> {return; }

}