You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
After integrating react-native-audio-recorder-player, I'm encountering the following error: ERROR TypeError: Cannot read property 'prototype' of undefined. I'm not sure what's causing it; please assist. Here's the code: import React, { useState, useRef } from 'react';
import { View, Text, StyleSheet, ScrollView, TouchableOpacity } from 'react-native';
import DocumentPicker from 'react-native-document-picker';
import { AudioRecorderPlayer } from 'react-native-audio-recorder-player';
import IconComponent from './IconComponent';
import Spacer from './Spacer';
const LunchAudioPlayerRecorderComponent = ({ onAudioSelect, onCancel, selectedAudio, setSelectedAudio }) => {
const [isPlaying, setIsPlaying] = useState(false);
const audioRecorderPlayer = useRef(new AudioRecorderPlayer());
const handleLaunchAudioPicker = async () => {
try {
const res = await DocumentPicker.pick({
type: [DocumentPicker.types.audio],
});
handleResponse(res, onAudioSelect);
} catch (err) {
if (DocumentPicker.isCancel(err)) {
console.log('User cancelled audio picker');
} else {
console.log('DocumentPicker Error: ', err);
}
}
};
const handleResponse = async (response, callback) => {
setSelectedAudio(response);
const uri = response.uri;
await audioRecorderPlayer.current.startPlayer(uri);
audioRecorderPlayer.current.addPlayBackListener((e) => {
if (e.current_position === e.duration) {
audioRecorderPlayer.current.stopPlayer();
setIsPlaying(false);
}
});
setIsPlaying(true);
callback(response);
};
const handlePlayPauseAudio = async () => {
if (isPlaying) {
await audioRecorderPlayer.current.pausePlayer();
} else {
await audioRecorderPlayer.current.startPlayer();
}
setIsPlaying(!isPlaying);
};
const handleStopAudio = async () => {
await audioRecorderPlayer.current.stopPlayer();
setIsPlaying(false);
};
const handleCancel = () => {
setSelectedAudio(null);
onCancel();
};
return (
{selectedAudio && (
<IconComponent onPress={handlePlayPauseAudio} name={isPlaying ? 'pause' : 'play'} size={25} color="white" />
)}
{selectedAudio && (
Cancel
)}
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
launchStyle: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
audioContainer: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
controls: {
flexDirection: 'row',
justifyContent: 'space-around',
alignItems: 'center',
marginTop: 20,
},
cancelSelectionButton: {
fontSize: 16,
color: 'red',
textDecorationLine: 'underline',
},
});
export default LunchAudioPlayerRecorderComponent;
Beta Was this translation helpful? Give feedback.
All reactions