Skip to content

Commit

Permalink
audio messages tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Sep 21, 2024
1 parent fa7c2b5 commit 87288e7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class FileUtils {
public static final int MAX_FILE_SIZE_BYTES = 100000; // ~100 kByte

public static void updateVisualizer(final Context context, final File file, final PlayerVisualizerSeekbar playerVisualizerSeekbar){
Log.e(" BYTES", "CALLED");
new AsyncTask<Void, Void, byte[]>() {
new AsyncTask<Void, Void, byte[]>()
{
@Override
protected byte[] doInBackground(Void... voids) {
return fileToBytes(file);
Expand All @@ -28,29 +28,35 @@ protected void onPostExecute(final byte[] bytes) {
super.onPostExecute(bytes);
((Activity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
public void run()
{
playerVisualizerSeekbar.setBytes(bytes);
playerVisualizerSeekbar.invalidate();
}
});
}
}.execute();
}
public static byte[] fileToBytes(File file) {

public static byte[] fileToBytes(File file)
{
if (file.length() > MAX_FILE_SIZE_BYTES)
{
return null;
}
int size = (int) file.length();
byte[] bytes = new byte[size];
try {
byte[] bytes = null;
try
{
int size = (int) file.length();
bytes = new byte[size];
BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
buf.read(bytes, 0, bytes.length);
buf.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
return bytes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public class PlayerVisualizerSeekbar extends androidx.appcompat.widget.AppCompat
/**
* Canvas painting for sample scale, filling played part of audio sample
*/
private Paint playedStatePainting = new Paint();
private final Paint playedStatePainting = new Paint();
/**
* Canvas painting for sample scale, filling not played part of audio sample
*/
private Paint notPlayedStatePainting = new Paint();
private final Paint notPlayedStatePainting = new Paint();

private int width;
private int height;
Expand Down Expand Up @@ -76,6 +76,7 @@ public void updateVisualizer(File file) {

FileUtils.updateVisualizer(getContext(), file, this);
}

public void setBytes(byte[] bytes){
this.bytes = bytes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void onCompletion(MediaPlayer mp) {
seekbarV.updateVisualizer(new File(path));
}
seekbarV.setOnSeekBarChangeListener(seekBarListener);
seekbarV.updateVisualizer(new File(path));
// seekbarV.updateVisualizer(new File(path));
}


Expand Down Expand Up @@ -634,10 +634,10 @@ public void run() {
imgPause.setOnClickListener(imgPauseClickListener);
imgShare.setOnClickListener(imgShareClickListener);
if (seekbarV.getVisibility() == VISIBLE){
seekbarV.updateVisualizer(new File(path));
Log.i("VoicePlayerView", "VoicePlayerView:refreshPlayer:updateVisualizer");
// seekbarV.updateVisualizer(new File(path));
seekbarV.setOnSeekBarChangeListener(seekBarListener);
seekbarV.updateVisualizer(new File(path));
Log.i("VoicePlayerView", "VoicePlayerView:refreshPlayer:updateVisualizer");
}
}
});
Expand Down

0 comments on commit 87288e7

Please sign in to comment.