簡體   English   中英

React Native Audio 播放名稱中帶有空格的 mp3 文件

[英]React Native Audio Playing mp3 files with spaces in their names

我一直在嘗試使用 Expo 在 React Native 中構建一個媒體播放器,以便能夠在我的音樂項目中播放音頻。

我已經成功地與首選設計等一起破解了一個,但我仍然有一個小錯誤。 在這里,我從帶有指向存儲在服務器中的文件的鏈接的 API 端點接收信息。 當文件名只有一個詞時,此音頻會播放。 當文件名中有空格時,它不會播放。 例如 .../musics/test.mp3 播放而 .../musics/test 32.mp3 不播放。 任何關於如何在 React Native 中處理這個問題的想法都將受到高度贊賞。 我的播放功能

 startPlay = async (index = this.index, playing = false) => {
        const url = this.list[index].url;
        this.index = index;
        console.log(url);
        // Checking if now playing music, if yes stop that
        if(playing) {
            await this.soundObject.stopAsync();
        } else {
            // Checking if item already loaded, if yes just play, else load music before play
            if(this.soundObject._loaded) {
                await this.soundObject.playAsync();
            } else {
                await this.soundObject.loadAsync(url);
                await this.soundObject.playAsync();
            }
        }
    };

url 是文件的鏈接。

我正在一個流媒體平台上工作,我很想得到一個類似這樣的播放器:

在此處輸入圖片說明

像這樣的東西https://hackernoon.com/building-a-music-streaming-app-using-react-native-6d0878a13ba4

但我正在使用 React Native 博覽會。 我在網上遇到的所有實現都是使用原生的,沒有博覽會。 使用 expo 指向任何已經完成的工作的任何指針都會有很大幫助,例如包。

謝謝

應該對網址進行編碼:

const uri = this.list[index].url;
this.index = index;
const url = encodeURI(uri);
console.log(url);

uri = "../musics/test 32.mp3"將被編碼為url = "../musics/test%2032.mp3"

暫無
暫無

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

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