簡體   English   中英

有沒有辦法在反應原生的新資產系統中要求非圖像資產?

[英]Is there a way to require a non-image asset in react-native new asset system?

在反應天然0.14,我們可以require使用圖像const fireImage = require('./images/demo.jpg') require適用於圖像(png,jpeg,gif),'js'和'json'文件。

我的問題是:是否可以“要求”'.mp3'或'.mp4'文件?

我試過'mp3'文件,Xcode報告了這樣的構建錯誤

uncaught error Error: UnableToResolveError: Unable to resolve module ./music/some from /Users/rongshen/tmp/react-native-test/imageTest/index.ios.js: Invalid directory /Users/rongshen/tmp/react-native-test/imageTest/music/some.mp3

對於正在嘗試解決此問題的任何其他人,您可以利用rn-cli.config.js文件為require()方法添加其他文件類型。

例如,將名為rn-cli.config.js的文件添加到項目根目錄,其中包含以下內容:

module.exports = {
    getAssetExts() {
        return ['mp3', 'mp4']
    }
}

如果您正在嘗試播放mp3文件,我建議使用React Native Sound

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM