nativescript-audio
Advanced tools
Comparing version 6.1.0 to 6.2.0
@@ -256,6 +256,21 @@ import { Application, Observable, Utils } from '@nativescript/core'; | ||
let result = true; | ||
let focusResult = null; | ||
if (!this._mAudioFocusGranted) { | ||
const ctx = this._getAndroidContext(); | ||
const am = ctx.getSystemService(android.content.Context.AUDIO_SERVICE); | ||
const focusResult = am.requestAudioFocus(this._mOnAudioFocusChangeListener, android.media.AudioManager.STREAM_MUSIC, this._durationHint); | ||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { | ||
const playbackAttributes = new android.media.AudioAttributes.Builder() | ||
.setUsage(android.media.AudioAttributes.USAGE_MEDIA) | ||
.setContentType(android.media.AudioAttributes.CONTENT_TYPE_MUSIC) | ||
.build(); | ||
this._audioFocusRequest = new android.media.AudioFocusRequest.Builder(android.media.AudioManager.AUDIOFOCUS_GAIN) | ||
.setAudioAttributes(playbackAttributes) | ||
.setAcceptsDelayedFocusGain(true) | ||
.setOnAudioFocusChangeListener(this._mOnAudioFocusChangeListener) | ||
.build(); | ||
focusResult = am.requestAudioFocus(this._audioFocusRequest); | ||
} | ||
else { | ||
focusResult = am.requestAudioFocus(this._mOnAudioFocusChangeListener, android.media.AudioManager.STREAM_MUSIC, this._durationHint); | ||
} | ||
if (focusResult === android.media.AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { | ||
@@ -273,3 +288,10 @@ result = true; | ||
const am = ctx.getSystemService(android.content.Context.AUDIO_SERVICE); | ||
const result = am.abandonAudioFocus(this._mOnAudioFocusChangeListener); | ||
let result = null; | ||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { | ||
result = am.abandonAudioFocusRequest(this._audioFocusRequest); | ||
this._audioFocusRequest = null; | ||
} | ||
else { | ||
result = am.abandonAudioFocus(this._mOnAudioFocusChangeListener); | ||
} | ||
if (this._mediaPlayer && !preserveMP) { | ||
@@ -276,0 +298,0 @@ this._mediaPlayer.release(); |
@@ -62,2 +62,5 @@ import { Application } from '@nativescript/core'; | ||
} | ||
if (options.maxDuration) { | ||
this._recorder.setMaxDuration(options.maxDuration); | ||
} | ||
this._recorder.setOutputFile(options.filename); | ||
@@ -64,0 +67,0 @@ this._recorder.setOnErrorListener(new android.media.MediaRecorder.OnErrorListener({ |
@@ -57,2 +57,3 @@ import { Observable } from '@nativescript/core'; | ||
start(options) { | ||
this._recorderOptions = options; | ||
return new Promise((resolve, reject) => { | ||
@@ -70,3 +71,8 @@ try { | ||
const recordSetting = NSMutableDictionary.alloc().init(); | ||
recordSetting.setValueForKey(NSNumber.numberWithInt(kAudioFormatMPEG4AAC), 'AVFormatIDKey'); | ||
if (options.format) { | ||
recordSetting.setValueForKey(NSNumber.numberWithInt(options.format), 'AVFormatIDKey'); | ||
} | ||
else { | ||
recordSetting.setValueForKey(NSNumber.numberWithInt(kAudioFormatMPEG4AAC), 'AVFormatIDKey'); | ||
} | ||
recordSetting.setValueForKey(NSNumber.numberWithInt(64), 'AVEncoderAudioQualityKey'); | ||
@@ -86,4 +92,9 @@ recordSetting.setValueForKey(NSNumber.numberWithFloat(16000.0), 'AVSampleRateKey'); | ||
} | ||
this._recorder.prepareToRecord(); | ||
this._recorder.record(); | ||
if (options.maxDuration) { | ||
this._recorder.recordForDuration(options.maxDuration / 1000); | ||
} | ||
else { | ||
this._recorder.prepareToRecord(); | ||
this._recorder.record(); | ||
} | ||
resolve(); | ||
@@ -90,0 +101,0 @@ } |
{ | ||
"name": "nativescript-audio", | ||
"version": "6.1.0", | ||
"version": "6.2.0", | ||
"description": "NativeScript plugin to record and play audio.", | ||
@@ -133,4 +133,3 @@ "main": "audio", | ||
"dependencies": { | ||
"nativescript-permissions": "~1.3.9", | ||
"ts-node": "^9.0.0" | ||
"nativescript-permissions": "~1.3.9" | ||
}, | ||
@@ -145,2 +144,3 @@ "devDependencies": { | ||
"rimraf": "^3.0.2", | ||
"ts-node": "^9.0.0", | ||
"ts-patch": "^1.3.0", | ||
@@ -147,0 +147,0 @@ "tslint": "~6.1.3", |
60268
1
1343
11
- Removedts-node@^9.0.0
- Removedarg@4.1.3(transitive)
- Removedbuffer-from@1.1.2(transitive)
- Removedcreate-require@1.1.1(transitive)
- Removeddiff@4.0.2(transitive)
- Removedmake-error@1.3.6(transitive)
- Removedsource-map@0.6.1(transitive)
- Removedsource-map-support@0.5.21(transitive)
- Removedts-node@9.1.1(transitive)
- Removedtypescript@5.7.3(transitive)
- Removedyn@3.1.1(transitive)