Nativescript-sound - sound is not played?


#1

var sound = require(“nativescript-sound”);

No errors in console ( and if I put other non-existing filename - then it shows an error : “file not found”) - so it does see the file.

Why doesn’t it play ?

manifest

tnsinfo :
image

EDIT

If I put

  let tada = sound.create("~/raw/beep.mp3");

as a field ( outside a function):

  tada = sound.create("~/raw/beep.mp3");

then it does work.

I don’t want to initialize it as a field.

Is it possible to use it as a pseudo : Promise(loadFile).then(playFile) ?


#2

Hi @Royi_Namir
Here’s how I used {N} sound plugin in my app.

I created a “sounds” folder in my app folder. (not inside App_Resources), and placed my sound file there, (an mp3 file).

And then to play the song,

const TNSPlayer = require("nativescript-audio").TNSPlayer;

const player = new TNSPlayer();
        player
            .initFromFile({
                audioFile: "~/sounds/name_of_file.mp3",
                loop: false
            })
            .then(() => {
                player.play();
            });

Cheers! Happy NativeScripting :slight_smile:


#3

@multishiv19

That’s another plugin.

:slight_smile:

i’m using nativescript-sound. not nativescript-audio


#4

Try switching to nativescript-audio then! I has worked well for me

Nativescript-sound was last published 2 years ago. It might be outdated