File tree Expand file tree Collapse file tree
core/src/main/java/xyz/gianlu/librespot/player Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -393,9 +393,13 @@ private void loadTrack(boolean play) {
393393
394394 private void handlePlay () {
395395 if (state .isStatus (Spirc .PlayStatus .kPlayStatusPause )) {
396- if (trackHandler != null ) trackHandler .sendPlay ();
397396 state .setStatus (Spirc .PlayStatus .kPlayStatusPlay );
398- state .setPositionMeasuredAt (TimeProvider .currentTimeMillis ());
397+ if (trackHandler != null ) {
398+ trackHandler .sendPlay ();
399+ state .setPositionMs (trackHandler .getPosition ());
400+ state .setPositionMeasuredAt (TimeProvider .currentTimeMillis ());
401+ }
402+
399403 stateUpdated ();
400404 }
401405 }
Original file line number Diff line number Diff line change 1515import javax .sound .sampled .*;
1616import java .io .IOException ;
1717import java .io .InputStream ;
18+ import java .util .concurrent .TimeUnit ;
1819
1920/**
2021 * @author Gianlu
@@ -26,7 +27,7 @@ public class PlayerRunner implements Runnable {
2627 private static final int BUFFER_SIZE = 2048 ;
2728 private static final int CONVERTED_BUFFER_SIZE = BUFFER_SIZE * 2 ;
2829 private static final Logger LOGGER = Logger .getLogger (PlayerRunner .class );
29- private static final long TRACK_PRELOAD_THRESHOLD = 10 ; // sec
30+ private static final long TRACK_PRELOAD_THRESHOLD = TimeUnit . SECONDS . toMillis ( 10 );
3031 private final SyncState joggSyncState = new SyncState ();
3132 private final InputStream audioIn ;
3233 private final Listener listener ;
@@ -250,14 +251,14 @@ private void decodeCurrentPacket(@NotNull SourceDataLine line) {
250251 }
251252
252253 private void checkPreload () {
253- if (preloadEnabled && !calledPreload && !stopped && ( duration / 1000 ) - time () <= TRACK_PRELOAD_THRESHOLD ) {
254+ if (preloadEnabled && !calledPreload && !stopped && duration - time () <= TRACK_PRELOAD_THRESHOLD ) {
254255 calledPreload = true ;
255256 listener .preloadNextTrack ();
256257 }
257258 }
258259
259260 public int time () {
260- return (int ) (pcm_offset / jorbisInfo .rate );
261+ return (int ) ((( float ) pcm_offset / ( float ) jorbisInfo .rate ) * 1000f );
261262 }
262263
263264 private void cleanup () {
Original file line number Diff line number Diff line change @@ -139,6 +139,10 @@ boolean isTrack(@NotNull TrackId id) {
139139 return track != null && track .hasGid () && Arrays .equals (id .getGid (), track .getGid ().toByteArray ());
140140 }
141141
142+ public int getPosition () {
143+ return playerRunner == null ? 0 : playerRunner .time ();
144+ }
145+
142146 public enum Command {
143147 Load , Play , Pause ,
144148 Stop , Seek , Terminate
You can’t perform that action at this time.
0 commit comments