Place the audio in the assets and write a custom typing file called audio.d.ts with the following code :-
declare module '*.mp3';
and place it in the root of your project under any name, ex: ./custom_typings/audio.d.ts.
Here, I have just done it for an mp3 file.
After this go to your tsconfig.json and under "typeRoots" add the custom_typings folder.
"typeRoots": [
"node_modules/@types",
"custom_typings/"
]
Once this is done you can just import the audio file from anywhere and use it normally as you would.
import {audioFile} from '../../../../assets/audio/audioFile.mp3';
TrackPlayer.add({
id: '1',
url: audioFile,
title: 'Example title',
artist: 'Example Artist',
artwork: 'https://picsum.photos/100',
});
declare module '*.m4a';
in/typings/audio.d.ts
, then had changed my"include"
to"include": ["src", "typings"]
. ChangingtypeRoots
did nothing for me for some reason. – Assiduity