So I have a plugin that loads an mp3 file from the attachments folder using fetch() as below. Works fine on MacOS but fetch() fails in iOS and iPadOS with a Load failed error. Any thoughts one what may be going wrong here?
export default class DrumTabPlayer extends Plugin {
const filePath = this.app.vault.adapter.getResourcePath(`${this.Plugin.manifest.dir}/assets/samples/acoustic-kit/${fileName}.mp3`);
const response = await fetch(filePath); // fails here
}
You need to have vault on iCloud and use the file:// URI scheme. I had same problem cannot access the file system on iOS and iPAD OS. But this is the limitation of those system not Obsidian.
It’s a custom code block that plays text drum notation. So the plugin loads a bunch of drum samples - bass, snare, cymbals, whatever, which are played according to the text in the code block. Web Audio is used to play.
It looks like it’s not possible to do this in any cross-platform way so I’m going to, reluctantly, wrap this up and look for a different solution. It’s a shame, Obsidian was looking so good.
FWIW, I figured a workaround; base64 encoding the audio and using import in the plugin. Although not ideal it works well enough. I’m surprised, though, that there isn’t a way to load asset data at run time.