Skip to content

Commit

Permalink
Added timeline to video compression page
Browse files Browse the repository at this point in the history
  • Loading branch information
yashlbbd committed Apr 27, 2020
1 parent f47ca6e commit ce149d7
Show file tree
Hide file tree
Showing 16 changed files with 220 additions and 52 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions app/src/main/java/com/sample/compressor/TimelineAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.sample.compressor

import android.content.Context
import android.graphics.Bitmap
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView

class TimelineAdapter(context: Context) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

private var bitmapList = ArrayList<Bitmap>()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return TimelineViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_timeline, parent, false))
}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is TimelineViewHolder) holder.bindView(position)
}

override fun getItemCount(): Int {
return bitmapList.size
}

inner class TimelineViewHolder(view: View): RecyclerView.ViewHolder(view) {
val timelineFrame = view.findViewById<ImageView>(R.id.iv_video_frame)

fun bindView(pos: Int) {
timelineFrame.setImageBitmap(bitmapList[pos])
}
}

fun updateList(data: ArrayList<Bitmap>) {
bitmapList.clear()
bitmapList.addAll(data)
notifyDataSetChanged()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.media.MediaMetadataRetriever;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
Expand All @@ -27,6 +29,7 @@
import androidx.core.app.NotificationCompat;
import androidx.lifecycle.Observer;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkInfo;
import androidx.work.WorkManager;
Expand All @@ -40,16 +43,21 @@
import com.karumi.dexter.listener.PermissionGrantedResponse;
import com.karumi.dexter.listener.single.BasePermissionListener;

import org.w3c.dom.Text;

import java.io.File;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;


public class VideoCompressActivity extends AppCompatActivity {

public static final String TAG = VideoCompressActivity.class.getSimpleName();
public static final String NOTIFICATION_CHANNEL_ID = "compressorChannel";
//User visible Channel Name
public static final String CHANNEL_NAME = "uploadsChannel";
Expand All @@ -64,9 +72,16 @@ public class VideoCompressActivity extends AppCompatActivity {

private ProgressBar pb_compress;
private CompressReceiver compressReceiver;
//
private TextView mediaInfo;
private RecyclerView timelineView;

private RestartReceiver restartService;
NotificationManager notificationManager;
//
private TimelineAdapter timelineAdapter;
//
private ProgressBar pbTimeline;


private long startTime, endTime;
Expand Down Expand Up @@ -146,6 +161,14 @@ public void onClick(View view) {
tv_progress = (TextView) findViewById(R.id.tv_progress);

pb_compress = (ProgressBar) findViewById(R.id.pb_compress);

mediaInfo = (TextView) findViewById(R.id.tv_mediaInfo);
timelineView = findViewById(R.id.rv_timeline);
pbTimeline = findViewById(R.id.pb_timeline);

timelineAdapter = new TimelineAdapter(this);
timelineView.setAdapter(timelineAdapter);

}

@Override
Expand All @@ -159,6 +182,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
try {
inputPath = Util.getFilePath(this, data.getData());
tv_input.setText(inputPath);
//Set Media meta data info here
final MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(inputPath);
Log.d(TAG, "media meta data received: " + mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_MIMETYPE));

extractMediaFrames(mediaMetadataRetriever);


} catch (URISyntaxException e) {
e.printStackTrace();
}
Expand All @@ -169,6 +200,49 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}

private void extractMediaFrames(final MediaMetadataRetriever mediaMetadataRetriever) {
String result = "";
result += "MimeType: " + mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_MIMETYPE) + "\n";
result += "Duration: " + mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION) + "ms\n";
result += "Bitrate: " + mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE) + "bits/s\n";

mediaInfo.setText(result);

pbTimeline.setVisibility(View.VISIBLE);
timelineView.setVisibility(View.GONE);

//Set an executor for background thread op
Executor executor = Executors.newSingleThreadExecutor();
executor.execute(new Runnable() {
@Override
public void run() {
//Prepare data source
long duration = Long.parseLong(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
long currentDuration = 0L;

final ArrayList<Bitmap> frames = new ArrayList<>();
while (currentDuration <= duration) {
//Will update every 5s
frames.add(mediaMetadataRetriever.getFrameAtTime(currentDuration * 1000));
currentDuration += 1000;
}
mediaMetadataRetriever.close();

VideoCompressActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
pbTimeline.setVisibility(View.GONE);
timelineView.setVisibility(View.VISIBLE);
timelineAdapter.updateList(frames);
Log.d(TAG, "Bitmap list size: " + frames.size());
}
});

}
});

}

private Locale getLocale() {
Configuration config = getResources().getConfiguration();
Locale sysLocale = null;
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/layout/item_timeline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:orientation="vertical">

<ImageView
android:id="@+id/iv_video_frame"
android:layout_width="100dp"
android:layout_height="100dp"
android:scaleType="centerCrop"/>
</LinearLayout>
32 changes: 32 additions & 0 deletions app/src/main/res/layout/video_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="10dp"
android:orientation="vertical"
android:gravity="center_horizontal">
Expand All @@ -10,6 +12,7 @@
android:layout_width="match_parent"
android:gravity="center_horizontal"
android:orientation="horizontal">

<Button android:id="@+id/btn_select"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -84,4 +87,33 @@
android:layout_width="40dp"
android:visibility="invisible"/>

<TextView
android:id="@+id/tv_mediaInfo"
android:layout_marginTop="12dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="asdsadsadsadsasadasdsadsadsd"
android:gravity="center"/>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ProgressBar
android:id="@+id/pb_timeline"
android:layout_width="48dp"
android:layout_height="48dp"
android:visibility="gone"
android:layout_gravity="center"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_timeline"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>

</FrameLayout>


</LinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
o/classes
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
o/classes
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<merger version="3"><dataSet config="main" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/main/jniLibs"/></dataSet><dataSet config="debug" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/debug/jniLibs"/></dataSet></merger>
<merger version="3"><dataSet config="main" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/yash/StudioProjects/compression/videocompressor/src/main/jniLibs"/></dataSet><dataSet config="debug" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/yash/StudioProjects/compression/videocompressor/src/debug/jniLibs"/></dataSet></merger>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<merger version="3"><dataSet config="main" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/main/shaders"/></dataSet><dataSet config="debug" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/debug/shaders"/></dataSet></merger>
<merger version="3"><dataSet config="main" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/yash/StudioProjects/compression/videocompressor/src/main/shaders"/></dataSet><dataSet config="debug" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/yash/StudioProjects/compression/videocompressor/src/debug/shaders"/></dataSet></merger>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<merger version="3"><dataSet config="main" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/main/assets"/><source path="/Users/lbb/AndroidStudioProjects/compression/videocompressor/build/intermediates/shader_assets/debug/out"/></dataSet><dataSet config="debug" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/debug/assets"/></dataSet></merger>
<merger version="3"><dataSet config="main" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/yash/StudioProjects/compression/videocompressor/src/main/assets"/><source path="/Users/yash/StudioProjects/compression/videocompressor/build/intermediates/shader_assets/debug/out"/></dataSet><dataSet config="debug" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/yash/StudioProjects/compression/videocompressor/src/debug/assets"/></dataSet></merger>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#Mon Apr 20 15:39:42 IST 2020
#Mon Apr 27 11:15:21 IST 2020
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<merger version="3"><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="main$Generated" generated="true" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/main/res"/><source path="/Users/lbb/AndroidStudioProjects/compression/videocompressor/build/generated/res/rs/debug"/><source path="/Users/lbb/AndroidStudioProjects/compression/videocompressor/build/generated/res/resValues/debug"/></dataSet><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="main" generated-set="main$Generated" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/main/res"><file path="/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/main/res/values/strings.xml" qualifiers=""><string name="app_name">VideoCompressor</string></file></source><source path="/Users/lbb/AndroidStudioProjects/compression/videocompressor/build/generated/res/rs/debug"/><source path="/Users/lbb/AndroidStudioProjects/compression/videocompressor/build/generated/res/resValues/debug"/></dataSet><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="debug$Generated" generated="true" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/debug/res"/></dataSet><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="debug" generated-set="debug$Generated" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/debug/res"/></dataSet><mergedItems/></merger>
<merger version="3"><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="main$Generated" generated="true" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/yash/StudioProjects/compression/videocompressor/src/main/res"/><source path="/Users/yash/StudioProjects/compression/videocompressor/build/generated/res/rs/debug"/><source path="/Users/yash/StudioProjects/compression/videocompressor/build/generated/res/resValues/debug"/></dataSet><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="main" generated-set="main$Generated" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/yash/StudioProjects/compression/videocompressor/src/main/res"><file path="/Users/yash/StudioProjects/compression/videocompressor/src/main/res/values/strings.xml" qualifiers=""><string name="app_name">VideoCompressor</string></file></source><source path="/Users/yash/StudioProjects/compression/videocompressor/build/generated/res/rs/debug"/><source path="/Users/yash/StudioProjects/compression/videocompressor/build/generated/res/resValues/debug"/></dataSet><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="debug$Generated" generated="true" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/yash/StudioProjects/compression/videocompressor/src/debug/res"/></dataSet><dataSet aapt-namespace="http://schemas.android.com/apk/res-auto" config="debug" generated-set="debug$Generated" ignore_pattern="!.svn:!.git:!.ds_store:!*.scc:.*:&lt;dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"><source path="/Users/yash/StudioProjects/compression/videocompressor/src/debug/res"/></dataSet><mergedItems/></merger>
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
6
7 <uses-sdk
8 android:minSdkVersion="15"
8-->/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/main/AndroidManifest.xml
8-->/Users/yash/StudioProjects/compression/videocompressor/src/main/AndroidManifest.xml
9 android:targetSdkVersion="29" />
9-->/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/main/AndroidManifest.xml
9-->/Users/yash/StudioProjects/compression/videocompressor/src/main/AndroidManifest.xml
10
11 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
11-->/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/main/AndroidManifest.xml:4:5-79
11-->/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/main/AndroidManifest.xml:4:22-77
11-->/Users/yash/StudioProjects/compression/videocompressor/src/main/AndroidManifest.xml:4:5-79
11-->/Users/yash/StudioProjects/compression/videocompressor/src/main/AndroidManifest.xml:4:22-77
12 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
12-->/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/main/AndroidManifest.xml:5:5-80
12-->/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/main/AndroidManifest.xml:5:22-78
12-->/Users/yash/StudioProjects/compression/videocompressor/src/main/AndroidManifest.xml:5:5-80
12-->/Users/yash/StudioProjects/compression/videocompressor/src/main/AndroidManifest.xml:5:22-78
13
14 <application
14-->/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/main/AndroidManifest.xml:7:5-8:37
14-->/Users/yash/StudioProjects/compression/videocompressor/src/main/AndroidManifest.xml:7:5-8:37
15 android:allowBackup="true"
15-->/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/main/AndroidManifest.xml:7:18-44
15-->/Users/yash/StudioProjects/compression/videocompressor/src/main/AndroidManifest.xml:7:18-44
16 android:label="@string/app_name"
16-->/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/main/AndroidManifest.xml:7:45-77
16-->/Users/yash/StudioProjects/compression/videocompressor/src/main/AndroidManifest.xml:7:45-77
17 android:supportsRtl="true" />
17-->/Users/lbb/AndroidStudioProjects/compression/videocompressor/src/main/AndroidManifest.xml:8:9-35
17-->/Users/yash/StudioProjects/compression/videocompressor/src/main/AndroidManifest.xml:8:9-35
18
19</manifest>
Loading

0 comments on commit ce149d7

Please sign in to comment.