Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cordova-plugin-nativeaudio with ionic Capacitor #159

Open
raphrmx opened this issue Jun 26, 2019 · 7 comments
Open

Use cordova-plugin-nativeaudio with ionic Capacitor #159

raphrmx opened this issue Jun 26, 2019 · 7 comments

Comments

@raphrmx
Copy link

raphrmx commented Jun 26, 2019

Is it to possible to update plugin for remove hardcoded www in NativeAudio.java

...
int voices;
if (data.length() <= 3) {
  voices = 1;
} else {
  voices = data.getInt(3);
}

String fullPath = "www/".concat(assetPath);

Context ctx = cordova.getActivity().getApplicationContext();
AssetManager am = ctx.getResources().getAssets();
AssetFileDescriptor afd = am.openFd(fullPath);
...

thanks in advance,
Raph.

@sta55en
Copy link

sta55en commented Oct 23, 2019

@raphrmx If you replace www with public it'll all work. I'll submit a pull request to add Capacitor support when I have time. It won't be soon.

@wzr1337
Copy link

wzr1337 commented Apr 5, 2020

It is the same for iOS

to avoid

[log] - (NATIVE AUDIO) Asset not found.

you need to change
ios/capacitor-cordova-ios-plugins/sources/CordovaPluginNativeaudio/NativeAudio.m
from:
line 87: NSString* basePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"www"];
to:
line 87: NSString* basePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"public"];

Reason: capacitor does not place the js files and assets folder under www but public.

@nicobytes
Copy link

Any update about this issue?

@danielehrhardt
Copy link

@jorgemedhaku
Copy link

jorgemedhaku commented Oct 27, 2020

In Ionic Capacitor if you are using preloadComplex:
await this.nativeAudio.preloadComplex(unique_id, url, volume, 1, 0);
then change NativeAudio.m line 172 to:

NSString*` basePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"public"];
NSString* path = [NSString stringWithFormat:@"%@/%@", basePath, assetPath];
NSString* simplePath = [NSString stringWithFormat:@"%@", assetPath];
            if ([[NSFileManager defaultManager] fileExistsAtPath : simplePath]) {
                NativeAudioAsset* asset = [[NativeAudioAsset alloc] initWithPath:simplePath
                                                                      withVoices:voices
                                                                      withVolume:volume
                                                                   withFadeDelay:delay];

                audioMapping[audioID] = asset;

                NSString *RESULT = [NSString stringWithFormat:@"%@ (%@)", INFO_ASSET_LOADED, audioID];
                [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: RESULT] callbackId:callbackId];

            } else if ([[NSFileManager defaultManager] fileExistsAtPath : path]) {
                NativeAudioAsset* asset = [[NativeAudioAsset alloc] initWithPath:path
                                                                      withVoices:voices
                                                                      withVolume:volume
                                                                   withFadeDelay:delay];

                audioMapping[audioID] = asset;

                NSString *RESULT = [NSString stringWithFormat:@"%@ (%@)", INFO_ASSET_LOADED, audioID];
                [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: RESULT] callbackId:callbackId];

            } else {
                NSString *RESULT = [NSString stringWithFormat:@"%@ (%@)", ERROR_ASSETPATH_INCORRECT, assetPath];
                [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: RESULT] callbackId:callbackId];
            }

@mikelhamer
Copy link

Still waiting on a fix. Having to modify the plugin seems really janky, since wouldn't it be overriden on every npm install + ionic cap sync?

@bchehraz
Copy link

bchehraz commented Oct 28, 2021

@mikelhamer Yep I'm having to do the change pretty much every iOS production build and it's easy to forget... And it's a necessary feature on my project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants