linkedin / linkedin/LiTr

Help with the implementation of listener

Open
#175 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
663
Forks
92
PR merge metrics
No merged PRs in 30d

Description

Hi, first of all thanks a lot for making LiTr and keeping it opensource. I need a help. I am a bit confused as to how to implement the listener. What I am trying to do is basically take a video, change the width and height of the video keeping the aspect ratio sama and reduce the bitrate of both the video and audio track (Basically trying to reduce the size of the video before uploading to firebase). I have used the TransformationListener but seems like the methods of the interface are not being triggered. I have used debugger to track whether the onStart or onComplete function is being triggered but apparently they are not. I am attaching the code snippet here that I have used. I would really appreciate if someone can guide me as to what mistake I am doing. Also after the video is transcoded how do I access the URI of the transcoded video??

private void compressAndUpload(final Uri fileUri, final String fileName, final StorageReference photoRef, final String uploadPath, final String groupName, final String feedName, FeedPostData feedPostData) {
        File f = new File(getFilesDir().getAbsolutePath() + "/" + getPackageName() + "/media/videos");
        if (f.mkdirs() || f.isDirectory()) {
            //compress and output new video specs
            Log.d(TAG, "inside if to async task");
//            new VideoCompressAsyncTask(this, this, fileUri, fileName, photoRef, uploadPath, groupName, feedName, feedPostData).execute(fileUri.toString(), f.getPath());
            TransformationListener listener;
            listener = new TransformationListener() {
                @Override
                public void onStarted(@NonNull String id) {
                    Log.d(TAG, "onStarted: ");
                }

                @Override
                public void onProgress(@NonNull String id, float progress) {
                    Log.d(TAG, "onStarted: ");
                }

                @Override
                public void onCompleted(@NonNull String id, @Nullable List<TrackTransformationInfo> trackTransformationInfos) {
                    Log.d(TAG, "onStarted: ");
                    uploadFile(Uri.fromFile(new File(f.getPath())), photoRef, groupName, feedName, feedPostData);
                }

                @Override
                public void onCancelled(@NonNull String id, @Nullable List<TrackTransformationInfo> trackTransformationInfos) {

                }

                @Override
                public void onError(@NonNull String id, @Nullable Throwable cause, @Nullable List<TrackTransformationInfo> trackTransformationInfos) {

                }
            };
            String filePath = null;
            try {

                MediaMetadataRetriever retriever = new MediaMetadataRetriever();
                retriever.setDataSource(Uri.parse(fileUri.toString()).getPath());

                MediaExtractor mediaExtractor = new MediaExtractor();
                mediaExtractor.setDataSource(Uri.parse(fileUri.toString()).getPath());
                MediaFormat inputFormat = selectVideoTrack(mediaExtractor);

                MediaFormat mediaFormat = MediaFormat.createVideoFormat(
                        MediaFormat.MIMETYPE_VIDEO_AVC,
                        inputFormat.getInteger(MediaFormat.KEY_WIDTH),
                        inputFormat.getInteger(MediaFormat.KEY_HEIGHT));

                int bitrate = Integer.parseInt(retriever.extractMetadata((MediaMetadataRetriever.METADATA_KEY_BITRATE)));

                Log.d(TAG, "OG bitrate is : " + bitrate);

                int destBitrate = bitrate;
                if (bitrate > 5 * 1024 * 1024 || new File(fileUri.toString()).length() > 10 * 1024 * 1024) {
                    destBitrate = Math.min(bitrate / 2, 5 * 1024 * 1024); // max Bitrate allowed = 5Mbps
                }

                mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, destBitrate );
                MediaTransformer mediaTransformer = new MediaTransformer(getApplicationContext());

                mediaTransformer.transform(UUID.randomUUID().toString(),
                        Uri.parse(fileUri.toString()),
                        Uri.fromFile(new File(f.getPath())).getPath(),
                        mediaFormat,
                        null,
                        listener,
                        null);


            } catch (IOException e) {
                FirebaseCrashlytics.getInstance().recordException(e);
                e.printStackTrace();
            }
        }
    } 

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the TransformationListener callbacks and the MediaTransformer.transform call shown in the issue, including its input and output URI arguments. Reproduce the transformation with the provided listener and inspect whether callbacks fire; done means the listener lifecycle is understood and the resulting transcoded file URI can be identified for upload.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.