Skip to content

Commit b527731

Browse files
Kentros AlexandrosKentros Alexandros
authored andcommitted
Implemented seekTo(x seconds)
1 parent 9a0617f commit b527731

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

src/main/java/com/goxr3plus/streamplayer/application/Main.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ public Main() {
4040

4141
//Seek
4242
// seek(500000L);
43-
seekTo(243);
43+
seekTo(-5);
4444

4545
// Play it
4646
play();
4747
//pause();
4848

4949

5050

51-
} catch (final StreamPlayerException ex) {
51+
} catch (final Exception ex) {
5252
ex.printStackTrace();
5353
}
5454

@@ -82,16 +82,17 @@ public void progress(final int nEncodedBytes, final long microsecondPosition, fi
8282
double progress = (nEncodedBytes > 0 && totalBytes > 0)
8383
? (nEncodedBytes * 1.0f / totalBytes * 1.0f)
8484
: -1.0f;
85-
// System.out.println(progress*100+"%")
85+
// System.out.println(progress*100+"%");
86+
87+
System.out.println("Seconds : " + (int) (microsecondPosition / 1000000) + " s " + "Progress: [ " + progress * 100 + " ] %");
8688

87-
//System.out.println("Seconds : " + (int) (microsecondPosition / 1000000) + " s " + "Progress: [ " + progress * 100 + " ] %");
88-
//System.out.println();
8989

9090
// .WHATEVER MUSIC FILE*
9191
} else {
9292
//System.out.println("Current time is : " + (int) (microsecondPosition / 1000000) + " seconds");
9393
}
9494

95+
9596
}
9697

9798
@Override

src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -765,24 +765,21 @@ else if (previousStatus == Status.PAUSED) {
765765
*
766766
* @param seconds Seconds to Skip
767767
*/
768-
public void seekTo(int seconds) throws StreamPlayerException {
769-
try {
770-
int durationInSeconds = this.getDurationInSeconds();
768+
public void seekTo(int seconds) throws Exception {
769+
int durationInSeconds = this.getDurationInSeconds();
771770

772-
if (seconds < 0 || seconds >= durationInSeconds) {
773-
throw new StreamPlayerException(PlayerException.SKIP_NOT_SUPPORTED);
774-
}
771+
if (seconds < 0) {
772+
throw new Exception("Trying to skip negative seconds ");
773+
} else if (seconds >= durationInSeconds) {
774+
throw new Exception("Trying to skip with seconds {" + seconds + "} > maximum {" + durationInSeconds + "}");
775+
}
775776

776-
//Calculate Bytes
777-
double percentage = (seconds * 100) / durationInSeconds;
778-
long totaBytes = getTotalBytes();
779-
long seekBytes = (long) (totaBytes / (0.9936346345345345));
780-
boolean b = seekBytes > totaBytes;
777+
//Calculate Bytes
778+
long totalBytes = getTotalBytes();
779+
double percentage = (seconds * 100) / durationInSeconds;
780+
long seekBytes = (long) (totalBytes * (percentage / 100));
781781

782-
seek(this.getEncodedStreamPosition() + seekBytes);
783-
} catch (Exception ex) {
784-
ex.printStackTrace();
785-
}
782+
seek(seekBytes);
786783
}
787784

788785
// /**

0 commit comments

Comments
 (0)