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
Live Audio Streaming not working in socket using when i receiving the audio file facing the error like Failed to load sound {"extra": -2147483648, "what": 1}
#29
Open
DevaPandiyan opened this issue
May 21, 2024
· 0 comments
const timestamp = Date.now();
// const buffer = Buffer.from(chunk, 'base64');
const base64String = 'data:audio/wav;base64,' + chunk;
const filePath = `${RNFS.DocumentDirectoryPath}/temp_sound_${timestamp}.wav`;
// Ensure the directory exists
await RNFS.mkdir(RNFS.DocumentDirectoryPath);
// Write the audio chunk to a file
await RNFS.writeFile(filePath,chunk, 'base64').then(async ()=>{
const fileExists = await RNFS.exists(filePath);
if (!fileExists) {
console.log('Audio file does not exist');
return;
}
// Play the audio file
const sound = new Sound(filePath,'', (error) => {
if (error) {
console.log('Failed to load sound', error);
return;
}
sound.play((success) => {
if (success) {
console.log('Successfully finished playing');
} else {
console.log('Playback failed due to audio decoding errors');
}
sound.release();
});
});
});
} catch (err) {
console.log('Failed to play sound', err);
}
};
return (
);
};
export default LiveStreaming;
const styles = StyleSheet.create({
});
`
The text was updated successfully, but these errors were encountered:
DevaPandiyan
changed the title
Live Audio Streaming not working
Live Audio Streaming not working in socket
May 21, 2024
DevaPandiyan
changed the title
Live Audio Streaming not working in socket
Live Audio Streaming not working in socket using when i receiving the audio file facing the error like Failed to load sound {"extra": -2147483648, "what": 1}
May 21, 2024
`import { Alert, Button, PermissionsAndroid, Platform, StyleSheet, Text, View } from 'react-native';
import React, { useEffect, useState } from 'react';
import io from 'socket.io-client';
import { useNavigation } from '@react-navigation/native';
import Sound from 'react-native-sound';
import LiveAudioStream from 'react-native-live-audio-stream';
import { Buffer } from 'buffer';
import RNFS from 'react-native-fs';
Sound.setCategory('Playback');
const LiveStreaming = () => {
const navigation = useNavigation();
const [socket, setSocket] = useState(null);
const [isStreaming, setIsStreaming] = useState(false);
const [initial, setInitial] = useState(false);
useEffect(() => {
const socketInstance = io('https://devtamilcalendar.shrewdbs.com', { path: '/audio-meeting' });
}, []);
const ListenerJoin = () => {
if (socket) {
const data = {
username: "Raone",
isSpeaker: false,
};
socket.emit('join', data);
}
};
const SpeakerJoin = () => {
if (socket) {
const data = {
username: "Ravana",
isSpeaker: true,
};
socket.emit('join', data);
}
};
const requestAudioPermission = async () => {
if (Platform.OS === 'android') {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
{
title: 'Audio Permission',
message: 'App needs access to your microphone to record audio.',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
},
);
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
console.log('Audio permission denied');
}
} catch (err) {
console.warn(err);
}
}
};
useEffect(() => {
console.log("isStreaming",isStreaming)
}, [ ]);
const startStreaming = () => {
if (socket && !isStreaming) {
LiveAudioStream.start();
LiveAudioStream.on('data', data => {
var chunk = Buffer.from(data, 'base64');
socket.emit('audio_emit', data);
// console.log('Emitted audio chunk:',data);
});
};
const receiveAudio = async (chunk) => {
console.log("Received audio chunk:", chunk);
await playSound(chunk);
};
const stopStreaming = () => {
if (isStreaming) {
LiveAudioStream.stop();
setIsStreaming(false);
}
};
const AdminClear = () => {
if (socket) {
socket.emit('adminCommand', "clearAll");
}
};
const playSound = async (chunk) => {
try {
} catch (err) {
console.log('Failed to play sound', err);
}
};
return (
);
};
export default LiveStreaming;
const styles = StyleSheet.create({
});
`
The text was updated successfully, but these errors were encountered: