a914-gowtham / android-video-trimmer

Helps to trim local videos with compress option on Android applications using Exoplayer 2 and FFmpeg.
Other
362 stars 115 forks source link

getRealPath getting null #56

Closed Narendrakumar-Vanamala closed 1 year ago

Narendrakumar-Vanamala commented 3 years ago

Updated provider details in the manifest as well.

Am adding this project as library to main project, updated all the permissions and provider details too

hsinha76 commented 3 years ago

Getting same issue.

a914-gowtham commented 3 years ago

@Narendrakumar-Vanamala @hsinha76 Could you share the device detail and library version?

Narendrakumar-Vanamala commented 3 years ago

Am checking Samsung Galaxy- A30S - Android 11 Version

a914-gowtham commented 3 years ago

this issue had been fixed in 1.7.0. Could you share the library version?

hsinha76 commented 3 years ago

Xioami Note 4 Android version 7.0

Narendrakumar-Vanamala commented 3 years ago

this issue had been fixed in 1.7.0. Could you share the library version

Am using 1.7.0 version and yesterday i debug here are the obsevation

Library working demo i verified it am getting file path as content://media/external/video/media/1583 but my application returns some different path as /storage/emulated/0/Android/data/packagename/cache/test.mp4.

Please suggest and help me for the above fix.

a914-gowtham commented 3 years ago

Before, 1.5.11 there was an option to store video files in the storage folder wherever we want. In 1.5.11 I removed write permission due to the android 11 storage changes.

Demo app uses an older version than 1.5.11.

Now Trimmed videos are stored as a cache file because it doesn't need any write permission, won't be showing in the gallery as a video file and I thought it would be fine. since most use cases will be just uploading the trimmed video file to the server.

Narendrakumar-Vanamala commented 3 years ago

Before, 1.5.11 there was an option to store video files in the storage folder wherever we want. In 1.5.11 I removed write permission due to the android 11 storage changes.

Demo app uses an older version than 1.5.11.

Now Trimmed videos are stored as a cache file because it doesn't need any write permission, won't be showing in the gallery as a video file and I thought it would be fine. since most use cases will be just uploading the trimmed video file to the server.

I checked latest version too, am getting the same issue. shall I change the video save location ? Please suggest on this.

It would be great help me on how to store video file location in Android-11 and i need to pass that location to TrimActivity.

a914-gowtham commented 3 years ago

You can't change video location.

  1. Do you still get getRealPath null issue?
  2. Share your use case I will try to find a workaround
Narendrakumar-Vanamala commented 3 years ago

Yes, am getting null

Here is the my usecase

We have two options one is record a video and trim the video and other one is pick video from gallery and trim. Now am passing video storage URLto openTrimActivity(), after that am getting null from getRealPath() method.

Here the below format am passing storage URL to openTrimActivity() ex: /storage/emulated/0/Android/data/packagename/cache/test.mp4.

Let me know any other details if required.

a914-gowtham commented 3 years ago

@Narendrakumar-Vanamala Can try passing uri string instead of filepath

Narendrakumar-Vanamala commented 3 years ago

Ya I tried with Uri.fromFile() pass file as input and it's works fine now.

Thanks.

On Sun, 4 Jul, 2021, 3:34 pm Gowtham Balamurugan, @.***> wrote:

@Narendrakumar-Vanamala https://github.com/Narendrakumar-Vanamala Can try passing uri string instead of filepath

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/a914-gowtham/android-video-trimmer/issues/56#issuecomment-873558324, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACDM5X3XDTBGT4YF6QP6UBDTWAWZ3ANCNFSM47YAPW3Q .

gifandadelasty commented 1 year ago

Hello.. I'm getting same issue.. I'm developing app that allow user to take video or pick from gallery, but after video taken and video saved in storage Video Trimmer facing error with this details :

java.lang.NullPointerException: Attempt to invoke interface method 'int android.database.Cursor.getColumnIndexOrThrow(java.lang.String)' on a null object reference at com.gowtham.library.utils.FileUtils.getRealPath(FileUtils.java:26) at com.gowtham.library.ui.ActVideoTrimmer.lambda$setDataInView$4$com-gowtham-library-ui-ActVideoTrimmer(ActVideoTrimmer.java:217) at com.gowtham.library.ui.ActVideoTrimmer$$ExternalSyntheticLambda11.run(Unknown Source:2) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:764)

This is code in CreatorActivity.kt :

// --- START TRIM VIDEO --- TrimVideo.activity(videoUri.toString()) .setCompressOption(CompressOption(30, "1M", 480, 640)) .setTrimType(TrimType.MIN_MAX_DURATION) .setMinToMax(10, 120) .start(this, startTrimVideoForResult)

videoUri is an Uri, and it converted to string with toString() to become: "/storage/emulated/0/AppName/Camera/video_2023Jun24_2209.mp4"

I have try using Uri.fromFile() that suggested by @Narendrakumar-Vanamala , but still getting this NullException..

Thanks for your help..

gifandadelasty commented 1 year ago

Hi bro.. I have solved this.. This library needs Content Uri instead of File Path. So, if the video come from CameraActivity.kt first its need to converted to content Uri before calling TrimVideo activity..

Before : "/storage/emulated/0/AppName/Camera/video_2023Jun24_2209.mp4" (getRealPath getting Null)

Converting to Content Uri: [ KOTLIN ] val videoFile = File("/storage/emulated/0/VideoPath/example_video.mp4") val projection = arrayOf(videoFile.absolutePath) MediaScannerConnection.scanFile(context, projection, null) { path, contentUri -> // --- TrimVideo.activity(contentUri.toString()) --- }

[ JAVA ] File videoFile = new File("/storage/emulated/0/VideoPath/example_video.mp4"); String[] projection = { videoFile.getAbsolutePath() }; MediaScannerConnection.scanFile(context, projection, null, new MediaScannerConnection.OnScanCompletedListener() { public void onScanCompleted(String path, Uri contentUri) { // --- TrimVideo.activity(contentUri.toString()) --- } });

After : "content://media/external/video/media/####" (Its WORKED)

Thank you for the great library @a914-gowtham 👍

Reference : https://stackoverflow.com/a/53349110/18410044

a914-gowtham commented 1 year ago

thanks @gifandadelasty . I have fixed this and added some fixes for android 13 in v1.7.14

simon1867 commented 3 months ago

The work around works for me, but there's a similar issue on version 1.7.19

There should be another option to pass the absolute path if the client already has it. And then just don't call FileUtilKt.getValidatedFileUri() because you already have the actual file path. With the work around ^^ we have to convert the actual file path back to a media store path, and then the library converts it back to the actual path. Just add the option to set the actual path if we have it.

Could be adding a new static method. And then set the boolean value in the bundle and reference it to determine if you need to get the validated file uri.

public static ActivityBuilder activity(String uri) {
       return new ActivityBuilder(uri, false);
 }

public static ActivityBuilder activity(String uri, boolean isActualPath) {
       return new ActivityBuilder(uri, isActualPath);
}

Here is my stack trace:

java.io.FileNotFoundException: No content provider: /storage/emulated/0/Movies/IMG_20240328_120059_339.mp4
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:2029)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1858)
at android.content.ContentResolver.openInputStream(ContentResolver.java:1528)
at com.gowtham.library.utils.FileUtilKt.getValidatedFileUri(FileUtilsKt.kt:18)
at com.gowtham.library.ui.ActVideoTrimmer.lambda$setDataInView$4(ActVideoTrimmer.java:219)