Animation 反应本地音频动画

Animation 反应本地音频动画,animation,audio,react-native,waveform,Animation,Audio,React Native,Waveform,我目前正在使用录制音频和存储声音。我想知道是否有任何方法可以实时获取此录制的进度,以将麦克风输入映射到动画,提供麦克风工作的视觉反馈 目前,包的onProgress()函数只发送当前的时间码,根据我的发现 谢谢你的帮助 我目前正在研究somthing similer 我就是这样做的 import React, { Component } from 'react'; import { Platform, StyleSheet, Text, View, Tou

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

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


谢谢你的帮助

我目前正在研究somthing similer

我就是这样做的

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',
    },

});
import React,{Component}来自'React';
进口{
平台,
样式表,
文本,
看法
可触摸不透明度,
按钮
布局动画,
形象,,
滚动视图,
有生气的
}从“反应本机”;
导出默认类应用程序扩展组件{
状态={
我说:错,
已设置动画:新的已设置动画。值(0),
opacityA:新的动画值(1),
}
建造师(道具){
超级(道具);
this.\u onPress=this.\u onPress.bind(this);
}
_runAnimation(){
const{animated,opacityA}=this.state;
动画循环(
平行动画([
动画。计时(动画{
toValue:1,
持续时间:1000,
}),
动画。计时(不透明{
toValue:0,
持续时间:1000,
})
])
).start();
}
_停止动画(){
动画循环(
平行动画([
动画。计时(动画),
动画。计时(不透明)
])
).停止();
}
_onPress(){
这是我的国家(
state=>({isPressed:!state.isPressed}),
)
}
_micButton(){
const{isPressed,animated,opacityA,}=this.state;
如果(显示){
//某些功能
这个;
返回(
{/*图标或图像*/}
);
}否则{
//某些功能
返回(
{/*图标或图像*/}
);
}
}
render(){
返回(
{this.\u micButton()}
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
为内容辩护:“中心”,
对齐项目:“居中”,
背景颜色:“#F5FCFF”,
},
});
我希望这能解决你的问题。

我用。有一个API,您可以设置一个函数,该函数根据录制状态定期调用。比如说,

异步startRecording(回调:onRecordingStatusUpdated){ this.isLoading=true wait Audio.setAudioModeAsync({ allowsRecordingIOS:正确, 中断模式:Audio.INTERRUPTION\u MODE\u IOS\u DO\u NOT\u MIX, playsInSilentModeIOS:没错, 真的, 中断模式ANDROID:Audio.INTERRUPTION\u MODE\u ANDROID\u DO\u NOT\u MIX, playthroughandroid:真的 }); if(this.recording!==null){ //只允许存在一个记录器 this.recording.setOnRecordingStatusUpdate(null); this.recording=null; } const recording=新建音频.recording(); 等待录制.prepareToRecordAsync(this.recordingSettings); // ✨✨✨设置回调 recording.setOnRecordingStatusUpdate(回调); 这个。记录=记录; 等待此消息。recording.startAsync();//将调用此函数。_updateScreenForRecordingStatus以更新屏幕。 this.isLoading=false }
//我发现了一个类似的库,它不再维护了,但它仍然可以正常工作。