Skip to content

Commit

Permalink
tracks video integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaji Khan committed Mar 15, 2024
1 parent 2a93056 commit b505db9
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/src/main/java/com/shajikhan/ladspa/amprack/Camera2.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.media.MediaCodecInfo;
import android.media.MediaFormat;
import android.media.MediaMuxer;
import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.util.Log;
Expand Down Expand Up @@ -280,9 +281,12 @@ private void prepareEncoder() {
// hard-coded output directory.
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy_HH.mm.ss");
Date date = new Date();
mainActivity.lastRecordedFileName = formatter.format(date);
mainActivity.lastRecordedFileName = mainActivity.dir.getAbsolutePath() + "/" + mainActivity.lastRecordedFileName + ".mp4";
mainActivity.lastRecordedFileName =
String.format("%s/%s.mp4",
mainActivity.getExternalFilesDir(Environment.DIRECTORY_MOVIES).getAbsolutePath(),
formatter.format(date));
String outputPath = mainActivity.lastRecordedFileName;
Log.d(TAG, String.format ("recording video to file: %s", mainActivity.lastRecordedFileName));

// Create a MediaMuxer. We can't add the video track and start() the muxer here,
// because our MediaFormat doesn't have the Magic Goodies. These can only be
Expand Down Expand Up @@ -426,7 +430,7 @@ public void onOutputBufferAvailable(@NonNull MediaCodec codec, int index, @NonNu
mMuxer.start();
mMuxerStarted = true;
}

outPutByteBuffer = codec.getOutputBuffer(index);
// byte[] outDate = new byte[info.size];
// outPutByteBuffer.get(outDate);
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/shajikhan/ladspa/amprack/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -786,6 +788,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
}

tracks.load(dir);
tracks.load(context.getExternalFilesDir(Environment.DIRECTORY_MOVIES));
Set<String> _tracksCustom = defaultSharedPreferences.getStringSet("tracks", null) ;
if (_tracksCustom != null) {
for (String _d:
Expand Down Expand Up @@ -856,6 +859,26 @@ void showMediaPlayerDialog() {
LayoutInflater inflater = getLayoutInflater();

ConstraintLayout constraintLayout = (ConstraintLayout) inflater.inflate(R.layout.media_player_dialog, null);
SurfaceView surface = constraintLayout.findViewById(R.id.video_player_dialog);

surface.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
mediaPlayer.setDisplay(holder);
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {

}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {

}
});

ToggleButton toggleButton = constraintLayout.findViewById(R.id.media_play);
Button openFolder = constraintLayout.findViewById(R.id.open_folder);
openFolder.setOnClickListener(new View.OnClickListener() {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/shajikhan/ladspa/amprack/Rack.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (!isChecked) {
videoPreview.setVisibility(View.GONE);
mainActivity.camera2.closeCamera();
mainActivity.showMediaPlayerDialog();
}
else {
videoPreview.setVisibility(View.VISIBLE);
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/com/shajikhan/ladspa/amprack/Tracks.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
Expand All @@ -29,6 +31,7 @@
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.analytics.AnalyticsListener;
import com.google.android.exoplayer2.audio.AuxEffectInfo;
import com.google.android.material.slider.Slider;

Expand All @@ -41,6 +44,7 @@ public class Tracks extends Fragment {
ToggleButton playPause ;
boolean themeInit = false;
String TAG = getClass().getSimpleName();
SurfaceView surfaceView;
String filesDir ;
ExoPlayer player ;
static int requestCode = 1001 ;
Expand Down Expand Up @@ -70,8 +74,27 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
recyclerView = (RecyclerView) view.findViewById(R.id.tracks_recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(mainActivity));
recyclerView.setAdapter(tracksAdapter);
surfaceView = view.findViewById(R.id.tracks_video);
// load (mainActivity.dir);

surfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(@NonNull SurfaceHolder holder) {
player.setVideoSurface(surfaceView.getHolder().getSurface());

}

@Override
public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {

}

@Override
public void surfaceDestroyed(@NonNull SurfaceHolder holder) {

}
});

LinearLayout shareTip = view.findViewById(R.id.share_tip);
recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
Expand Down Expand Up @@ -100,13 +123,16 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (!b) {
playPause.setBackgroundDrawable(getResources().getDrawable(R.drawable.ic_baseline_play_arrow_24));
player.pause();
surfaceView.setVisibility(View.GONE);
if (mainActivity.useTheme) {
if (pause != null)
playPause.setCompoundDrawables(pause, null, null, null);
}
} else {
playPause.setBackgroundDrawable(getResources().getDrawable(R.drawable.ic_baseline_pause_24));
player.play();
if (player.getVideoFormat() != null)
surfaceView.setVisibility(View.VISIBLE);
if (mainActivity.useTheme) {
if (pause != null)
playPause.setCompoundDrawables(play, null, null, null);
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/layout/media_player_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<SurfaceView
android:layout_width="match_parent"
android:id="@+id/video_player_dialog"
android:layout_height="200dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/tracks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
app:layout_constraintTop_toTopOf="parent"
android:orientation="vertical"
app:layout_constraintLeft_toLeftOf="parent">
<SurfaceView
android:layout_width="match_parent"
android:layout_height="300dp"
android:visibility="gone"
android:id="@+id/tracks_video"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down

0 comments on commit b505db9

Please sign in to comment.