You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo-AV 9.2.3与Expo 42.0.3中Sound.playAsync()无法播放音频

问题描述

概述

  • 背景:正在使用React Native、Expo和Expo-AV开发计时器应用,基于托管工作流初始化标准应用,使用expo-av (9.2.3)播放MP3文件。
  • 问题:Moto G6(Android 9)、iPhone SE(iOS 14.6)及网页端均无法播放音频(此前有报告提及Moto G5(Android 8)存在类似音频播放问题)。
  • 已附上App.json和package.json文件:
    app json
    package json

工作流类型

托管

问题涉及平台

Android、网页端

SDK版本(托管工作流)

42.0.3

环境信息

Expo CLI 4.9.0,环境详情:

  • 系统:Windows 10 10.0.19042
  • 二进制文件:Node: 14.17.4,npm: 6.14.14
  • 集成开发环境:Android Studio 2020.3.0.0
  • npm包版本:
    • expo: ~42.0.1 → 42.0.3
    • react: 16.13.1
    • react-dom: 16.13.1
    • react-native: 0.63.2
    • react-native-web: ~0.13.12 → 0.13.18
  • Expo工作流:托管

复现步骤

  1. 运行expo init my-app
  2. 运行expo install expo-av
  3. 将任意MP3文件添加到项目根目录
  4. 替换App.js内容为以下代码:
import { StatusBar } from 'expo-status-bar';
import React, { useEffect } from 'react';
import { Audio } from 'expo-av';
import { StyleSheet, Text, View } from 'react-native';

export default function App() {
  useEffect(() => {
    playSound()
  }, []);

  async function playSound() {
    const sound = new Audio.Sound();
    try {
      await sound.loadAsync(require('./sound.mp3'));
      await sound.playAsync();
      await sound.unloadAsync();
    } catch (error) {
      console.error(error)
    }
  }

  return (
    <View style={styles.container}>
      <Text>Open up App.js to start working on your app!</Text>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});
  1. 运行expo start
  2. 在Moto G6(Android 9.0)、iPhone SE(iOS 14.6)的Expo Go应用中预览,或在终端输入w打开网页端预览。

内容的提问来源于stack exchange,提问作者Madhav Malhotra

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 10:39:16