Replies: 1 comment
-
Would you please try example app in the repo and compare with your's? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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