@akylas/nativescript-audio
Advanced tools
Comparing version 6.2.8 to 6.2.9
@@ -6,2 +6,10 @@ # Change Log | ||
## [6.2.9](https://github.com/farfromrefug/nativescript-audio/compare/v6.2.8...v6.2.9) (2022-02-08) | ||
**Note:** Version bump only for package @akylas/nativescript-audio | ||
## [6.2.8](https://github.com/farfromrefug/nativescript-audio/compare/v6.2.7...v6.2.8) (2022-02-07) | ||
@@ -8,0 +16,0 @@ |
@@ -29,2 +29,4 @@ import { Observable } from '@nativescript/core'; | ||
initFromFile(options: AudioPlayerOptions): Promise<any>; | ||
private prepareAudioSession; | ||
private handleStartPlayer; | ||
playFromFile(options: AudioPlayerOptions): Promise<any>; | ||
@@ -31,0 +33,0 @@ initFromUrl(options: AudioPlayerOptions): Promise<any>; |
@@ -65,7 +65,38 @@ import { Observable, Utils, knownFolders, path as nsFilePath } from '@nativescript/core'; | ||
} | ||
prepareAudioSession(options) { | ||
this.completeCallback = options.completeCallback; | ||
this.errorCallback = options.errorCallback; | ||
this.infoCallback = options.infoCallback; | ||
const audioSession = AVAudioSession.sharedInstance(); | ||
audioSession.setCategoryModeRouteSharingPolicyOptionsError(options.sessionCategory !== undefined ? options.sessionCategory : AVAudioSessionCategoryAmbient, options.sessionMode !== undefined ? options.sessionMode : AVAudioSessionModeDefault, options.sessionRouteSharingPolicy !== undefined ? options.sessionRouteSharingPolicy : 0, options.audioMixing ? 1 : 2, null); | ||
const output = audioSession.currentRoute.outputs.lastObject.portType; | ||
if (output.match(/Receiver/)) { | ||
try { | ||
audioSession.setCategoryError(AVAudioSessionCategoryPlayAndRecord); | ||
audioSession.overrideOutputAudioPortError(1936747378); | ||
audioSession.setActiveError(true); | ||
} | ||
catch (err) { | ||
console.error('setting audioSession catergory failed', err); | ||
} | ||
} | ||
} | ||
handleStartPlayer(options) { | ||
if (this.delegate === undefined) { | ||
this.delegate = TNSPlayerDelegate.initWithOwner(this); | ||
} | ||
this._player.delegate = this.delegate; | ||
this._player.enableRate = true; | ||
if (options.metering) { | ||
this._player.meteringEnabled = true; | ||
} | ||
if (options.loop) { | ||
this._player.numberOfLoops = -1; | ||
} | ||
if (options.autoPlay !== false) { | ||
this._player.play(); | ||
} | ||
} | ||
playFromFile(options) { | ||
return new Promise((resolve, reject) => { | ||
if (options.autoPlay !== false) { | ||
options.autoPlay = true; | ||
} | ||
try { | ||
@@ -76,18 +107,3 @@ let fileName = Utils.isString(options.audioFile) ? options.audioFile.trim() : ''; | ||
} | ||
this.completeCallback = options.completeCallback; | ||
this.errorCallback = options.errorCallback; | ||
this.infoCallback = options.infoCallback; | ||
const audioSession = AVAudioSession.sharedInstance(); | ||
audioSession.setCategoryModeRouteSharingPolicyOptionsError(options.sessionCategory || AVAudioSessionCategoryAmbient, options.sessionMode || AVAudioSessionModeDefault, options.sessionRouteSharingPolicy || 1, options.audioMixing ? 1 : 2, null); | ||
const output = audioSession.currentRoute.outputs.lastObject.portType; | ||
if (output.match(/Receiver/)) { | ||
try { | ||
audioSession.setCategoryError(AVAudioSessionCategoryPlayAndRecord); | ||
audioSession.overrideOutputAudioPortError(1936747378); | ||
audioSession.setActiveError(true); | ||
} | ||
catch (err) { | ||
console.error('setting audioSession catergory failed', err); | ||
} | ||
} | ||
this.prepareAudioSession(options); | ||
const errorRef = new interop.Reference(); | ||
@@ -100,16 +116,3 @@ this._player = AVAudioPlayer.alloc().initWithContentsOfURLError(NSURL.fileURLWithPath(fileName), errorRef); | ||
else if (this._player) { | ||
if (this.delegate === undefined) { | ||
this.delegate = TNSPlayerDelegate.initWithOwner(this); | ||
} | ||
this._player.delegate = this.delegate; | ||
this._player.enableRate = true; | ||
if (options.metering) { | ||
this._player.meteringEnabled = true; | ||
} | ||
if (options.loop) { | ||
this._player.numberOfLoops = -1; | ||
} | ||
if (options.autoPlay) { | ||
this._player.play(); | ||
} | ||
this.handleStartPlayer(options); | ||
resolve(null); | ||
@@ -135,5 +138,2 @@ } | ||
return new Promise((resolve, reject) => { | ||
if (options.autoPlay !== false) { | ||
options.autoPlay = true; | ||
} | ||
try { | ||
@@ -145,36 +145,12 @@ this._task = NSURLSession.sharedSession.dataTaskWithURLCompletionHandler(NSURL.URLWithString(options.audioFile), (data, response, error) => { | ||
} | ||
reject(); | ||
reject(error); | ||
} | ||
this.completeCallback = options.completeCallback; | ||
this.errorCallback = options.errorCallback; | ||
this.infoCallback = options.infoCallback; | ||
const audioSession = AVAudioSession.sharedInstance(); | ||
audioSession.setCategoryModeRouteSharingPolicyOptionsError(options.sessionCategory || AVAudioSessionCategoryAmbient, options.sessionMode || AVAudioSessionModeDefault, options.sessionRouteSharingPolicy || 1, options.audioMixing ? 1 : 2, null); | ||
const output = audioSession.currentRoute.outputs.lastObject.portType; | ||
if (output.match(/Receiver/)) { | ||
try { | ||
audioSession.setCategoryError(AVAudioSessionCategoryPlayAndRecord); | ||
audioSession.overrideOutputAudioPortError(1936747378); | ||
audioSession.setActiveError(true); | ||
} | ||
catch (err) { | ||
console.error('Setting audioSession category failed.', err); | ||
} | ||
} | ||
this.prepareAudioSession(options); | ||
const errorRef = new interop.Reference(); | ||
this._player = AVAudioPlayer.alloc().initWithDataError(data, errorRef); | ||
if (errorRef && errorRef.value) { | ||
reject(errorRef.value); | ||
return; | ||
return reject(errorRef.value); | ||
} | ||
else if (this._player) { | ||
this._player.delegate = TNSPlayerDelegate.initWithOwner(this); | ||
this._player.enableRate = true; | ||
this._player.numberOfLoops = options.loop ? -1 : 0; | ||
if (options.metering) { | ||
this._player.meteringEnabled = true; | ||
} | ||
if (options.autoPlay) { | ||
this._player.play(); | ||
} | ||
this.handleStartPlayer(options); | ||
resolve(null); | ||
@@ -181,0 +157,0 @@ } |
{ | ||
"name": "@akylas/nativescript-audio", | ||
"version": "6.2.8", | ||
"version": "6.2.9", | ||
"description": "NativeScript plugin to record and play audio.", | ||
@@ -95,3 +95,3 @@ "main": "./index", | ||
}, | ||
"gitHead": "de4a63875707c1dd27d5d48ca44aeee7f12b8d72" | ||
"gitHead": "5ac784b3e3a2e69ece3328634c3d1001fcc44c8b" | ||
} |
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
77620
1395