diff options
Diffstat (limited to 'src/github')
4 files changed, 47 insertions, 9 deletions
diff --git a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java index 942b0613..056c6e6f 100644 --- a/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java +++ b/src/github/daneren2005/dsub/fragments/NowPlayingFragment.java @@ -1249,18 +1249,18 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis onProgressChangedTask = new SilentBackgroundTask<Void>(context) {
DownloadService downloadService;
- boolean isJukeboxEnabled;
int millisPlayed;
Integer duration;
PlayerState playerState;
+ boolean isSeekable;
@Override
protected Void doInBackground() throws Throwable {
downloadService = getDownloadService();
- isJukeboxEnabled = downloadService.isRemoteEnabled();
millisPlayed = Math.max(0, downloadService.getPlayerPosition());
duration = downloadService.getPlayerDuration();
playerState = getDownloadService().getPlayerState();
+ isSeekable = downloadService.isSeekable();
return null;
}
@@ -1279,7 +1279,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis if(!seekInProgress) {
progressBar.setProgress(millisPlayed);
}
- progressBar.setEnabled((currentPlaying.isWorkDone() || isJukeboxEnabled) && playerState != PlayerState.PREPARING);
+ progressBar.setEnabled(isSeekable);
} else {
positionTextView.setText("0:00");
durationTextView.setText("-:--");
diff --git a/src/github/daneren2005/dsub/service/DLNAController.java b/src/github/daneren2005/dsub/service/DLNAController.java index 0a90c2d7..78f737ce 100644 --- a/src/github/daneren2005/dsub/service/DLNAController.java +++ b/src/github/daneren2005/dsub/service/DLNAController.java @@ -79,6 +79,7 @@ public class DLNAController extends RemoteController { int currentPosition = 0;
String currentPlayingURI;
boolean running = true;
+ boolean seekable = false;
public DLNAController(DownloadService downloadService, ControlPoint controlPoint, DLNADevice device) {
this.downloadService = downloadService;
@@ -174,6 +175,7 @@ public class DLNAController extends RemoteController { controlPoint.execute(new Play(getTransportService()) {
@Override
public void success(ActionInvocation invocation) {
+ lastUpdate.set(System.currentTimeMillis());
downloadService.setPlayerState(PlayerState.STARTED);
}
@@ -190,6 +192,9 @@ public class DLNAController extends RemoteController { controlPoint.execute(new Pause(getTransportService()) {
@Override
public void success(ActionInvocation invocation) {
+ int secondsSinceLastUpdate = (int) ((System.currentTimeMillis() - lastUpdate.get()) / 1000L);
+ currentPosition += secondsSinceLastUpdate;
+
downloadService.setPlayerState(PlayerState.PAUSED);
}
@@ -273,8 +278,17 @@ public class DLNAController extends RemoteController { @Override
public int getRemotePosition() {
- int secondsSinceLastUpdate = (int) ((System.currentTimeMillis() - lastUpdate.get()) / 1000L);
- return currentPosition + secondsSinceLastUpdate;
+ if(downloadService.getPlayerState() == PlayerState.STARTED) {
+ int secondsSinceLastUpdate = (int) ((System.currentTimeMillis() - lastUpdate.get()) / 1000L);
+ return currentPosition + secondsSinceLastUpdate;
+ } else {
+ return currentPosition;
+ }
+ }
+
+ @Override
+ public boolean isSeekable() {
+ return seekable;
}
private void startSong(final DownloadFile currentPlaying, final boolean autoStart, final int position) {
@@ -348,6 +362,8 @@ public class DLNAController extends RemoteController { downloadService.setPlayerState(PlayerState.PAUSED);
}
+ currentPosition = position;
+ lastUpdate.set(System.currentTimeMillis());
getUpdatedStatus();
}
@@ -397,6 +413,9 @@ public class DLNAController extends RemoteController { return;
}
+ long duration = positionInfo.getTrackDurationSeconds();
+ seekable = duration > 0;
+
lastUpdate.set(System.currentTimeMillis());
// Playback was stopped
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index f23b0995..6caf5c58 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -62,6 +62,7 @@ import java.util.List; import java.util.Timer; import java.util.TimerTask; +import android.annotation.TargetApi; import android.app.Service; import android.content.ComponentName; import android.content.Context; @@ -872,7 +873,7 @@ public class DownloadService extends Service { nextMediaPlayer = tmp; setCurrentPlaying(nextPlaying, true); setPlayerState(PlayerState.STARTED); - setupHandlers(currentPlaying, false); + setupHandlers(currentPlaying, false, start); setNextPlaying(); // Proxy should not be being used here since the next player was already setup to play @@ -1047,6 +1048,7 @@ public class DownloadService extends Service { } } + @TargetApi(Build.VERSION_CODES.JELLY_BEAN) public synchronized void reset() { if (bufferTask != null) { bufferTask.cancel(); @@ -1070,6 +1072,7 @@ public class DownloadService extends Service { } } + @TargetApi(Build.VERSION_CODES.JELLY_BEAN) public synchronized void resetNext() { try { if (nextMediaPlayer != null) { @@ -1303,6 +1306,16 @@ public class DownloadService extends Service { return mediaRouter.getSelector(); } + public boolean isSeekable() { + if(remoteState == LOCAL) { + return currentPlaying.isWorkDone() && playerState != PREPARING; + } else if(remoteController != null) { + return remoteController.isSeekable(); + } else { + return false; + } + } + public boolean isRemoteEnabled() { return remoteState != LOCAL; } @@ -1510,6 +1523,8 @@ public class DownloadService extends Service { synchronized (DownloadService.this) { if (position != 0) { + Util.sleepQuietly(10); + Log.i(TAG, "Restarting player from position " + position); mediaPlayer.seekTo(position); } @@ -1538,7 +1553,7 @@ public class DownloadService extends Service { } }); - setupHandlers(downloadFile, isPartial); + setupHandlers(downloadFile, isPartial, start); mediaPlayer.prepareAsync(); } catch (Exception x) { @@ -1546,6 +1561,7 @@ public class DownloadService extends Service { } } + @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private synchronized void setupNext(final DownloadFile downloadFile) { try { final File file = downloadFile.isCompleteFileAvailable() ? downloadFile.getCompleteFile() : downloadFile.getPartialFile(); @@ -1596,7 +1612,7 @@ public class DownloadService extends Service { } } - private void setupHandlers(final DownloadFile downloadFile, final boolean isPartial) { + private void setupHandlers(final DownloadFile downloadFile, final boolean isPartial, final boolean isPlaying) { final int duration = downloadFile.getSong().getDuration() == null ? 0 : downloadFile.getSong().getDuration() * 1000; mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { public boolean onError(MediaPlayer mediaPlayer, int what, int extra) { @@ -1607,7 +1623,7 @@ public class DownloadService extends Service { playNext(); } else { downloadFile.setPlaying(false); - doPlay(downloadFile, pos, true); + doPlay(downloadFile, pos, isPlaying); downloadFile.setPlaying(true); } return true; diff --git a/src/github/daneren2005/dsub/service/RemoteController.java b/src/github/daneren2005/dsub/service/RemoteController.java index 89d4f4fd..02deaf85 100644 --- a/src/github/daneren2005/dsub/service/RemoteController.java +++ b/src/github/daneren2005/dsub/service/RemoteController.java @@ -48,6 +48,9 @@ public abstract class RemoteController { public abstract void setVolume(int volume); public abstract void updateVolume(boolean up); public abstract double getVolume(); + public boolean isSeekable() { + return true; + } public abstract int getRemotePosition(); public int getRemoteDuration() { |