Cap-go / native-audio

Capacitor plugin for native audio engine.
https://capgo.app
MIT License
38 stars 16 forks source link

Asset is not loaded #46

Closed danielgoodwin97 closed 10 months ago

danielgoodwin97 commented 1 year ago

Describe the bug When running the application on iOS my application loads, shows the main menu screen and then freezes due to an error being thrown. When removing all calls to this package the application works as expected (albeit no sound, obviously).

The asset path seems to be set up correctly and the files exist there. I'm not attempting to play them directly after load either so I'm not sure as to why this error is being thrown.

All of this works on Android for the record.

2023-07-30 03:46:09.402014+0100 App[30814:297264] KeyboardPlugin: resize mode - native
2023-07-30 03:46:09.456596+0100 App[30814:297264] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x6000004e8fe0> F8BB1C28-BAE8-11D6-9C31-00039315CD46
⚡️  Loading app at capacitor://localhost...
⚡️  WebView loaded
⚡️  To Native ->  NativeAudio preload 12064351
⚡️  To Native ->  NativeAudio preload 12064352
⚡️  To Native ->  NativeAudio preload 12064353
⚡️  To Native ->  NativeAudio preload 12064354
⚡️  To Native ->  NativeAudio preload 12064355
⚡️  To Native ->  NativeAudio preload 12064356
⚡️  To Native ->  NativeAudio preload 12064357
⚡️  To Native ->  NativeAudio loop 12064358
⚡️  To Native ->  NativeAudio stop 12064359
⚡️  To Native ->  NativeAudio loop 12064360
⚡️  To Native ->  NativeAudio preload 12064361
⚡️  To Native ->  NativeAudio preload 12064362
ERROR MESSAGE:  {"message":"Asset is not loaded - public\/sounds\/music\/in-menu-loop.wav","errorMessage":"Asset is not loaded - public\/sounds\/music\/in-menu-loop.wav"}
ERROR MESSAGE:  {"errorMessage":"Asset is not loaded - public\/sounds\/music\/in-menu-loop.wav","message":"Asset is not loaded - public\/sounds\/music\/in-menu-loop.wav"}
⚡️  [error] - {"message":"Asset is not loaded - public/sounds/music/in-menu-loop.wav","errorMessage":"Asset is not loaded - public/sounds/music/in-menu-loop.wav"}
⚡️  [error] - {"errorMessage":"Asset is not loaded - public/sounds/music/in-menu-loop.wav","message":"Asset is not loaded - public/sounds/music/in-menu-loop.wav"}
⚡️  To Native ->  App addListener 12064363
⚡️  To Native ->  Keyboard getResizeMode 12064364
⚡️  TO JS {"mode":"native"}
⚡️  TO JS undefined
⚡️  TO JS undefined
⚡️  TO JS undefined
⚡️  TO JS undefined
⚡️  TO JS undefined
⚡️  TO JS undefined
⚡️  TO JS undefined
⚡️  TO JS undefined
(lldb) 

The debugger lands here and shows this error:

image

To Reproduce Steps to reproduce the behavior:

  1. Load an asset using the preload method.
  2. I'm seeing the error here despite not playing it.

Expected behavior The sound plays and the app loads as normal.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Here's the source code that actually loads/interacts with the assets.

class Sound {
    asset: Sounds;

    /**
     * Create a new sound.
     * @param asset Path to the sound file
     * @returns
     */
    constructor(asset: Sounds, config: SoundConfig = defaultConfig) {
        const { volume, voices, delay, autoplay } = _.defaults(config, defaultConfig);

        this.asset = asset;

        NativeAudio.preload({
            assetId: this.asset,
            assetPath: this.asset
        });

        return this;
    }

    /**
     * Play sound.
     */
    play() {
        NativeAudio.play({ assetId: this.asset });
    }

    /**
     * Loop sound.
     */
    loop() {
        NativeAudio.loop({ assetId: this.asset });
    }

    /**
     * Stop sound.
     * This will also restart the sound next time it is played.
     */
    stop() {
        NativeAudio.stop({ assetId: this.asset });
    }

    /**
     * Destroy the sound instance.
     */
    destroy() {
        NativeAudio.unload({ assetId: this.asset });
    }
}
riderx commented 1 year ago

Do you confirm you can find the file in public/sounds/music/in-menu-loop.wav in Xcode ?

danielgoodwin97 commented 1 year ago

Yes - it was present.

I'm no longer using the library due to this issue - I ended up finding another which worked instead but I thought I'd put a report in.

riderx commented 1 year ago

@danielgoodwin97 thanks, i think you put in your path you give to the lib "public/" where you shouldn't. You should preload like this: sounds/music/in-menu-loop.wav