Skip to content
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
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The MIT License (MIT)

nativescript-yourplugin
Copyright (c) 2016, Your Name
nativescript-audio
Copyright (c) 2016, Brad Martin & Nathan Walker

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
63 changes: 34 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# NativeScript-Audio
NativeScript plugin to play and record audio files.
NativeScript plugin to play and record audio files for Android and iOS.

*Currently Android only, iOS is in the works.*
Uses the following native classes:

[Android Media Recorder Docs](http://developer.android.com/reference/android/media/MediaRecorder.html)
#### Android

* [Player](http://developer.android.com/reference/android/media/MediaPlayer.html)
* [Recorder](http://developer.android.com/reference/android/media/MediaRecorder.html)

#### iOS

* [Player](https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioPlayerClassReference/)
* [Recorder](https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVAudioRecorder_ClassReference/)

## Installation
`npm install nativescript-audio`
Expand All @@ -12,41 +20,38 @@ NativeScript plugin to play and record audio files.

![AudioExample](screens/audiosample.gif)


## API

#### *Recording*

##### canDeviceRecord() - *Promise*
- retruns: *boolean*

##### startRecorder( { filename: string, errorCallback?: Function, infoCallback?: Function } ) - *Promise*
- returns: *recorder* (android.media.MediaRecorder)

##### stopRecorder(recorder: recorder object from startRecorder)

#### TNSRecorder

##### disposeRecorder(recorder: recorder object from startRecorder)
- *Free up system resources when done with recorder*
Method | Description
-------- | ---------
`TNSRecorder.CAN_RECORD()`: `boolean` | Determine if ready to record.
`start({ filename: string, errorCallback?: Function, infoCallback?: Function })`: `Promise` | Start recording file.
`stop()`: `void` | Stop recording.
`dispose()`: `void` | Free up system resources when done with recorder.

#### TNSPlayer

#### *Playing*
Method | Description
-------- | ---------
`playFromFile( { audioFile: string, completeCallback?: Function, errorCallback?: Function, infoCallback?: Function; } )`: `Promise` | Play from a file.
`playFromUrl( { audioFile: string, completeCallback?: Function, errorCallback?: Function, infoCallback?: Function; } )`: `Promise` | Play from a url.
`pause()`: `void` | Pause playback.
`dispose()`: `void` | Free up resources when done playing audio.
`isAudioPlaying()`: `boolean` | Determine if player is playing.
`getAudioTrackDuration()`: `Promise` | duration of media file assigned to mediaPlayer

##### playFromFile( { audioFile: string, completeCallback?: Function, errorCallback?: Function, infoCallback?: Function; } ) - *Promise*
- returns mediaPlayer (android.media.MediaPlayer)
## Why the TNS prefixed name?

##### playFromUrl( { audioFile: string, completeCallback?: Function, errorCallback?: Function, infoCallback?: Function; } ) - *Promise*
- returns mediaPlayer (android.media.MediaPlayer)
`TNS` stands for **T**elerik **N**ative**S**cript

##### pausePlayer(mediaPlayer) - *Promise*
- return boolean
iOS uses classes prefixed with `NS` (stemming from the [NeXTSTEP](https://en.wikipedia.org/wiki/NeXTSTEP) days of old):
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/

##### disposePlayer(mediaPlayer)
-- Free up resources when done playing audio with this instance of your mediaPlayer
To avoid confusion with iOS native classes, `TNS` is used instead.

##### isAudioPlaying(mediaPlayer) - *Promise*
- returns boolean
# License

##### getAudioTrackDuration(mediaPlayer) - *Promise*
- returns string - duration of media file assigned to mediaPlayer
[MIT](/LICENSE)

Loading