我正在尝试使用expo-av从aws s3存储桶中播放音频,但它无法工作。这是我第一次使用expo-av,但我认为问题出在将源URL指向我的aws API。下面是我的代码。我敢肯定,我在这里搞砸了,所以非常感谢您对答案的解释。
Audio.setIsEnabledAsync(true)
Audio.setAudioModeAsync(
{playsInSilentModeIOS : true,
allowsRecordingIOS : true,
staysActiveInBackground : true,
interruptionModeIOS : {
interruptionModeIOS : true,
INTERRUPTION_MODE_IOS_DO_NOT_MIX: true,
INTERRUPTION_MODE_IOS_DUCK_OTHERS: true,
},
interruptionModeAndroid : {
INTERRUPTION_MODE_ANDROID_DO_NOT_MIX: true,
INTERRUPTION_MODE_ANDROID_DUCK_OTHERS: true,
},
playThroughEarpieceAndroid: true,
}
)
export default class Audiol extends Component {
state = {
...
};
componentDidMount() {
Storage.get(this.props.a)
.then(result =>{ console.log("Storageb");
const Me = result;
this.setState({Audio: Me})
console.warn("geb")
})
.catch(err => console.log("S.ERROR",err))
}
async handleaudio() {
const soundObject = new Audio.Sound;
try {
soundObject.setOnPlaybackStatusUpdate(onPlaybackStatusUpdate);
await soundObject.loadAsync({uri: this.state.Audio}, {}, true);
console.warn("success")
} catch (error) {
console.warn("error", error, this.state.Audio)
// An error occurred!
}
}
更新:
只是注意到,如果我以下列方式使用this.state.Audio
给出的确切链接,则只有当我使用state.Audio
时,才会发生此错误。
await soundObject.loadAsync({uri: 'https://...amazonaws.com/...'});
但是我需要它与国家合作。
希望有人能帮助我。 谢谢!
答案 0 :(得分:0)
您能否在您的this.state.audio
期间向我们提供try
的结果?
您还可以在handleaudio
函数中尝试以下代码:
const myAudio = Audio.Sound.createAsync({uri: this.state.Audio}, {}, true);
myAudio.playbackInstance.playAsync()