Plugin, IOS, using fetch to open an mp3 file

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
	
}

On iOS, you may need to use the file:// URI scheme to refer to local files instead of just using the file path directly.

The file I’m loading is in a sub-directory of the plugin directory. I can’t use file://, or can I?

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.

Got it. thanks

Any particular reason you are using fetch?

It was what worked at the time. But then it didn’t on iOS. I have to confess to bimbling about in the dark a bit.

I’ve spent the morning on this, so far without getting it to work on a phone, so if anyone has any ideas I’d be eternally grateful.

What are you trying to do?
Play it?

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.

Demo vid: https://aldis.co.uk/downloads/ScreenFlow.mp4

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.

1 Like