问题
I'm making a simple app that uses nativescript-audio and I want to play some mp3 samples in the app. The problem is, when I click "Run on Device" in Sidekick, it doesn't transfer any mp3 files I included in the app folder (and therefore I can't play it). What is weird is that if I just change the extension of the file (for example to .jpg), the transfer works fine (and I can even play that file as if it was mp3).
So, just to exemplify the problem, if I use this code, it doesn't work:
const audio = require('nativescript-audio');
const player = new audio.TNSPlayer();
const playerOptions = {
audioFile: '~/audio/myfile.mp3',
loop: false
};
But if I just rename "myfile.mp3" to "myfile.jpg", change the code like this:
...
audioFile: '~/audio/myfile.jpg',
...
and then rebuild the app, it works just fine and plays the sample that was originally stored in myfile.mp3 and is now stored in myfile.jpg.
Using file-system I can also detect the .jpg file is present but .mp3 is not.
What I want to ask is whether Sidekick looks only for certain file extensions and ignores the others during build, and whether I can change the "watched file extensions" setting.
回答1:
I guess you are running with webpack, the default webpack configuration will copy only fonts and images (JPEG / PNG etc.,) along with your source code. If you have any other files to be copied modify the copy plugin configurations inside webpack.config.js
something like,
new CopyWebpackPlugin([
{ from: "fonts/**" },
{ from: "songs/**" },
{ from: "**/*.jpg" },
{ from: "**/*.png" },
{ from: "**/*.png" },
], { ignore: [`${relative(appPath, appResourcesFullPath)}/**`] }),
来源:https://stackoverflow.com/questions/52591357/nativescript-transferring-mp3-files-with-sidekick