first commit

This commit is contained in:
2024-11-28 13:06:18 +07:00
commit 2b1fe05f49
285 changed files with 24966 additions and 0 deletions

View File

@@ -0,0 +1,234 @@
package jbass;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.keywords.DateTime;
@BA.ShortName("MessageInformation")
public class AudioFileInformation {
private String filename;
private long size;
private double lengthseconds;
private boolean valid;
private boolean found;
private boolean playing = false;
private long startplayingtick = 0;
private final long KB_threshold = 1024;
private final long MB_threshold = 1024 * 1024;
private final long GB_threshold = 1024 * 1024 * 1024;
/**
* Check if currently being played
* @return true if playing
*/
public boolean getIsPlaying() {
return playing;
}
/**
* Set playing status
* @param value : true if playing
*/
public void setIsPlaying(boolean value) {
playing = value;
if (playing) {
startplayingtick = DateTime.getNow();
} else {
startplayingtick = -1;
}
}
/**
* Get Playback duration since IsPlaying is set true
* @return seconds of playback
*/
public int getPlaybackDuration() {
if (startplayingtick==-1) {
return -1;
} else {
return (int)((DateTime.getNow() - startplayingtick)/DateTime.TicksPerSecond);
}
}
/**
* Get Playback duration since IsPlaying is set true
* @return duration of playback in String
*/
public String getPlaybackDurationInString() {
int xx = getPlaybackDuration();
if (xx<0) {
return "N/A";
} else if (xx<60) {
return xx+" sec";
} else if (xx<3600) {
int mm = xx / 60;
int ss = xx - (mm*60);
return mm+"min "+ss+"sec";
} else {
int hh = xx / 3600;
xx = xx - (hh*3600);
int mm = xx / 60;
int ss = xx - (mm*60);
return hh+"h "+mm+"m "+ss+"s";
}
}
/**
* Get File size in bytes
* @return file size in bytes
*/
public long getSizeInBytes() {
return size;
}
/**
* Set File Size in bytes
* @param value : file size in bytes
*/
public void setSizeInBytes(long value) {
size = value;
}
/**
* Get File Size in readable string
* @return file size in readable string
*/
public String getSizeinString() {
if (valid) {
if (size<KB_threshold) {
return size+" B";
} else if (size<MB_threshold) {
double vv = (double)size / KB_threshold;
vv = Math.round(vv * 10.0) / 10.0; // 1 desimal
return vv+" KB";
} else if (size<GB_threshold) {
double vv = (double)size / MB_threshold;
vv = Math.round(vv*10.0)/ 10.0; // 1 desimal
return vv+" MB";
} else {
double vv = (double)size/ GB_threshold;
vv = Math.round(vv*10.0) / 10.0; // 1 desimal
return vv+" GB";
}
} else return "N/A";
}
/**
* Get File length in seconds
* @return audio file duration in seconds
*/
public double getLengthInSeconds() {
return lengthseconds;
}
/**
* Set File length in seconds
* @param value : file duration in seconds
*/
public void setLengthInSeconds(double value) {
lengthseconds = value;
}
/**
* Get File length in seconds in readable string
* @return audio file duration in readable string
*/
public String getLengthinString() {
if (valid) {
int sec = (int)lengthseconds;
if (sec < 60) {
return sec+" sec";
} else if (sec < 3600) {
int mm = (int)sec / 60;
int ss = (int)sec - (mm*60);
return mm+" min "+ss+" sec";
} else {
int hh = sec / 3600;
sec = sec - (hh*3600);
int mm = sec / 60;
int ss = sec - (mm*60);
return hh+"h "+mm+"m "+ss+"s";
}
} else return "N/A";
}
/**
* Get Filepath assigned
* @return filename or N/A if not assigned
*/
public String getFilePath() {
if (valid) {
return filename;
} else return "N/A";
}
/**
* Set Filepath
* @param value : filepath assigned
*/
public void setFilePath(String value) {
filename = value;
}
/**
* Check if this file is a valid audio file and can be played
* @return true if valid audio file
*/
public boolean getIsValid() {
return valid;
}
/**
* Set audio file validity
* @param value : true if valid
*/
public void setIsValid(boolean value) {
valid = value;
}
/**
* Check if this file path is found
* @return true if found
*/
public boolean getIsFound() {
return found;
}
/**
* Set audio file found
* @param value
*/
public void setIsFound(boolean value) {
found = value;
}
/**
* Return summary in string
* @return PATH:[filepath or N/A];VALID:[YES or NO];SIZE:[size in bytes];LENGTH:[length in seconds]
*/
public String toString() {
StringBuilder str = new StringBuilder();
str.append("PATH:").append((filename.isEmpty())?"N/A":filename).append(";");
str.append("VALID:").append((valid) ? "YES":"NO").append(";");
str.append("SIZE:").append(getSizeinString()).append(";");
str.append("LENGTH:").append(getLengthinString());
return str.toString();
}
}