Skip to content

Commit

Permalink
Basic features and functionality
Browse files Browse the repository at this point in the history
Signed-off-by: Ved Nig <[email protected]>
Signed-off-by: Your Name <[email protected]>
  • Loading branch information
vednig authored and Your Name committed Sep 23, 2023
1 parent acae158 commit f1d0d12
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 30 deletions.
22 changes: 11 additions & 11 deletions app/src/main/java/com/service/rare/recorder/CustomAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder> {

private String[] localDataSet;
private String[] localDataSet2;
private final String[] localDataSet;
private final String[] localDataSet2;

private String[] localDataSet3;
private final String[] localDataSet3;
public static Integer LastAdapterPos = -1;

public static ImageView prev_image;
Expand All @@ -32,27 +32,27 @@ public static class ViewHolder extends RecyclerView.ViewHolder {
private final TextView textView;
private final TextView textView2;
private final TextView title;
final ImageView play_image;

private final CardView cardview;
private final ImageView play_image;

public ViewHolder(View view) {
super(view);
// Define click listener for the ViewHolder's View

textView = (TextView) view.findViewById(R.id.textView);
textView2 = (TextView) view.findViewById(R.id.textView2);
title = (TextView) view.findViewById(R.id.title);
play_image = (ImageView) view.findViewById(R.id.imageView);
textView = view.findViewById(R.id.textView);
textView2 = view.findViewById(R.id.textView2);
title = view.findViewById(R.id.title);
play_image = view.findViewById(R.id.imageView);

play_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("TAG", "onClick: "+getAdapterPosition());

String filepath = MainActivity2.path.toString()+"/"+MainActivity2.files[getAdapterPosition()]+".mp3" ;
String filepath = MainActivity2.path +"/"+MainActivity2.files[getAdapterPosition()]+".mp3" ;
try {
boolean isPlaying=MainActivity2.playRecording(filepath,v,getAdapterPosition(),prev_image);
boolean isPlaying = MainActivity2.playRecording(filepath, v, getAdapterPosition(), prev_image, play_image);

if(isPlaying){
play_image.setImageResource(R.drawable.baseline_stop_24);
Expand All @@ -74,7 +74,7 @@ public void onClick(View v) {
}
});

cardview = (CardView) view.findViewById(R.id.cardView);
cardview = view.findViewById(R.id.cardView);
cardview.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Expand Down
56 changes: 37 additions & 19 deletions app/src/main/java/com/service/rare/recorder/MainActivity2.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.service.rare.recorder;

import static com.service.rare.recorder.CustomAdapter.LastAdapterPos;

import static java.lang.Integer.valueOf;

import android.content.Intent;
Expand All @@ -23,7 +22,6 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


import java.io.File;
import java.io.IOException;
import java.util.Date;
Expand Down Expand Up @@ -193,7 +191,8 @@ protected void onResume() {
Toast.makeText(this, "Resumed", Toast.LENGTH_SHORT).show();
super.onResume();
}
public static boolean playRecording(String filePath, View v, int adapterPosition, ImageView prev_image) throws IOException {

public static boolean playRecording(String filePath, View v, int adapterPosition, ImageView prev_image, ImageView play_image) throws IOException {
//----- ToDo: Convert to a switch/case scenario or faster processing----
// Create MediaPlayer Instance
if (!hasMPInstance) {
Expand All @@ -209,8 +208,14 @@ public static boolean playRecording(String filePath, View v, int adapterPosition
);
mediaPlayer.setDataSource(v.getContext(), myUri);
mediaPlayer.prepare();
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
play_image.setImageResource(R.drawable.baseline_play_arrow_24);
}
});
mediaPlayer.start();
hasMPInstance=true;

hasMPInstance = true;
return true;
} else {
if(mediaPlayer.isPlaying()) {
Expand Down Expand Up @@ -241,8 +246,14 @@ public static boolean playRecording(String filePath, View v, int adapterPosition
);
mediaPlayer.setDataSource(v.getContext(), myUri);
mediaPlayer.prepare();
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
play_image.setImageResource(R.drawable.baseline_play_arrow_24);
}
});
mediaPlayer.start();
hasMPInstance=true;

hasMPInstance = true;
return true;
}
}else {
Expand All @@ -254,23 +265,30 @@ public static boolean playRecording(String filePath, View v, int adapterPosition
else{
if(prev_image!=null){
prev_image.setImageResource(R.drawable.baseline_play_arrow_24);
Toast.makeText(v.getContext(), "NotNull ",Toast.LENGTH_SHORT).show();
// Toast.makeText(v.getContext(), "NotNull ",Toast.LENGTH_SHORT).show();
}
mediaPlayer.release();
// Toast.makeText(v.getContext(), "Situation 3 - "+ LastAdapterPos+"/"+adapterPosition,Toast.LENGTH_SHORT).show();
mediaPlayer = new MediaPlayer();
Uri myUri = Uri.parse(filePath); // initialize Uri here
mediaPlayer.setAudioAttributes(
new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.setUsage(AudioAttributes.USAGE_MEDIA)
.build()
);
mediaPlayer.setDataSource(v.getContext(), myUri);
mediaPlayer.prepare();
mediaPlayer.start();
hasMPInstance=true;
return true;}
mediaPlayer = new MediaPlayer();
Uri myUri = Uri.parse(filePath); // initialize Uri here
mediaPlayer.setAudioAttributes(
new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.setUsage(AudioAttributes.USAGE_MEDIA)
.build()
);
mediaPlayer.setDataSource(v.getContext(), myUri);
mediaPlayer.prepare();
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
play_image.setImageResource(R.drawable.baseline_play_arrow_24);
}
});
mediaPlayer.start();

hasMPInstance = true;
return true;
}

}

Expand Down

0 comments on commit f1d0d12

Please sign in to comment.