代码之家  ›  专栏  ›  技术社区  ›  Jordan

“乌里。“匹配”未定义,试图将音频文件输入视频源

  •  2
  • Jordan  · 技术社区  · 8 年前

    这是我的代码 <Video /> 要素

    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"}  
    />
    

    我得到的具体错误是。。。

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

    以下是版本

    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

    我正在尝试从本地软件包加载音频资源,但我似乎无法让它工作,如果我从该文件夹中删除音频文件,它会抛出一个错误,它无法找到它,因此它肯定找到了该文件。

    我很乐意帮忙

    0 回复  |  直到 8 年前
        1
  •  0
  •   Kishan Bharda    7 年前

    我找到了解决办法。变量 audioFile 它本身包含 uri 钥匙

    所以

    <Video source={{uri: this.audioFile}}   // Can be a URL or a local file.
      ...
      ...
    />
    

    试试这个:

    <Video source={this.audioFile}   // Can be a URL or a local file.
      ...
      ...
    />
    

    请注意,我已经直接通过了考试 this.audioFile 致消息来源。

    更重要的是,要显示视频,必须通过高度和宽度。

        2
  •  0
  •   Jordan    7 年前

    这就是在我的用例中工作的原因

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

    推荐文章