Nativescript:使用Sidekick传输mp3文件 [英] Nativescript: Transferring mp3 files with Sidekick
问题描述
我正在制作一个使用nativescript-audio的简单应用,我想在该应用中播放一些mp3样本.问题是,当我单击Sidekick中的在设备上运行"时,它不会传输我包含在app文件夹中的任何mp3文件(因此无法播放).奇怪的是,如果我只是更改文件的扩展名(例如,更改为.jpg),则传输工作正常(而且我什至可以像播放mp3一样播放该文件).
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
};
但是,如果我只是将"myfile.mp3"重命名为"myfile.jpg",请更改如下代码:
But if I just rename "myfile.mp3" to "myfile.jpg", change the code like this:
...
audioFile: '~/audio/myfile.jpg',
...
然后重建应用程序,它可以正常工作并播放最初存储在myfile.mp3中的示例,现在又存储在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.
使用文件系统,我还可以检测到存在.jpg文件,但没有.mp3.
Using file-system I can also detect the .jpg file is present but .mp3 is not.
我想问的是Sidekick是否仅查找某些文件扩展名,而在构建过程中忽略其他扩展名,以及我是否可以更改监视的文件扩展名"设置.
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.
推荐答案
我猜您正在使用webpack运行,默认的webpack配置将仅复制字体和图像以及源代码(JPEG/PNG等).如果您还有其他文件要复制,请在webpack.config.js
之内修改复制插件配置,
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)}/**`] }),
这篇关于Nativescript:使用Sidekick传输mp3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!