Search code examples
react-nativeexporeact-native-video

'uri.match' is undefined trying to require audio file into video source


Here is my code around this <Video /> element

class Menu extends Component {
    ...
    audioFile = null
    componentWillMount(){
        this.audioFile = require('../../assets/audio/subtle.mp3');
    }
}

<Video source={{uri: this.audioFile}}   // Can be a URL or a local file.
  ref={(ref) => {
    this.player = ref
  }}
  onError={this.audioError} 
  audioOnly
  style={styles.backgroundVideo}
  playInBackground
  playWhenInactive
  ignoreSilentSwitch={"ignore"}  
/>

The specific error I get is...

TypeError: uri.match is not a function. (In 'uri.match(/^\//)', 'uri.match' is undefined)

Here are the versions

expo: 30.0.0

expokit: 1.7.1

react: 16.3.1

react-native: https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz

react-native-video: 3.2.1

I'm trying to load an audio asset from the local package here, but I can't seem to get it to work, if I remove the audio file from that folder it throws an error that it can't find it so it's definitely finding the file.

Would love some help with this


Solution

  • This is what made it work in my use case

    <Video source={require('../../assets/audio/file.mp3')} ... />