简体   繁体   中英

React Native fetching audio from a CDN

I'm currently working on an app and need to fetch a lot of audio from external websites.

This would be an example for one:

"https://cdn.islamic.network/quran/audio/128/ar.alafasy/1.mp3"

I've been looking all over but couldn't really find the best way of going about this, would love if someone more experience could shed some light on this.

Much appreciated

Hi can you please explain what exactly you need to do with the audio?

In HTML you could do this :

 <audio controls> <source src="https://cdn.islamic.network/quran/audio/128/ar.alafasy/1.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio>

to let the user use the audio.

If it has to do with React.js (as you tagged), this post should help you out.

To play an Audio File onClick, just take a look at the following example:

import React from 'react';

function App() {
  let audio = new Audio("/christmas.mp3")

  const start = () => {
    audio.play()
  }

  return (
    < div >
      <button onClick={start}>Play</button>
    </div >
  );
}

export default App;

This example was provided in a duplicate found here by a user named hunter .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM