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文件:

工作流类型
托管
问题涉及平台
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工作流:托管
复现步骤
- 运行
expo init my-app - 运行
expo install expo-av - 将任意MP3文件添加到项目根目录
- 替换
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', }, });
- 运行
expo start - 在Moto G6(Android 9.0)、iPhone SE(iOS 14.6)的Expo Go应用中预览,或在终端输入
w打开网页端预览。
内容的提问来源于stack exchange,提问作者Madhav Malhotra
相关产品推荐
相关产品推荐

