Skip to main content

Remove audio from the video

The function allows you to remove audio from a video by specifying the file uri of the video.

Parameters

  • fileUri (string): The file uri of the video you want to trim.

Returns

A promise that resolves with the following values:

  • onfulfilled: the extracted audio's url
  • onrejected: the error message

Note: By default,the audio file format will be .aac,support for more format coming soon !

Supported Formats

  • Android: Currently, We support the .mp4 and .webm video formats. But, we are looking ahed to support more video formats

Usage

import React, { useState } from 'react';
import {
View,
Button,
Dimensions,
Alert,
StyleSheet,
ActivityIndicator,
Text,
} from 'react-native';
import { removeAudioFromVideo } from 'rnvideoeditor';
import { launchImageLibrary } from 'react-native-image-picker';

const AudioRemover = () => {
const [isProcessing, setIsProcessing] = useState(false);

const removeAudioAsync = async (fileUri: string) => {
try {
const outputVideoUri = await removeAudioFromVideo(fileUri);

console.log('Output video uri', outputVideoUri);

Alert.alert('Audio removed', outputVideoUri);
} catch (error) {
console.log('Error:', error);

Alert.alert('Failed to remove the audio', JSON.stringify(error.message));
} finally {
setIsProcessing(false);
}
};

const handlePickAndRemove = async () => {
const result = await launchImageLibrary({
mediaType: 'video',
});

if (result.assets) {
const fileUri = result.assets[0]?.uri;
if (!fileUri) return;

setIsProcessing(true);

removeAudioAsync(fileUri);
}
};

return (
<View style={styles.container}>
<Text style={styles.processingText}>
{isProcessing ? 'Removing Audio...' : ''}
</Text>
{isProcessing && <ActivityIndicator size="large" color="#0000ff" />}
<Button
title="Pick Video And Remove Audio from it"
onPress={handlePickAndRemove}
disabled={isProcessing}
/>
</View>
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
processingText: {
marginBottom: 10,
},
});

export default AudioRemover;