React native 如何在捕获新视频时不捕获设备上运行的音频播放
我在expo/react native中创建了一个应用程序,其中我将用户使用expo av拍摄的许多视频分层,类似于acapella效果。现在,如果用户不使用耳机并尝试分层新视频以收听他们以前的录音,则他们以前录音的声音(在电话扬声器上播放)会干扰新录音。 这似乎是可以避免的,因为我们看到,当使用Skype或Zoom时,用户无法听到来自远程用户的声音反馈。 是否可以使用expo av或任何react本机库来消除扬声器声音? 共享一些代码以备不时之需React native 如何在捕获新视频时不捕获设备上运行的音频播放,react-native,audio,video,expo,React Native,Audio,Video,Expo,我在expo/react native中创建了一个应用程序,其中我将用户使用expo av拍摄的许多视频分层,类似于acapella效果。现在,如果用户不使用耳机并尝试分层新视频以收听他们以前的录音,则他们以前录音的声音(在电话扬声器上播放)会干扰新录音。 这似乎是可以避免的,因为我们看到,当使用Skype或Zoom时,用户无法听到来自远程用户的声音反馈。 是否可以使用expo av或任何react本机库来消除扬声器声音? 共享一些代码以备不时之需 import React, { useStat
import React, { useState, useEffect, useRef } from 'react';
import { Text, View, TouchableOpacity } from 'react-native';
import { Camera } from 'expo-camera';
import {Video} from 'expo-av';
import { Ionicons } from '@expo/vector-icons';
export default function App() {
const [hasPermission, setHasPermission] = useState(null);
const [cameraRef, setCameraRef] = useState(null);
const [videoRef,setVideoRef] = useState(null);
const [type, setType] = useState(Camera.Constants.Type.back);
const [recording, setRecording] = useState(false);
const [videoSource, setVideoSource]= useState('http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4')
useEffect(() => {
(async () => {
const { status } = await Camera.requestPermissionsAsync();
setHasPermission(status === 'granted');
})();
}, []);
const fireOnLoad=()=>{
}
if (hasPermission === null) {
return <View />;
}
if (hasPermission === false) {
return <Text>No access to camera</Text>;
}
return (
<View style={{ flex: 1 }}>
<Camera style={{ flex: 1 }} type={type} ref={ref => {
setCameraRef(ref) ;
}}>
<View
style={{
flex: 1,
backgroundColor: 'transparent',
justifyContent: 'flex-end'
}}>
<View style={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-evenly'
}}>
<TouchableOpacity
style={{
flex: 0.1,
alignSelf: 'flex-end'
}}
onPress={() => {
setType(
type === Camera.Constants.Type.back
? Camera.Constants.Type.front
: Camera.Constants.Type.back
);
}}>
<Ionicons name={ Platform.OS === 'ios' ? "ios-reverse-camera" : 'md-reverse-camera'} size={40} color="white" />
</TouchableOpacity>
<TouchableOpacity style={{alignSelf: 'center'}} onPress={async() => {
if(cameraRef){
let photo = await cameraRef.takePictureAsync();
console.log('photo', photo);
}
}}>
<View style={{
borderWidth: 2,
borderRadius:60,
borderColor: 'white',
height: 50,
width:50,
display: 'flex',
justifyContent: 'center',
alignItems: 'center'}}
>
<View style={{
borderWidth: 2,
borderRadius:60,
borderColor: 'white',
height: 40,
width:40,
backgroundColor: 'white'}} >
</View>
</View>
</TouchableOpacity>
<TouchableOpacity style={{alignSelf: 'center'}} onPress={async() => {
if(!recording){
setRecording(true)
let video = await cameraRef.recordAsync();
//console.log('video', video);
setVideoSource(video.uri);
} else {
setRecording(false)
cameraRef.stopRecording()
}
}}>
<View style={{
borderWidth: 2,
borderRadius:60,
borderColor: 'red',
height: 50,
width:50,
display: 'flex',
justifyContent: 'center',
alignItems: 'center'}}
>
<View style={{
borderWidth: 2,
borderRadius:60,
borderColor: 'red',
height: 40,
width:40,
backgroundColor: 'red'}} >
</View>
</View>
</TouchableOpacity>
</View>
</View>
</Camera>
<Video
source={{ uri: videoSource }}
style={{ flex: 1 }}
useNativeControls='true'
resizeMode={Video.RESIZE_MODE_COVER}
onLoad={fireOnLoad}
onError={fireOnLoad}
isMuted={false}
/>
</View>
);
}
import React,{useState,useffect,useRef}来自'React';
从“react native”导入{Text,View,TouchableOpacity};
从“expo Camera”导入{Camera};
从“expo av”导入{Video};
从“@expo/vector icons”导入{Ionicons};
导出默认函数App(){
const[hasPermission,setHasPermission]=useState(null);
const[cameraRef,setCameraRef]=useState(null);
const[videoRef,setVideoRef]=useState(null);
const[type,setType]=useState(Camera.Constants.type.back);
const[recording,setRecording]=使用状态(false);
const[videoSource,setVideoSource]=useState('http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4')
useffect(()=>{
(异步()=>{
const{status}=wait-Camera.requestPermissionsAsync();
setHasPermission(状态==‘已授予’);
})();
}, []);
常量fireOnLoad=()=>{
}
if(hasPermission==null){
返回;
}
if(hasPermission==false){
不允许进入摄像机;
}
返回(
{
setCameraRef(参考);
}}>
{
集合类型(
类型===Camera.Constants.type.back
?摄像头.常数.类型.前部
:Camera.Constants.Type.back
);
}}>
{
如果(摄影师){
let photo=wait cameraRef.takePictureAsync();
console.log('photo',photo);
}
}}>
{
如果(!录制){
设置录制(真)
let video=wait cameraRef.recordAsync();
//console.log('video',video);
setVideoSource(video.uri);
}否则{
设置录制(错误)
cameraRef.stopRecording()
}
}}>
);
}