jbristowe / nativescript-sound

MIT License
12 stars 15 forks source link

Audio is not played on NativeScript 1.5 #3

Open calebeaires opened 8 years ago

calebeaires commented 8 years ago

It seems that the plugin does not work with NativeScript 1.5. I put the "sounds" folder with the file on "app" folder, then used this code:

var sound = require("nativescript-sound");
tap = sound.create("~/sounds/tap.mp3");
tap.play();

Its is not playing the sound!

NathanWalker commented 8 years ago

@calebeaires I'm using 1.5.2 and it's working fine. Still having an issue?

mudlabs commented 6 years ago

I can confirm this method works in NativeScript 3.4.0.

But it's the only method working for Android. See issue #11

EdJones commented 5 years ago

I'm trying to use in NativeScript-Vue. So far, (with tns preview) Sounds folder is not being built into iOS platform bundle. So nativescript-sound can't find the sound file.

JKcolab commented 4 years ago

Hi - I'm getting Sound not initialized; file not found when I'm trying to initialise the sound using

var beep = sound.create("~/sounds/beep.mp3")

I've checked and the mp3 is in that folder. This is using Android and Nativescript Vue.

EdJones commented 4 years ago

@JKcolab Did you see my comment above? Nativescript-vue doesn't automatically include folders like ~/sounds/.

JKcolab commented 4 years ago

Hi EdJones, it doesn't for Android either. I even put the file in the images folder and changed the line to

var beep = sound.create("~/images/beep.mp3")

but got the same error. Images in that folder do work however.

I hacked the sound-common.js script to show the path it was looking at and it's looking at

data/data/org.nativescript.[name of app]/files/app/images/beep.mp3 but the file isn't found there.

I've put the sound file in other areas, like the app folder (and appropriately changed the path in the command) but still no joy.

mudlabs commented 4 years ago

@EdJones @JKcolab

This might be a problem with webpack.config.js. Webpack may not be packaging your sound files to the out director.

Look for this section in webpack.config.js

// Copy assets to out dir. Add your own globs as needed.
new CopyWebpackPlugin(
  [
    { from: { glob: "fonts/**" } },
    { from: { glob: "**/*.+(jpg|png)" } },
    { from: { glob: "assets/**/*" } },
  ], 
  { 
     ignore: [`${relative(appPath, appResourcesFullPath)}/**`]
  }
)
eltharynd commented 4 years ago

Somebody found a fix already? I've tried the webpack thing but no success...

JKcolab commented 4 years ago

Hi @eltharynd I tried quickly @mudlabs suggestion (thank you) and I didn't get the error message :-) but the sound didn't still didn't work :-(.

I going to test a bit more thoroughly first.

mudlabs commented 4 years ago

If you don't get the "file not found" error, but you have no sound playing, maybe you are trying to play the sound before it has finished buffering. I've never had that problem on iOS, but Android seems to take a little longer to buffer.

@JKcolab and @eltharynd;

@eltharynd, After you tried the webpack fix did you keep getting the error message "file not found" when you try to initialise it, or just no sound?

JKcolab commented 4 years ago

@mudlabs Yes, allowing it buffer time works. Thanks you for reminding me.