jbristowe / nativescript-sound

MIT License
12 stars 15 forks source link

Nativescript-sound crashes on iOS 13.2 #15

Open methompson opened 4 years ago

methompson commented 4 years ago

When instantiating a new Sound object, Nativescript crashes with an error along the lines of 'null is not on object' evaluating this._player.initWithContentsOfURLError(this._url);

It turns out that new AVAudioPlayer() returns null. I updated the code to run AVAudioPlayer.alloc().initWithContentsOfURLError(this._url) and it worked.

I've made a Pull Request from a fork to fix this issue.

JKcolab commented 4 years ago

Although I made the above change I now get: "Terminating app due to uncaught exception 'NativeScript encountered a fatal error: TypeError: null is not an object (evaluating 'this._player.prepareToPlay')"

I am using a file, not a URL.

Any ideas would be appreciated.

methompson commented 4 years ago

@JKcolab

I forked the project into a new package. Give this a whirl and tell me if it works:

https://www.npmjs.com/package/nativescript-sound-kak

JKcolab commented 4 years ago

@methompson Thank you but I then ran into other problems. On Android I received loads of errors until I changed the require("nativescript-sound") to require("nativescript-sound-kak").

But then although I didn't receive error messages there was no sound.

I then tried it with iPhone and upon loading the simulator received this error in the Xcode console:

2020-03-05 11:35:24.023048+0100 Sound1[91553:926311] CONSOLE ERROR file:///app/vendor.js:143:20: Sound not initialized; file not found.

CONSOLE ERROR file:///app/vendor.js:143:20: Sound not initialized; file not found.

methompson commented 4 years ago

@JKcolab thanks for the heads up. I’ll change that oversight in the readme.

The “file not found” error is an error on your end. You aren’t initializing the object with a correct file path.

Here’s how I initialize a beep sound:

import * as fs from "tns-core-modules/file-system";
import * as Sound from 'nativescript-sound-kak';

const pathToBeep = fs.path.join(fs.knownFolders.currentApp().path, '/assets/sounds/beep.mp3');
if (fs.File.exists(pathToBeep)) {
  this.beepSound = Sound.create(pathToBeep);
}
kriefsacha commented 2 years ago

@methompson i tried with your package and iOS 15.1, and with the last method you sent. I have the error "Sound not initialized; file not found." ...

methompson commented 2 years ago

@kriefsacha That means the file you're initializing doesn't exist. That path you provided to the file is incorrect.

Note the console log is from line 12 in this file: https://github.com/methompson/nativescript-sound/blob/master/sound-common.js

You get that error, because the file doesn't exist at that path.

kriefsacha commented 2 years ago

@methompson but the file does exist and the path is the correct one ..

methompson commented 2 years ago

The constructor worked fine for iOS 12-14. If you get the "file not found" log, that means your path is invalid.

I don't maintain the project any longer, so if iOS 15 introduced a breaking change, I'm not going to fix the issue.

That said, I suggest you review the constructor in the link above and debug the issue.

kriefsacha commented 2 years ago

Okay so i found it, i had tons of sounds and there was one that actually didnt exist.. in android i didnt had any issue but in IOS yes.. sorry, thanks for your work and fast response

kriefsacha commented 2 years ago

@methompson im update the new version of nativescript and i have this:

ERROR in ./node_modules/nativescript-sound-kak/sound-common.js 1:0-51
Module not found: Error: Can't resolve 'tns-core-modules/file-system' in 'C:\Users\krief\OneDrive\Documents\Projets\GitHub\visualy\VisualyScan\node_modules\nativescript-sound-kak'
 @ ./node_modules/nativescript-sound-kak/sound.android.js 1:0-41 3:20-31
 @ ./src/app/scan/scan.component.ts 210:12-45
 @ ./src/app/app-routing.module.ts 5:0-58 18:31-44
 @ ./src/app/app.module.ts 2:0-56 38:12-28
 @ ./src/main.ts 6:0-45 8:69-78

Would you be able to fix that ? Opened a new issue about it

methompson commented 2 years ago

It means that either your version of tns-core-modules is incomplete or the Nativescript team removed file-system from the-core-modules.

if it’s the latter, I’m not fixing it. I’m done developing within NativeScript.

kriefsacha commented 2 years ago

Yeah i just found that they puted knownFolders and path into @nativescript/core.

Thats a shame i have to fix it myself .. :(

methompson commented 2 years ago

That’s why I stopped developing in the NativeScript platform. They just broke things all the time.