Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use constructor on android 10,11 #102

Open
trongtrong opened this issue Apr 9, 2021 · 0 comments
Open

How to use constructor on android 10,11 #102

trongtrong opened this issue Apr 9, 2021 · 0 comments

Comments

@trongtrong
Copy link

trongtrong commented Apr 9, 2021

Hi, i have a problem when using libary on andoid 10,11.
i use this constructor

public GPUMp4Composer descriptor(final FileDescriptor srcFileDescriptor, @NonNull final FileDescriptor destFileDescriptor) { if (Build.VERSION.SDK_INT < 26) { throw new IllegalArgumentException("destFileDescriptor can not use"); } this.srcDataSource = new FileDescriptorDataSource(srcFileDescriptor); this.destPath = null; this.destFileDescriptor = destFileDescriptor; return this; }

I have srcFileDescriptor by method:
public static FileDescriptor getSrcFileDescriptior(Context context, Uri uri) { try { ParcelFileDescriptor parcelFileDescriptor = context.getContentResolver().openFileDescriptor(uri, "rw"); return parcelFileDescriptor.getFileDescriptor(); } catch (FileNotFoundException e) { e.printStackTrace(); } return null; }

i use bellow method to get destFileDescriptor :

`
public static FileDescriptor getDesFileDescriptior(Context context) {

    Uri uriSavedVideo = null;
    try {
        ContentResolver resolver = context.getContentResolver();
        ContentValues contentValues = new ContentValues();
        contentValues.put(MediaStore.Video.Media.TITLE, System.currentTimeMillis() / 1000);
        contentValues.put(MediaStore.Video.Media.DISPLAY_NAME, System.currentTimeMillis() / 1000);
        contentValues.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
        contentValues.put(MediaStore.Video.Media.DATE_ADDED, System.currentTimeMillis() / 1000);

        Uri collection;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            collection = MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL);
            contentValues.put(MediaStore.Video.Media.RELATIVE_PATH, Environment.DIRECTORY_DCIM + context.getString(R.string.folder_app));

        } else {
            String videoPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString() + "/" + "test.mp4";
            collection = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            contentValues.put(MediaStore.Video.Media.DATA, videoPath);
        }
        uriSavedVideo = resolver.insert(collection, contentValues);

        return context.getContentResolver().openFileDescriptor(uriSavedVideo , "w").getFileDescriptor();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;`

But when i run, I get the following error:

W/System.err: java.lang.NullPointerException: uri 2021-04-09 10:36:20.285 8431-8431/com.example.textonvideo W/System.err: at com.android.internal.util.Preconditions.checkNotNull(Preconditions.java:128) 2021-04-09 10:36:20.285 8431-8431/com.example.textonvideo W/System.err: at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1233) 2021-04-09 10:36:20.285 8431-8431/com.example.textonvideo W/System.err: at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1106) 2021-04-09 10:36:20.285 8431-8431/com.example.textonvideo W/System.err: at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1060) 2021-04-09 10:36:20.285 8431-8431/com.example.textonvideo W/System.err: at com.videoart.textonvideo.utils.Utils.getDesFileDescriptior(Utils.java:109) 2021-04-09 10:36:20.286 8431-8431/com.example.textonvideo W/System.err: at com.videoart.textonvideo.services.VideoEditorService.composeMp4(VideoEditorService.java:114) 2021-04-09 10:36:20.286 8431-8431/com.example.textonvideo W/System.err: at com.videoart.textonvideo.services.VideoEditorService.onStartCommand(VideoEditorService.java:63) 2021-04-09 10:36:20.286 8431-8431/com.example.textonvideo W/System.err: at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3693) 2021-04-09 10:36:20.286 8431-8431/com.example.textonvideo W/System.err: at android.app.ActivityThread.-wrap22(Unknown Source:0) 2021-04-09 10:36:20.286 8431-8431/com.example.textonvideo W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1827) 2021-04-09 10:36:20.286 8431-8431/com.example.textonvideo W/System.err: at android.os.Handler.dispatchMessage(Handler.java:106) 2021-04-09 10:36:20.286 8431-8431/com.example.textonvideo W/System.err: at android.os.Looper.loop(Looper.java:164) 2021-04-09 10:36:20.287 8431-8431/com.example.textonvideo W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7000) 2021-04-09 10:36:20.287 8431-8431/com.example.textonvideo W/System.err: at java.lang.reflect.Method.invoke(Native Method) 2021-04-09 10:36:20.287 8431-8431/com.example.textonvideo W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441) 2021-04-09 10:36:20.287 8431-8431/com.example.textonvideo W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)

how to solve this problem ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant