Is there a way to set the http headers for url playback?
@DanielWare I use RNFetchBlob to download audio file with headers to local cache directory, then play it. It looks like this:
RNFetchBlob
.config({
path: RNFetchBlob.fs.dirs.CacheDir + '/voiceMsgReceived.aac',
fileCache: true,
appendExt: 'aac',
})
.fetch('GET', `https://example.com/file/${uri}`, {
// your custom headers here
'x-access-token': this.state.token
})
.then((res) => {
console.log('The file saved to ', res.path())
// Beware that when using a file path as Image source on Android,
// you must prepend "file://"" before the file path
return (Platform.OS === 'android' ? 'file://' : '') + res.path()
})
.then((path) => {
// These timeouts are a hacky workaround for some issues with react-native-sound.
// See https://github.com/zmxv/react-native-sound/issues/89.
setTimeout(() => {
const sound = new Sound(path, '', (error) => {
if (error) {
console.log('failed to load the sound', error)
}
})
chatStore.setPlayingStatus(true)
setTimeout(() => {
sound.play((success) => {
chatStore.setPlayingStatus(false)
if (success) {
console.log('successfully finished playing')
} else {
console.log('playback failed due to audio decoding errors')
}
})
}, 100)
}, 100)
})