|
1 | 1 | package goxr3plus.javastreamplayer.application;
|
2 | 2 | /**
|
3 |
| - * |
| 3 | + * |
4 | 4 | */
|
5 | 5 |
|
6 | 6 | import java.io.File;
|
7 | 7 | import java.util.Map;
|
8 | 8 |
|
| 9 | +import goxr3plus.javastreamplayer.stream.Status; |
9 | 10 | import goxr3plus.javastreamplayer.stream.StreamPlayer;
|
10 | 11 | import goxr3plus.javastreamplayer.stream.StreamPlayerEvent;
|
11 | 12 | import goxr3plus.javastreamplayer.stream.StreamPlayerException;
|
|
17 | 18 | */
|
18 | 19 | public class Main extends StreamPlayer implements StreamPlayerListener {
|
19 | 20 |
|
20 |
| - private final String audioAbsolutePath = "Logic - Ballin [Bass Boosted].mp3"; |
| 21 | + private final String audioAbsolutePath = "Logic - Ballin [Bass Boosted].mp3"; |
21 | 22 |
|
22 | 23 | /**
|
23 | 24 | * Constructor
|
@@ -45,47 +46,72 @@ public Main() {
|
45 | 46 |
|
46 | 47 | }
|
47 | 48 |
|
48 |
| - /* |
49 |
| - * (non-Javadoc) |
50 |
| - * |
51 |
| - * @see streamplayer.StreamPlayerListener#opened(java.lang.Object, |
52 |
| - * java.util.Map) |
53 |
| - */ |
54 | 49 | @Override
|
55 | 50 | public void opened(final Object dataSource, final Map<String, Object> properties) {
|
56 | 51 |
|
57 | 52 | }
|
58 | 53 |
|
59 |
| - /* |
60 |
| - * (non-Javadoc) |
61 |
| - * |
62 |
| - * @see streamplayer.StreamPlayerListener#progress(int, long, byte[], |
63 |
| - * java.util.Map) |
64 |
| - */ |
65 | 54 | @Override
|
66 | 55 | public void progress(final int nEncodedBytes, final long microsecondPosition, final byte[] pcmData,
|
67 |
| - final Map<String, Object> properties) { |
| 56 | + final Map<String, Object> properties) { |
68 | 57 |
|
69 | 58 | System.out.println("Encoded Bytes : " + nEncodedBytes);
|
70 | 59 |
|
71 | 60 | // 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 |
74 | 64 | // Just for demostration purposes :)
|
75 | 65 | // I will add more advanced techniques with milliseconds , microseconds , hours
|
76 | 66 | // 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 | + |
78 | 87 | }
|
79 | 88 |
|
80 |
| - /* |
81 |
| - * (non-Javadoc) |
82 |
| - * |
83 |
| - * @see streamplayer.StreamPlayerListener#statusUpdated(streamplayer. |
84 |
| - * StreamPlayerEvent) |
85 |
| - */ |
86 | 89 | @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 |
89 | 115 | }
|
90 | 116 |
|
91 | 117 | public static void main(final String[] args) {
|
|
0 commit comments