AgoraIO-Extensions / react-native-agora

React Native around the Agora RTC SDKs for Android and iOS agora
https://www.agora.io
MIT License
626 stars 227 forks source link

Virtual background for image is not working #829

Open risingmax123456 opened 1 month ago

risingmax123456 commented 1 month ago

Describe the bug Virtual background for image is not working receiving error -2 in console

To Reproduce Steps to reproduce the behavior: implement agora with group video call and set a image virtual background

Expected behavior Virtual background should work

Code using

agoraEngine?.enableExtension(
     'agora_video_filters_segmentation',
    'portrait_segmentation',
    true,
 );

let backgroundSourceType = BackgroundSourceType.BackgroundImg; let source = 'https://jamme3na.blob.core.windows.net/jamme3na/001A00AD-630C-44FB-8054-6826F02C1564.jpg'; const result = agoraEngine?.enableVirtualBackground( true, { background_source_type: backgroundSourceType, source: source, }, {}, ); if (result !== 0) { console.error('Failed to set virtual background. Error code:', result); }

please help

guoxianzhe commented 1 month ago

@risingmax123456 pls check https://github.com/AgoraIO-Extensions/react-native-agora/blob/main/example/src/examples/advanced/VirtualBackground/VirtualBackground.tsx#L132

risingmax123456 commented 1 month ago

follow same documentation still facing issue

guoxianzhe commented 1 month ago

@risingmax123456 You should use local absolute path of the custom background image.

risingmax123456 commented 1 month ago

i am using this to get absolute path still having issue

export async function getAbsolutePath(filePath) { if (Platform.OS === 'android') { if (filePath.startsWith('/assets/')) { const fileName = filePath.replace('/assets/', ''); const destPath = ${ExternalCachesDirectoryPath}/${fileName}; if (!(await exists(destPath))) { await copyFileAssets(fileName, destPath); } return destPath; } } return filePath; }

risingmax123456 commented 2 weeks ago

Any update ?

guoxianzhe commented 2 weeks ago

@risingmax123456 Can you try to install the demo in your phone? It works fine to me. You can refer to the image configuration and code of the demo in https://github.com/AgoraIO-Extensions/react-native-agora/blob/main/example/src/examples/advanced/VirtualBackground/VirtualBackground.tsx#L132