Skip to content

Commit

Permalink
fix(Android): guard against undefined player instance
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanWalker committed Jun 14, 2017
1 parent 72d559f commit 42b9541
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-audio",
"version": "3.4.2",
"version": "3.4.3",
"description": "NativeScript plugin to record and play audio.",
"main": "audio",
"typings": "index.d.ts",
Expand Down
20 changes: 11 additions & 9 deletions src/android/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ export class TNSPlayer implements TNSPlayerI {
public pause(): Promise<any> {
return new Promise((resolve, reject) => {
try {
if (this.player.isPlaying()) {
if (this.player && this.player.isPlaying()) {
this.player.pause();
resolve(true);
}
resolve(true);
} catch (ex) {
reject(ex);
}
Expand All @@ -182,18 +182,18 @@ export class TNSPlayer implements TNSPlayerI {
public play(): Promise<any> {
return new Promise((resolve, reject) => {
try {
if (!this.player.isPlaying()) {
if (this.player && !this.player.isPlaying()) {
this.player.start();
resolve(true);
}
resolve(true);
} catch (ex) {
reject(ex);
}
});
}

public resume(): void {
this.player.start();
this.player && this.player.start();
}


Expand All @@ -202,8 +202,8 @@ export class TNSPlayer implements TNSPlayerI {
try {
if (this.player) {
this.player.seekTo(time);
resolve(true);
}
resolve(true);
} catch (ex) {
reject(ex);
}
Expand All @@ -225,7 +225,9 @@ export class TNSPlayer implements TNSPlayerI {
public dispose(): Promise<any> {
return new Promise((resolve, reject) => {
try {
this.player.release();
if (this.player) {
this.player.release();
}
resolve();
} catch (ex) {
reject(ex);
Expand All @@ -234,13 +236,13 @@ export class TNSPlayer implements TNSPlayerI {
}

public isAudioPlaying(): boolean {
return this.player.isPlaying();
return this.player && this.player.isPlaying();
}

public getAudioTrackDuration(): Promise<string> {
return new Promise((resolve, reject) => {
try {
var duration = this.player.getDuration();
var duration = this.player ? this.player.getDuration() : 0;
resolve(duration.toString());
} catch (ex) {
reject(ex);
Expand Down

0 comments on commit 42b9541

Please sign in to comment.