Skip to content

Commit

Permalink
Add backgroiund replacement code
Browse files Browse the repository at this point in the history
  • Loading branch information
goncalocostamendes committed Jan 25, 2024
1 parent be9fac2 commit 12d76d8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Video-Transformers-Java/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ android {

dependencies {
// Dependency versions are defined in the ../../commons.gradle file
implementation "com.opentok.android:opentok-android-sdk:2.25.2"
implementation "com.opentok.android:opentok-android-sdk:2.27.0"
implementation "androidx.appcompat:appcompat:${extAppCompatVersion}"
implementation "pub.devrel:easypermissions:${extEasyPermissionsVersion}"
implementation "androidx.constraintlayout:constraintlayout:${extConstraintLyoutVersion}"
Expand Down
1 change: 1 addition & 0 deletions Video-Transformers-Java/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.Manifest;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
Expand Down Expand Up @@ -39,6 +40,7 @@
import retrofit2.Retrofit;
import retrofit2.converter.moshi.MoshiConverterFactory;

import java.io.File;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -205,7 +207,7 @@ public void onPermissionsDenied(int requestCode, List<String> perms) {

@AfterPermissionGranted(PERMISSIONS_REQUEST_CODE)
private void requestPermissions() {
String[] perms = {Manifest.permission.INTERNET, Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO};
String[] perms = {Manifest.permission.INTERNET, Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.READ_EXTERNAL_STORAGE};

if (EasyPermissions.hasPermissions(this, perms)) {

Expand Down Expand Up @@ -354,10 +356,25 @@ public void onTransform(BaseVideoRenderer.Frame frame){
public void SetVideoTransformers(View view) {
if(!isSet) {
videoTransformers.clear();
PublisherKit.VideoTransformer backgroundBlur = publisher.new VideoTransformer("BackgroundBlur", "{\"radius\":\"High\"}");
PublisherKit.VideoTransformer myCustomTransformer = publisher.new VideoTransformer("myTransformer", logoTransformer);
videoTransformers.add(backgroundBlur);
videoTransformers.add(myCustomTransformer);
String resourceName;
try {
resourceName = getResources().getResourceEntryName(R.drawable.beach); // Assuming "beach" is the name of the drawable resource
} catch (Resources.NotFoundException e) {
return; // Return if the resource ID is not found
}

File imageFile = new File(getBaseContext().getFilesDir(), resourceName + ".jpeg");

//ArrayList<PublisherKit.VideoTransformer> videoTransformers = new ArrayList<>();
PublisherKit.VideoTransformer backgroundReplacement = publisher.new VideoTransformer(
"BackgroundReplacement",
"{\"image_file_path\":\"" + imageFile.getAbsolutePath() + "\"}"
);
videoTransformers.add(backgroundReplacement);
//PublisherKit.VideoTransformer backgroundBlur = publisher.new VideoTransformer("BackgroundBlur", "{\"radius\":\"High\"}");
//PublisherKit.VideoTransformer myCustomTransformer = publisher.new VideoTransformer("myTransformer", logoTransformer);
//videoTransformers.add(backgroundBlur);
//videoTransformers.add(myCustomTransformer);
publisher.setVideoTransformers(videoTransformers);
isSet = true;
buttonVideoTransformers.setText("Reset");
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 12d76d8

Please sign in to comment.