Does anyone have a working example of loading an audio file from a network url?

#1

The Expo documentation is quite sparse on loading audio from a network URL. The below is from the documentation at https://docs.expo.io/versions/latest/sdk/audio:

Expo.Audio.Sound.create(source, initialStatus = {}, onPlaybackStatusUpdate = null, downloadFirst = true)

Parameters

  • source ( object / number / Asset ) – The source of the sound. The following forms are supported:

    • A dictionary of the form { uri: 'http://path/to/file' } with a network URL pointing to an audio file on the web.

    • require('path/to/file') for an audio file asset in the source code directory.

    • An Expo.Asset object for an audio file asset.

I have tried to load audio from a number of different sources (my own API, dropbox, etc.). All download links work perfectly when using a web browser, but the Expo Audio API throws cryptic errors.

I would greatly appreciate a working example of using a remote URL or any troubleshooting tips. See relevant code below:

Relevant native code below:

const playbackObject = await Audio.Sound.create(
      // require('../assets/audio/recording-1234.caf'),
      { uri: 'http://xx.x.x.xxx:5000/api/file/recording-1234.caf'},
      { shouldPlay: true }
    );

My server is a nodeJS / Express API. The endpoint just finds the correct file in the local server file system, and streams back the response:

app.get('/api/file/:filename', function (req, res) {
    const fileName = req.params.filename
    const src = fs.createReadStream('./files/audio/' + fileName);
    res.setHeader( 'content-type', 'audio/x-caf')
    src.pipe(res);
    //'audio/x-caf'

})

The error I receive is (same error received with dropbox link):

YellowBox.js:80 Possible Unhandled Promise Rejection (id: 0):
Error: The server is not correctly configured. - The AVPlayerItem instance has failed with the error code -11850 and domain "AVFoundationErrorDomain".
Error: The server is not correctly configured. - The AVPlayerItem instance has failed with the error code -11850 and domain "AVFoundationErrorDomain".
    at loadError (blob:http://localhost:19001/d3b3b86a-aac6-4b17-9f10-57945e3b1958:104934:28)
    at MessageQueue.__invokeCallback (blob:http://localhost:19001/d3b3b86a-aac6-4b17-9f10-57945e3b1958:2800:18)
    at blob:http://localhost:19001/d3b3b86a-aac6-4b17-9f10-57945e3b1958:2545:18
    at MessageQueue.__guardSafe (blob:http://localhost:19001/d3b3b86a-aac6-4b17-9f10-57945e3b1958:2713:11)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (blob:http://localhost:19001/d3b3b86a-aac6-4b17-9f10-57945e3b1958:2544:14)
    at http://localhost:19001/debugger-ui/debuggerWorker.js:70:58

Any help is greatly appreciated!

1 Like

closed #2

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.

0 Likes