Nativescript-audio plugin errors: 'Error Domain' and 'null is not an object'


#1

I am using the nativescript-audio plugin (https://github.com/nstudio/nativescript-audio). Focusing on ios for now.

Any solutions for these errors below?

When the player loads, I get this error:

CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:1479:24: ERROR Error: Uncaught (in promise): Error Domain=NSOSStatusErrorDomain Code=2003334207 “(null)”

If I hit play, I get these errors:

CONSOLE LOG file:///app/tns_modules/nativescript-audio/common.js:18:20: TNSPlayer play error,TypeError: null is not an object (evaluating ‘_this._player.play’)

CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:1479:24: ERROR Error: Uncaught (in promise): TypeError: null is not an object (evaluating ‘_this._player.play’)

The github repo has some folks mentioning errors like this, but, as far as I can tell, there are no resolutions offered there that offer new code changes that are applicable. I can open a new issue there if that is more appropriate.

Here is my code:

ts:

import {Component} from "@angular/core";
import { TNSPlayer } from "nativescript-audio";
@Component({
    selector: "page2",
    templateUrl: "./components/page2/page2.component.html",
})
export class Page2Component {
	 private _player: TNSPlayer;

  public constructor() {
    this._player = new TNSPlayer();
    this._player.debug = true; // set true to enable TNSPlayer console logs for debugging.
    this._player
      .initFromFile({
        audioFile: "https://soundcloud.com/vancejoy/02-riptide"
        loop: false
      })
 }

togglePlay(){
 if (this._player.isAudioPlaying()) {
      this._player.pause();
    } else {
      this._player.play();
    }
}

}

html:

<ActionBar title="Page 2">
    <ActionItem text="play" (tap)="togglePlay()" ios.position="right"></ActionItem>
</ActionBar>

I saw someone with similar errors say they fixed with proper plugin implementation. I believe I have followed correct implementation here:

$ tns plugin add nativescript-audio

(and then imports in the ts file per the above code)


Issue with nativescript-audio
#2

The problems I mentioned above continue. I found Brad Martin’s helpful tutorial on downloading plugins: https://bradmartin.net/2016/07/20/ahhh-this-nativescript-plugin-doesnt-work/ , but I still get these errors after following those steps.

Any ideas? Are people able to get this to work with remote audio on ios and nativescript 3?


#3

Change initFromFile to initFromUrl.


#4

Thank you. I now see that in the TNSPlayerMethods identified on the repo: https://github.com/nstudio/nativescript-audio.

Saying initFromURL, instead of initFromFile, is a big step forward. From what I can tell right now, the remote url must be specified as an m4a file (or, I assume, mp3 file) in order to play.

So, audio from a url that ends in m4a seems to play. Audio from a url that is not specified in a sound format does not play, so far as I can tell. So for example, the following code gives the same errors as noted earlier.

import { TNSPlayer } from "nativescript-audio";togglePlay(){
....
 public constructor() {
    this._player = new TNSPlayer();
    this._player.debug = true; // set true to enable TNSPlayer console logs for debugging.
    this._player
      .initFromUrl({
        audioFile: "https://soundcloud.com/vancejoy/02-riptide", 
        loop: false,
      })
 }

togglePlay(){
 if (this._player.isAudioPlaying()) {
   console.log('pause it')
      this._player.pause();
  } else {
      console.log('play it')
      this._player.play();
  }
}

This may be the expected behavior of the plugin. If anyone knows of how to play a url that is not already specified in a sound format, would be helpful to know. The solution may be to convert the url into a sound format, but I am not sure how to do that through code.


#5

Well, that https://soundcloud.com/vancejoy/02-riptide link is actually a link to a website, not an audio file. I’m using the nativescript-audio plugin to play links like https://mydomain.com/myfile (no extension, but it is an mp3 file).


#6

Thanks. I see that now, per my earlier reply. One could still play the soundcloud link but would have to use a webview/iframe, or something like that.

I am still curious about the best way to take the sound from that and convert to a m4a or mp3 (on the user’s phone, so through the app), but the plugin seems to be working for its intended purpose well (playing files, even remote files, that are in a sound format).


#7

If you want to play soundcloud within app natively using plugin, you will have to use their Http APIs and find steam / download url of a track.


#8

Makes sense. I see some download options here:https://developers.soundcloud.com/docs/api/reference#tracks

Thanks.