2016-10-24 37 views
2

我正在使用原生反應來開發音樂應用程序,並且我試圖找出搜索和播放已保存在客戶端手機上的音頻文件的最佳方法。我只是不確定什麼是最好的模塊/庫來解決這個問題,或者iOS/Android OS是否允許這種類型的用戶文件訪問。使用React Native搜索手機上的音頻文件

我使用react-native-sound來播放音頻文件,我發現react-native-fs模塊,這看起來接近我覺得我需要搜索音頻文件。有一個READDIR功能,但你通過它的目錄路徑常量像MainBundlePath,CachesDirectoryPath,DocumentDirectoryPath等:

// require the module 
var RNFS = require('react-native-fs'); 

// get a list of files and directories in the main bundle 
RNFS.readDir(RNFS.MainBundlePath) 

有了: 1 MainBundlePath - 的絕對路徑主束目錄 2. CachesDirectoryPath - 絕對路徑到高速緩存目錄 3. DocumentDirectoryPath - 文檔目錄的絕對路徑

這些目錄中的任何一個都是我尋找已存儲在客戶端電話上的音頻文件的位置嗎?

+0

有關[如何搜索iPhone文件系統下載文件夾中的MP3文件在本機](http://stackoverflow.com/questions/40259710/how-to-search-through-iphone-filesystem-downloads-folder-換的MP3文件,在反應的)。 – NiFi

回答

-1

react-native-get-music-files是一個npm包,用於搜索本地存儲卡和SD卡上的所有音樂文件。

import MusicFiles from 'react-native-get-music-files'; 

MusicFiles.get(
    (success) => { 
    //this.saveSongData(success) 
    }, 
    (error) => { 
     console.log(error) 
    } 
); 

該函數返回對象的數組,你可以遍歷像這樣:

[ 
    { 
    id : 1, 
    title : "La danza del fuego", 
    author : "Mago de Oz", 
    album : "Finisterra", 
    genre : "Folk", 
    duration : 132132312321, // miliseconds 
    cover : "file:///sdcard/0/123.png", 
    blur : "file:///sdcard/0/123.png", 
    path : "/sdcard/0/la-danza-del-fuego.mp3" 
    } 
] 

不幸的是,它目前只支持Android。

相關問題