Skip to content

Commit 7221b7a

Browse files
Kentros AlexandrosKentros Alexandros
authored andcommitted
Added more examples for Time
1 parent 7d7e845 commit 7221b7a

File tree

2 files changed

+52
-27
lines changed

2 files changed

+52
-27
lines changed

src/main/java/goxr3plus/javastreamplayer/application/Main.java

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package goxr3plus.javastreamplayer.application;
22
/**
3-
*
3+
*
44
*/
55

66
import java.io.File;
77
import java.util.Map;
88

9+
import goxr3plus.javastreamplayer.stream.Status;
910
import goxr3plus.javastreamplayer.stream.StreamPlayer;
1011
import goxr3plus.javastreamplayer.stream.StreamPlayerEvent;
1112
import goxr3plus.javastreamplayer.stream.StreamPlayerException;
@@ -17,7 +18,7 @@
1718
*/
1819
public class Main extends StreamPlayer implements StreamPlayerListener {
1920

20-
private final String audioAbsolutePath = "Logic - Ballin [Bass Boosted].mp3";
21+
private final String audioAbsolutePath = "Logic - Ballin [Bass Boosted].mp3";
2122

2223
/**
2324
* Constructor
@@ -45,47 +46,72 @@ public Main() {
4546

4647
}
4748

48-
/*
49-
* (non-Javadoc)
50-
*
51-
* @see streamplayer.StreamPlayerListener#opened(java.lang.Object,
52-
* java.util.Map)
53-
*/
5449
@Override
5550
public void opened(final Object dataSource, final Map<String, Object> properties) {
5651

5752
}
5853

59-
/*
60-
* (non-Javadoc)
61-
*
62-
* @see streamplayer.StreamPlayerListener#progress(int, long, byte[],
63-
* java.util.Map)
64-
*/
6554
@Override
6655
public void progress(final int nEncodedBytes, final long microsecondPosition, final byte[] pcmData,
67-
final Map<String, Object> properties) {
56+
final Map<String, Object> properties) {
6857

6958
System.out.println("Encoded Bytes : " + nEncodedBytes);
7059

7160
// Current time position in seconds:) by GOXR3PLUS STUDIO
72-
// This is not the more precise way ... in XR3Player i am using different
73-
// techniques .
61+
// This is not the more precise way ...
62+
// in XR3Player i am using different techniques .
63+
//https://github.com/goxr3plus/XR3Player
7464
// Just for demostration purposes :)
7565
// I will add more advanced techniques with milliseconds , microseconds , hours
7666
// and minutes soon
77-
System.out.println("Current time is : " + (int) (microsecondPosition / 1000000) + " seconds");
67+
68+
// .MP3 OR .WAV
69+
final String extension = "mp3"; //THE SAMPLE Audio i am using is .MP3 SO ... :)
70+
71+
long totalBytes = getTotalBytes();
72+
if ("mp3".equals(extension) || "wav".equals(extension)) {
73+
74+
// Calculate the progress until now
75+
double progress = (nEncodedBytes > 0 && totalBytes > 0)
76+
? (nEncodedBytes * 1.0f / totalBytes * 1.0f)
77+
: -1.0f;
78+
// System.out.println(progress*100+"%")
79+
80+
System.out.println("Seconds : " + (int) (microsecondPosition / 1000000) + " s " + "Progress: [ " + progress * 100 + " ] %");
81+
System.out.println();
82+
83+
// .WHATEVER MUSIC FILE*
84+
} else
85+
System.out.println("Current time is : " + (int) (microsecondPosition / 1000000) + " seconds");
86+
7887
}
7988

80-
/*
81-
* (non-Javadoc)
82-
*
83-
* @see streamplayer.StreamPlayerListener#statusUpdated(streamplayer.
84-
* StreamPlayerEvent)
85-
*/
8689
@Override
87-
public void statusUpdated(final StreamPlayerEvent event) {
88-
System.out.println(event.getPlayerStatus());
90+
public void statusUpdated(final StreamPlayerEvent streamPlayerEvent) {
91+
92+
// Player status
93+
final Status status = streamPlayerEvent.getPlayerStatus();
94+
System.out.println(streamPlayerEvent.getPlayerStatus());
95+
96+
//Examples
97+
98+
if (status == Status.OPENED) {
99+
100+
} else if (status == Status.OPENING) {
101+
102+
} else if (status == Status.RESUMED) {
103+
104+
} else if (status == Status.PLAYING) {
105+
106+
} else if (status == Status.STOPPED) {
107+
108+
} else if (status == Status.SEEKING) {
109+
110+
} else if (status == Status.SEEKED) {
111+
112+
}
113+
114+
//etc... SEE XR3PLAYER https://github.com/goxr3plus/XR3Player for advanced examples
89115
}
90116

91117
public static void main(final String[] args) {

src/main/java/goxr3plus/javastreamplayer/stream/StreamPlayer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public class StreamPlayer implements Callable<Void> {
6767

6868
// -------------------AUDIO---------------------
6969

70-
/** @SEE streamplayer.Status */
7170
private volatile Status status = Status.NOT_SPECIFIED;
7271

7372
/** The data source. */

0 commit comments

Comments
 (0)