gpt4 book ai didi

animation - react 原生音频动画

转载 作者:行者123 更新时间:2023-12-02 22:13:18 24 4
gpt4 key购买 nike

我目前正在使用 React Native Audio 来录制音频并存储声音。我想知道是否有办法实时获取此录音的进度以将麦克风输入映射到动画,以提供麦克风正在工作的视觉反馈。

目前,包的 onProgress() 函数仅根据我的发现仅发送当前时间码。

谢谢你的帮助!

最佳答案

我目前正在做类似的事情。
我就是这样做的。

import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View,
TouchableOpacity,
Button,
LayoutAnimation,
Image,
ScrollView,
Animated
} from 'react-native';
export default class App extends Component {
state = {
isPressed: false,
animated: new Animated.Value(0),
opacityA: new Animated.Value(1),
}
constructor(props) {
super(props);
this._onPress = this._onPress.bind(this);
}
_runAnimation() {
const { animated, opacityA } = this.state;

Animated.loop(
Animated.parallel([
Animated.timing(animated, {
toValue: 1,
duration: 1000,

}),
Animated.timing(opacityA, {
toValue: 0,
duration: 1000,

})
])
).start();
}
_stopAnimation() {
Animated.loop(
Animated.parallel([
Animated.timing(animated),
Animated.timing(opacityA)
])
).stop();
}
_onPress() {
this.setState(
state => ({ isPressed: !state.isPressed }),
)
}
_micButton() {
const { isPressed, animated, opacityA, } = this.state;
if (isPressed) {
//some function
this._runAnimation();
return (
<Animated.View style={{
width: 100,
height: 100,
borderRadius: 50,
backgroundColor: 'rgba(153,0,0,0.4)',
opacity: opacityA,
transform: [
{
scale: animated
}
]
}}>
{/* icon or image */}
</Animated.View>
);
} else {
//some function
return (
<View style={{
width: 100,
height: 100,
borderRadius: 50,
backgroundColor: 'rgba(153,0,0,0.4)',
}}>
{/* icon or image */}
</View>
);
}
}






render() {
return (
<View style={styles.container}>
<TouchableOpacity onPress={this._onPress}>
{this._micButton()}
</TouchableOpacity>
</View>
);
}
}


const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},

});
我希望能解决你的问题。

关于animation - react 原生音频动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45517840/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com