New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nativescript-audio

Package Overview
Dependencies
Maintainers
3
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nativescript-audio - npm Package Compare versions

Comparing version 5.0.5 to 5.1.0

104

android/player.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TNSPlayer = void 0;
var app = require("tns-core-modules/application");

@@ -9,4 +10,5 @@ var observable_1 = require("tns-core-modules/data/observable");

var TNSPlayer = (function () {
function TNSPlayer() {
function TNSPlayer(durationHint) {
var _this = this;
if (durationHint === void 0) { durationHint = options_1.AudioFocusDurationHint.AUDIOFOCUS_GAIN; }
this._mAudioFocusGranted = false;

@@ -47,4 +49,3 @@ this._mOnAudioFocusChangeListener = new android.media.AudioManager.OnAudioFocusChangeListener({

});
this._mAudioFocusGranted = this._requestAudioFocus();
common_1.TNS_Player_Log('_mAudioFocusGranted', this._mAudioFocusGranted);
this._durationHint = durationHint;
}

@@ -58,3 +59,3 @@ Object.defineProperty(TNSPlayer.prototype, "events", {

},
enumerable: true,
enumerable: false,
configurable: true

@@ -66,3 +67,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -74,3 +75,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -89,3 +90,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -102,3 +103,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -110,3 +111,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -128,10 +129,5 @@ });

}
_this._options = options;
var audioPath = common_1.resolveAudioFilePath(options.audioFile);
common_1.TNS_Player_Log('audioPath', audioPath);
if (!_this._player) {
common_1.TNS_Player_Log('android mediaPlayer is not initialized, creating new instance');
_this._player = new android.media.MediaPlayer();
}
_this._mAudioFocusGranted = _this._requestAudioFocus();
common_1.TNS_Player_Log('_mAudioFocusGranted', _this._mAudioFocusGranted);
_this._player.setAudioStreamType(android.media.AudioManager.STREAM_MUSIC);

@@ -150,23 +146,2 @@ common_1.TNS_Player_Log('resetting mediaPlayer...');

}
if (options.completeCallback) {
_this._player.setOnCompletionListener(new android.media.MediaPlayer.OnCompletionListener({
onCompletion: function (mp) {
if (options.loop === true) {
mp.seekTo(5);
mp.start();
}
options.completeCallback({ player: mp });
}
}));
}
if (options.errorCallback) {
_this._player.setOnErrorListener(new android.media.MediaPlayer.OnErrorListener({
onError: function (player, error, extra) {
_this._player.reset();
common_1.TNS_Player_Log('errorCallback', error);
options.errorCallback({ player: player, error: error, extra: extra });
return true;
}
}));
}
if (options.infoCallback) {

@@ -192,2 +167,3 @@ _this._player.setOnInfoListener(new android.media.MediaPlayer.OnInfoListener({

catch (ex) {
_this._abandonAudioFocus();
common_1.TNS_Player_Log('playFromFile error', ex);

@@ -218,2 +194,3 @@ reject(ex);

_this._player.pause();
_this._abandonAudioFocus(true);
_this._sendEvent(options_1.AudioPlayerEvents.paused);

@@ -234,2 +211,7 @@ }

if (_this._player && !_this._player.isPlaying()) {
_this._mAudioFocusGranted = _this._requestAudioFocus();
common_1.TNS_Player_Log('_mAudioFocusGranted', _this._mAudioFocusGranted);
if (!_this._mAudioFocusGranted) {
throw new Error('Could not request audio focus');
}
_this._sendEvent(options_1.AudioPlayerEvents.started);

@@ -255,3 +237,3 @@ app.android.foregroundActivity.setVolumeControlStream(android.media.AudioManager.STREAM_MUSIC);

common_1.TNS_Player_Log('resume');
this._player.start();
this.play();
this._sendEvent(options_1.AudioPlayerEvents.started);

@@ -301,2 +283,3 @@ }

_this._player.reset();
_this._options = undefined;
common_1.TNS_Player_Log('unregisterBroadcastReceiver ACTION_AUDIO_BECOMING_NOISY...');

@@ -347,7 +330,7 @@ app.android.unregisterBroadcastReceiver(android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY);

TNSPlayer.prototype._requestAudioFocus = function () {
var result = false;
var result = true;
if (!this._mAudioFocusGranted) {
var ctx = this._getAndroidContext();
var am = ctx.getSystemService(android.content.Context.AUDIO_SERVICE);
var focusResult = am.requestAudioFocus(this._mOnAudioFocusChangeListener, android.media.AudioManager.STREAM_MUSIC, android.media.AudioManager.AUDIOFOCUS_GAIN);
var focusResult = am.requestAudioFocus(this._mOnAudioFocusChangeListener, android.media.AudioManager.STREAM_MUSIC, this._durationHint);
if (focusResult === android.media.AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {

@@ -363,6 +346,11 @@ result = true;

};
TNSPlayer.prototype._abandonAudioFocus = function () {
TNSPlayer.prototype._abandonAudioFocus = function (preserveMP) {
if (preserveMP === void 0) { preserveMP = false; }
var ctx = this._getAndroidContext();
var am = ctx.getSystemService(android.content.Context.AUDIO_SERVICE);
var result = am.abandonAudioFocus(this._mOnAudioFocusChangeListener);
if (this._mediaPlayer && !preserveMP) {
this._mediaPlayer.release();
this._mediaPlayer = undefined;
}
if (result === android.media.AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {

@@ -390,4 +378,40 @@ this._mAudioFocusGranted = false;

};
Object.defineProperty(TNSPlayer.prototype, "_player", {
get: function () {
var _this = this;
if (!this._mediaPlayer && this._options) {
this._mediaPlayer = new android.media.MediaPlayer();
common_1.TNS_Player_Log('android mediaPlayer is not initialized, creating new instance');
this._mediaPlayer.setOnCompletionListener(new android.media.MediaPlayer.OnCompletionListener({
onCompletion: function (mp) {
if (_this._options && _this._options.completeCallback) {
if (_this._options.loop === true) {
mp.seekTo(5);
mp.start();
}
_this._options.completeCallback({ player: mp });
}
if (_this._options && !_this._options.loop) {
_this._abandonAudioFocus();
}
}
}));
this._mediaPlayer.setOnErrorListener(new android.media.MediaPlayer.OnErrorListener({
onError: function (player, error, extra) {
if (_this._options && _this._options.errorCallback) {
_this._options.errorCallback({ player: player, error: error, extra: extra });
}
common_1.TNS_Player_Log('errorCallback', error);
_this.dispose();
return true;
}
}));
}
return this._mediaPlayer;
},
enumerable: false,
configurable: true
});
return TNSPlayer;
}());
exports.TNSPlayer = TNSPlayer;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TNSRecorder = void 0;
var permissions = require("nativescript-permissions");
var app = require("tns-core-modules/application");
require("../async-await");
var common_1 = require("../common");

@@ -14,3 +14,3 @@ var TNSRecorder = (function () {

},
enumerable: true,
enumerable: false,
configurable: true

@@ -22,3 +22,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -25,0 +25,0 @@ });

"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./options"));
__export(require("./android/player"));
__export(require("./android/recorder"));
__exportStar(require("./options"), exports);
__exportStar(require("./android/player"), exports);
__exportStar(require("./android/recorder"), exports);
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./options"));
__export(require("./ios/player"));
__export(require("./ios/recorder"));
__exportStar(require("./options"), exports);
__exportStar(require("./ios/player"), exports);
__exportStar(require("./ios/recorder"), exports);
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveAudioFilePath = exports.isStringUrl = exports.TNS_Recorder_Log = exports.TNSRecorderUtil = exports.TNS_Player_Log = exports.TNSPlayerUtil = void 0;
var fs = require("tns-core-modules/file-system");

@@ -4,0 +5,0 @@ var types_1 = require("tns-core-modules/utils/types");

@@ -198,2 +198,9 @@ import { Observable } from 'tns-core-modules/data/observable';

/**
* @param {AudioFocusDurationHint} durationHint - Determines differents behaviors by
* the system and the other application that previously held audio focus.
* See the {@link https://developer.android.com/reference/android/media/AudioFocusRequest#the-different-types-of-focus-requests different types of focus requests}
*/
constructor(durationHint?: AudioFocusDurationHint);
initFromFile(options: AudioPlayerOptions): Promise<any>;

@@ -332,2 +339,37 @@

}
export const AudioPlayerEvents: IAudioPlayerEvents;
export enum AudioFocusDurationHint {
/**
* Expresses the fact that your application is now the sole source
* of audio that the user is listening to. The duration of the
* audio playback is unknown, and is possibly very long: after the
* user finishes interacting with your application, (s)he doesn’t
* expect another audio stream to resume.
*/
AUDIOFOCUS_GAIN = android.media.AudioManager.AUDIOFOCUS_GAIN,
/**
* For a situation when you know your application is temporarily
* grabbing focus from the current owner, but the user expects
* playback to go back to where it was once your application no
* longer requires audio focus.
*/
AUDIOFOCUS_GAIN_TRANSIENT = android.media.AudioManager.AUDIOFOCUS_GAIN_TRANSIENT,
/**
* This focus request type is similar to AUDIOFOCUS_GAIN_TRANSIENT
* for the temporary aspect of the focus request, but it also
* expresses the fact during the time you own focus, you allow
* another application to keep playing at a reduced volume,
* “ducked”.
*/
AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK = android.media.AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK,
/**
* Also for a temporary request, but also expresses that your
* application expects the device to not play anything else. This
* is typically used if you are doing audio recording or speech
* recognition, and don’t want for examples notifications to be
* played by the system during that time.
*/
AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE = android.media.AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TNSPlayer = void 0;
var file_system_1 = require("tns-core-modules/file-system");

@@ -15,3 +16,3 @@ var types_1 = require("tns-core-modules/utils/types");

},
enumerable: true,
enumerable: false,
configurable: true

@@ -23,3 +24,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -36,3 +37,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -49,3 +50,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -57,3 +58,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -75,3 +76,2 @@ });

try {
var audioPath = void 0;
var fileName = types_1.isString(options.audioFile) ? options.audioFile.trim() : '';

@@ -78,0 +78,0 @@ if (fileName.indexOf('~/') === 0) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TNSRecorder = void 0;
var common_1 = require("../common");

@@ -16,3 +17,3 @@ var TNSRecorder = (function (_super) {

},
enumerable: true,
enumerable: false,
configurable: true

@@ -24,3 +25,3 @@ });

},
enumerable: true,
enumerable: false,
configurable: true

@@ -36,3 +37,3 @@ });

else {
reject("Record permissions denied");
reject('Record permissions denied');
}

@@ -39,0 +40,0 @@ });

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AudioFocusDurationHint = exports.AudioPlayerEvents = void 0;
exports.AudioPlayerEvents = {

@@ -8,1 +9,8 @@ seek: 'seek',

};
var AudioFocusDurationHint;
(function (AudioFocusDurationHint) {
AudioFocusDurationHint[AudioFocusDurationHint["AUDIOFOCUS_GAIN"] = android.media.AudioManager.AUDIOFOCUS_GAIN] = "AUDIOFOCUS_GAIN";
AudioFocusDurationHint[AudioFocusDurationHint["AUDIOFOCUS_GAIN_TRANSIENT"] = android.media.AudioManager.AUDIOFOCUS_GAIN_TRANSIENT] = "AUDIOFOCUS_GAIN_TRANSIENT";
AudioFocusDurationHint[AudioFocusDurationHint["AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK"] = android.media.AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK] = "AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK";
AudioFocusDurationHint[AudioFocusDurationHint["AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE"] = android.media.AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK] = "AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE";
})(AudioFocusDurationHint = exports.AudioFocusDurationHint || (exports.AudioFocusDurationHint = {}));
{
"name": "nativescript-audio",
"version": "5.0.5",
"version": "5.1.0",
"description": "NativeScript plugin to record and play audio.",

@@ -15,27 +15,12 @@ "main": "audio",

"tsc": "tsc -skipLibCheck",
"build": "npm i && npm run tsc",
"link": "npm i && cd ../demo && npm i && cd ../src && npm run plugin.link",
"demo.reset": "cd ../demo && rimraf platforms",
"demo.ios": "npm run preparedemo && cd ../demo && tns run ios --syncAllFiles",
"demo.ios.device": "npm run preparedemo && cd ../demo && tns platform remove ios && tns run ios",
"demo.android": "npm run preparedemo && cd ../demo && tns run android --syncAllFiles",
"test": "npm run tslint && npm run tslint.demo && cd ../demo && tns build ios && tns build android",
"test.ios": "cd ../demo && tns platform remove ios && tns test ios --emulator",
"test.ios.device": "cd ../demo && tns platform remove ios && tns test ios",
"test.android": "cd ../demo && tns platform remove android && tns test android --justlaunch",
"preparedemo": "npm run build && cd ../demo && tns plugin remove nativescript-audio && tns plugin add ../src && tns install",
"setup": "npm run build && cd ../demo && npm i",
"plugin.link": "npm link && cd ../demo && npm link nativescript-audio && cd ../src",
"plugin.tscwatch": "npm run tsc -- -w",
"setupandinstall": "npm i && cd ../demo && npm i && cd ../src && npm run build && cd ../demo && tns plugin add ../src && cd ../src",
"tslint": "tslint --config '../tslint.json' '*.ts' --exclude '**/node_modules/**'",
"tslint.demo": "tslint --config '../tslint.json' '../demo/app/*.ts' --exclude '**/node_modules/**'",
"build": "npm i && tsc",
"tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\" --exclude \"*demo*/platforms/**\"",
"ci.tslint": "npm i && tslint '**/*.ts' --config '../tslint.json' --exclude '**/node_modules/**'",
"prepublishOnly": "npm run build",
"precommit": "lint-staged",
"development.setup": "npm run setup && npm link && cd ../demo && npm link nativescript-audio && cd ../src",
"demo.ios": "npm run setup && cd ../demo && tns run ios",
"demo.android": "npm run setup && cd ../demo && tns run android",
"setup": "npm i && tsc",
"generate.typings.ios": "cd ../demo && TNS_DEBUG_METADATA_PATH=\"$(pwd)/metadata\" tns build ios && TNS_TYPESCRIPT_DECLARATIONS_PATH=\"$(pwd)/typings\" tns build ios && echo 'Now look for your library typings in demo/typings!'"
},
"lint-staged": {
"*.ts": [
"**/*.{js, css, ts, json, scss, html, xml, md}": [
"prettier --write",

@@ -45,2 +30,8 @@ "git add"

},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "npm run tslint"
}
},
"repository": {

@@ -134,2 +125,6 @@ "type": "git",

"url": "https://github.com/DickSmith"
},
{
"name": "Daniel Pereira",
"url": "https://github.com/danieldspx"
}

@@ -144,14 +139,14 @@ ],

"dependencies": {
"nativescript-permissions": "~1.2.3"
"nativescript-permissions": "~1.3.9"
},
"devDependencies": {
"husky": "^0.14.3",
"lint-staged": "^7.2.0",
"prettier": "^1.13.5",
"tns-core-modules": "^4.1.0",
"tns-platform-declarations": "^4.1.0",
"rimraf": "^2.5.0",
"tslint": "~5.10.0",
"typescript": "~2.8.1"
"husky": "^4.2.5",
"lint-staged": "^10.2.7",
"prettier": "^2.0.5",
"tns-core-modules": "^6.5.2",
"tns-platform-declarations": "^6.5.2",
"rimraf": "^2.6.3",
"tslint": "~6.0.0",
"typescript": "~3.9.3"
}
}

@@ -7,2 +7,5 @@ <a align="center" href="https://www.npmjs.com/package/nativescript-audio">

<p align="center">
<a href="https://www.npmjs.com/package/@nstudio/nativescript-audio">
<img src="https://github.com/nstudio/nativescript-audio/workflows/Build%20CI/badge.svg" alt="Action Build">
</a>
<a href="https://www.npmjs.com/package/nativescript-audio">

@@ -14,17 +17,6 @@ <img src="https://img.shields.io/npm/v/nativescript-audio.svg" alt="npm">

</a>
<a href="https://github.com/nstudio/nativescript-audio/stargazers">
<img src="https://img.shields.io/github/stars/nstudio/nativescript-audio.svg" alt="stars">
</a>
<a href="https://github.com/nstudio/nativescript-audio/network">
<img src="https://img.shields.io/github/forks/nstudio/nativescript-audio.svg" alt="forks">
</a>
<a href="https://github.com/nstudio/nativescript-audio/blob/master/LICENSE.md">
<img src="https://img.shields.io/github/license/nstudio/nativescript-audio.svg" alt="license">
</a>
<a href="https://paypal.me/bradwayne88">
<img src="https://img.shields.io/badge/Donate-PayPal-green.svg" alt="donate">
</a>
<a href="http://nstudio.io">
<img src="./screens/nstudio-banner.png" alt="nStudio banner">
</a>
<br />
<h5 align="center">Do you need assistance on your project or plugin? Contact the nStudio team anytime at <a href="mailto:team@nstudio.io">team@nstudio.io</a> to get up to speed with the best practices in mobile and web app development.

@@ -71,2 +63,8 @@ </h5>

this._player = new TNSPlayer();
// You can pass a duration hint to control the behavior of other application that may
// be holding audio focus.
// For example: new TNSPlayer(AudioFocusDurationHint.AUDIOFOCUS_GAIN_TRANSIENT);
// Then when you play a song, the previous owner of the
// audio focus will stop. When your song stops
// the previous holder will resume.
this._player.debug = true; // set true to enable TNSPlayer console logs for debugging.

@@ -78,6 +76,6 @@ this._player

completeCallback: this._trackComplete.bind(this),
errorCallback: this._trackError.bind(this)
errorCallback: this._trackError.bind(this),
})
.then(() => {
this._player.getAudioTrackDuration().then(duration => {
this._player.getAudioTrackDuration().then((duration) => {
// iOS: duration is in seconds

@@ -122,11 +120,11 @@ // Android: duration is in milliseconds

loop: false,
completeCallback: function() {
completeCallback: function () {
console.log('finished playing');
},
errorCallback: function(errorObject) {
errorCallback: function (errorObject) {
console.log(JSON.stringify(errorObject));
},
infoCallback: function(args) {
infoCallback: function (args) {
console.log(JSON.stringify(args));
}
},
};

@@ -136,6 +134,6 @@

.playFromUrl(playerOptions)
.then(function(res) {
.then(function (res) {
console.log(res);
})
.catch(function(err) {
.catch(function (err) {
console.log('something went wrong...', err);

@@ -184,3 +182,3 @@ });

| _resume()_: `void` | Resume playback. |
| _seekTo(time:number)_: `Promise<boolean>` | Seek to position of track (in seconds). |
| _seekTo(time:number)_: `Promise<boolean>` | Seek to position of track (in seconds). |
| _dispose()_: `Promise<boolean>` | Free up resources when done playing audio. |

@@ -187,0 +185,0 @@ | _isAudioPlaying()_: `boolean` | Determine if player is playing. |

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc