@akylas/nativescript-audio
Advanced tools
Comparing version 6.2.11 to 6.3.0
@@ -53,3 +53,3 @@ import { EventData, Observable } from '@nativescript/core'; | ||
isAudioPlaying(): boolean; | ||
getAudioTrackDuration(): Promise<string>; | ||
getAudioTrackDuration(): Promise<number>; | ||
private _requestAudioFocus; | ||
@@ -56,0 +56,0 @@ private _abandonAudioFocus; |
@@ -301,3 +301,3 @@ import { Application, Observable, Utils } from '@nativescript/core'; | ||
const duration = this._player ? this._player.getDuration() : 0; | ||
return duration.toString(); | ||
return duration; | ||
} | ||
@@ -304,0 +304,0 @@ _requestAudioFocus() { |
import { AudioRecorderOptions } from '..'; | ||
export declare class TNSRecorder { | ||
private _recorder; | ||
get android(): any; | ||
private _wavrecorder; | ||
static CAN_RECORD(): boolean; | ||
@@ -6,0 +6,0 @@ requestRecordPermission(): Promise<[import("@nativescript-community/perms").Status, boolean]>; |
import { check, request } from '@nativescript-community/perms'; | ||
import { Application } from '@nativescript/core'; | ||
import { ANDROID_ENCODER_PCM, ANDROID_ENCODER_PCM_16 } from '..'; | ||
export class TNSRecorder { | ||
get android() { | ||
return this._recorder; | ||
} | ||
static CAN_RECORD() { | ||
@@ -26,2 +24,3 @@ const pManager = Application.android.context.getPackageManager(); | ||
await this.requestRecordPermission(); | ||
const audioSource = options.source ? options.source : 0; | ||
if (this._recorder) { | ||
@@ -31,35 +30,50 @@ this._recorder.reset(); | ||
else { | ||
this._recorder = new android.media.MediaRecorder(); | ||
if (options.encoder === ANDROID_ENCODER_PCM || options.encoder === ANDROID_ENCODER_PCM_16) { | ||
console.log('WaveRecorder'); | ||
this._wavrecorder = new com.github.squti.androidwaverecorder.WaveRecorder(options.filename); | ||
} | ||
else { | ||
this._recorder = new android.media.MediaRecorder(); | ||
} | ||
} | ||
const audioSource = options.source ? options.source : 0; | ||
this._recorder.setAudioSource(audioSource); | ||
const outFormat = options.format ? options.format : 0; | ||
this._recorder.setOutputFormat(outFormat); | ||
const encoder = options.encoder ? options.encoder : 0; | ||
this._recorder.setAudioEncoder(encoder); | ||
if (options.channels) { | ||
this._recorder.setAudioChannels(options.channels); | ||
if (this._recorder) { | ||
this._recorder.setAudioSource(audioSource); | ||
const outFormat = options.format ? options.format : 0; | ||
this._recorder.setOutputFormat(outFormat); | ||
const encoder = options.encoder ? options.encoder : 0; | ||
this._recorder.setAudioEncoder(encoder); | ||
if (options.channels) { | ||
this._recorder.setAudioChannels(options.channels); | ||
} | ||
if (options.sampleRate) { | ||
this._recorder.setAudioSamplingRate(options.sampleRate); | ||
} | ||
if (options.bitRate) { | ||
this._recorder.setAudioEncodingBitRate(options.bitRate); | ||
} | ||
if (options.maxDuration) { | ||
this._recorder.setMaxDuration(options.maxDuration); | ||
} | ||
options.errorCallback && | ||
this._recorder.setOnErrorListener(new android.media.MediaRecorder.OnErrorListener({ | ||
onError: (recorder, error, extra) => { | ||
options.errorCallback({ recorder, error, extra }); | ||
} | ||
})); | ||
options.infoCallback && | ||
this._recorder.setOnInfoListener(new android.media.MediaRecorder.OnInfoListener({ | ||
onInfo: (recorder, info, extra) => { | ||
options.infoCallback({ recorder, info, extra }); | ||
} | ||
})); | ||
this._recorder.setOutputFile(options.filename); | ||
this._recorder.prepare(); | ||
this._recorder.start(); | ||
} | ||
if (options.sampleRate) { | ||
this._recorder.setAudioSamplingRate(options.sampleRate); | ||
else if (this._wavrecorder) { | ||
this._wavrecorder.waveConfig.sampleRate = options.sampleRate || 44100; | ||
this._wavrecorder.waveConfig.channels = options.channels === 1 ? android.media.AudioFormat.CHANNEL_IN_MONO : 2; | ||
this._wavrecorder.waveConfig.audioEncoding = options.encoder === ANDROID_ENCODER_PCM_16 ? android.media.AudioFormat.ENCODING_PCM_16BIT : android.media.AudioFormat.ENCODING_PCM_8BIT; | ||
this._wavrecorder.startRecording(); | ||
} | ||
if (options.bitRate) { | ||
this._recorder.setAudioEncodingBitRate(options.bitRate); | ||
} | ||
if (options.maxDuration) { | ||
this._recorder.setMaxDuration(options.maxDuration); | ||
} | ||
this._recorder.setOutputFile(options.filename); | ||
this._recorder.setOnErrorListener(new android.media.MediaRecorder.OnErrorListener({ | ||
onError: (recorder, error, extra) => { | ||
options.errorCallback({ recorder, error, extra }); | ||
} | ||
})); | ||
this._recorder.setOnInfoListener(new android.media.MediaRecorder.OnInfoListener({ | ||
onInfo: (recorder, info, extra) => { | ||
options.infoCallback({ recorder, info, extra }); | ||
} | ||
})); | ||
this._recorder.prepare(); | ||
this._recorder.start(); | ||
} | ||
@@ -76,2 +90,5 @@ getMeters() { | ||
} | ||
else if (this._wavrecorder) { | ||
this._wavrecorder.pauseRecording(); | ||
} | ||
} | ||
@@ -82,2 +99,5 @@ async resume() { | ||
} | ||
else if (this._wavrecorder) { | ||
this._wavrecorder.resumeRecording(); | ||
} | ||
} | ||
@@ -88,2 +108,5 @@ async stop() { | ||
} | ||
else if (this._wavrecorder) { | ||
this._wavrecorder.stopRecording(); | ||
} | ||
} | ||
@@ -90,0 +113,0 @@ async dispose() { |
@@ -6,2 +6,13 @@ # Change Log | ||
# [6.3.0](https://github.com/farfromrefug/nativescript-audio/compare/v6.2.11...v6.3.0) (2022-09-16) | ||
### Features | ||
* **android:** support for wav recording ([fdbf720](https://github.com/farfromrefug/nativescript-audio/commit/fdbf72075fe82f9705ace173042cc656eb097308)) | ||
## [6.2.11](https://github.com/farfromrefug/nativescript-audio/compare/v6.2.10...v6.2.11) (2022-05-06) | ||
@@ -8,0 +19,0 @@ |
@@ -0,1 +1,3 @@ | ||
export declare const ANDROID_ENCODER_PCM = 161234; | ||
export declare const ANDROID_ENCODER_PCM_16 = 1612341; | ||
export declare enum AudioPlayerEvents { | ||
@@ -2,0 +4,0 @@ seek = "seek", |
import { Utils, knownFolders, path as nsFilePath } from '@nativescript/core'; | ||
export const ANDROID_ENCODER_PCM = 161234; | ||
export const ANDROID_ENCODER_PCM_16 = 1612341; | ||
export var AudioPlayerEvents; | ||
@@ -3,0 +5,0 @@ (function (AudioPlayerEvents) { |
import { Observable } from '@nativescript/core'; | ||
export { AudioPlayerEvents } from './common'; | ||
export { AudioPlayerEvents, ANDROID_ENCODER_PCM, ANDROID_ENCODER_PCM_16 } from './common'; | ||
export interface AudioPlayerOptions { | ||
@@ -24,3 +24,2 @@ /** | ||
metering?: boolean; | ||
audioMixing?: boolean; | ||
@@ -48,2 +47,7 @@ pitch?: number; | ||
/** | ||
* Should mix audio. | ||
*/ | ||
audioMixing?: boolean; | ||
/** | ||
* iOS: The category for playing recorded music or other sounds that are central to the successful use of your app. | ||
@@ -196,3 +200,3 @@ * https://developer.apple.com/documentation/avfaudio/avaudiosessioncategory?language=objc | ||
*/ | ||
getAudioTrackDuration(): Promise<string>; | ||
getAudioTrackDuration(): Promise<number>; | ||
@@ -278,3 +282,2 @@ /** | ||
export enum AudioFocusDurationHint { | ||
@@ -281,0 +284,0 @@ /** |
@@ -41,5 +41,5 @@ import { Observable } from '@nativescript/core'; | ||
isAudioPlaying(): boolean; | ||
getAudioTrackDuration(): Promise<string>; | ||
getAudioTrackDuration(): Promise<number>; | ||
changePlayerSpeed(speed: any): void; | ||
private _reset; | ||
} |
@@ -242,3 +242,3 @@ import { Observable, Utils, knownFolders, path as nsFilePath } from '@nativescript/core'; | ||
const duration = this._player ? this._player.duration : 0; | ||
return duration.toString(); | ||
return duration; | ||
} | ||
@@ -245,0 +245,0 @@ catch (ex) { |
{ | ||
"name": "@akylas/nativescript-audio", | ||
"version": "6.2.11", | ||
"version": "6.3.0", | ||
"description": "NativeScript plugin to record and play audio.", | ||
@@ -95,3 +95,3 @@ "main": "./index", | ||
}, | ||
"gitHead": "2a62c6ea4c9e2492a0dca2dc5c042a45f4569c37" | ||
"gitHead": "3740013de42ee411c2b6bf2d85379ffd2d01e69b" | ||
} |
@@ -17,4 +17,5 @@ { | ||
"android.media.MediaRecorder:OnErrorListener*", | ||
"android.media.MediaRecorder:OnInfoListener*" | ||
"android.media.MediaRecorder:OnInfoListener*", | ||
"com.github.squti.androidwaverecorder:WaveRecorder*" | ||
] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
81095
21
1441