aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-09-14 17:32:33 -0700
committerScott Jackson <daneren2005@gmail.com>2014-09-14 17:32:33 -0700
commit3895e6a34561f9384d09836551039e57ac5ed9b9 (patch)
tree442a22d2280d4fa200c8e56eea762b4936d0dbe8 /src
parent46de452c50617c2bde3b648977b22a9f363a5b85 (diff)
parent73fc8c68dc2729a9e1ee9b6b1d5a31efa8eca444 (diff)
downloaddsub-3895e6a34561f9384d09836551039e57ac5ed9b9.tar.gz
dsub-3895e6a34561f9384d09836551039e57ac5ed9b9.tar.bz2
dsub-3895e6a34561f9384d09836551039e57ac5ed9b9.zip
Merge branch 'PlayerPosition'
Conflicts: res/xml/changelog.xml
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/service/DownloadService.java27
-rw-r--r--src/github/daneren2005/dsub/service/ssl/SSLSocketFactory.java27
2 files changed, 46 insertions, 8 deletions
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java
index 676d263c..7ff1d5eb 100644
--- a/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/src/github/daneren2005/dsub/service/DownloadService.java
@@ -144,6 +144,10 @@ public class DownloadService extends Service {
private boolean autoPlayStart = false;
private MediaRouteManager mediaRouter;
+
+ // Variables to manage getCurrentPosition sometimes starting from an arbitrary non-zero number
+ private long subtractNextPosition = 0;
+ private int subtractPosition = 0;
@Override
public void onCreate() {
@@ -803,6 +807,7 @@ public class DownloadService extends Service {
Util.broadcastPlaybackStatusChange(this, currentPlaying.getSong(), PlayerState.PREPARED);
// Swap the media players since nextMediaPlayer is ready to play
+ subtractPosition = 0;
if(start) {
nextMediaPlayer.start();
} else if(!nextMediaPlayer.isPlaying()) {
@@ -810,6 +815,9 @@ public class DownloadService extends Service {
nextMediaPlayer.start();
} else {
Log.i(TAG, "nextMediaPlayer already playing");
+
+ // Next time the cachedPosition is updated, use that as position 0
+ subtractNextPosition = System.currentTimeMillis();
}
MediaPlayer tmp = mediaPlayer;
mediaPlayer = nextMediaPlayer;
@@ -850,6 +858,7 @@ public class DownloadService extends Service {
} else {
mediaPlayer.seekTo(position);
cachedPosition = position;
+ subtractPosition = 0;
}
} catch (Exception x) {
handleError(x);
@@ -980,6 +989,7 @@ public class DownloadService extends Service {
mediaPlayer.setOnErrorListener(null);
mediaPlayer.setOnCompletionListener(null);
mediaPlayer.reset();
+ subtractPosition = 0;
} catch (Exception x) {
handleError(x);
}
@@ -1012,7 +1022,7 @@ public class DownloadService extends Service {
if (remoteState != RemoteControlState.LOCAL) {
return remoteController.getRemotePosition() * 1000;
} else {
- return cachedPosition;
+ return Math.max(0, cachedPosition - subtractPosition);
}
} catch (Exception x) {
handleError(x);
@@ -1109,6 +1119,14 @@ public class DownloadService extends Service {
try {
if(mediaPlayer != null && playerState == STARTED) {
cachedPosition = mediaPlayer.getCurrentPosition();
+ if(subtractNextPosition > 0) {
+ // Subtraction amount is current position - how long ago onCompletionListener was called
+ subtractPosition = cachedPosition - (int) (System.currentTimeMillis() - subtractNextPosition);
+ if(subtractPosition < 0) {
+ subtractPosition = 0;
+ }
+ subtractNextPosition = 0;
+ }
}
Thread.sleep(1000L);
}
@@ -1332,6 +1350,7 @@ public class DownloadService extends Service {
boolean isPartial = file.equals(downloadFile.getPartialFile());
downloadFile.updateModificationDate();
+ subtractPosition = 0;
mediaPlayer.setOnCompletionListener(null);
mediaPlayer.reset();
setPlayerState(IDLE);
@@ -1456,7 +1475,7 @@ public class DownloadService extends Service {
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
public boolean onError(MediaPlayer mediaPlayer, int what, int extra) {
Log.w(TAG, "Error on playing file " + "(" + what + ", " + extra + "): " + downloadFile);
- int pos = cachedPosition;
+ int pos = getPlayerPosition();
reset();
if (!isPartial || (downloadFile.isWorkDone() && (Math.abs(duration - pos) < 10000))) {
playNext();
@@ -1479,7 +1498,7 @@ public class DownloadService extends Service {
setPlayerStateCompleted();
- int pos = cachedPosition;
+ int pos = getPlayerPosition();
Log.i(TAG, "Ending position " + pos + " of " + duration);
if (!isPartial || (downloadFile.isWorkDone() && (Math.abs(duration - pos) < 10000)) || nextSetup) {
playNext();
@@ -1770,7 +1789,7 @@ public class DownloadService extends Service {
private boolean isPastCutoff() {
int duration = getPlayerDuration();
int cutoffPoint = (int) (duration * DELETE_CUTOFF);
- return duration > 0 && cachedPosition > cutoffPoint;
+ return duration > 0 && getPlayerPosition() > cutoffPoint;
}
private void clearCurrentBookmark() {
diff --git a/src/github/daneren2005/dsub/service/ssl/SSLSocketFactory.java b/src/github/daneren2005/dsub/service/ssl/SSLSocketFactory.java
index 2ffed048..2f11730a 100644
--- a/src/github/daneren2005/dsub/service/ssl/SSLSocketFactory.java
+++ b/src/github/daneren2005/dsub/service/ssl/SSLSocketFactory.java
@@ -27,6 +27,8 @@
package github.daneren2005.dsub.service.ssl;
+import android.util.Log;
+
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.scheme.HostNameResolver;
import org.apache.http.conn.scheme.LayeredSocketFactory;
@@ -140,7 +142,7 @@ import java.security.UnrecoverableKeyException;
* @since 4.0
*/
public class SSLSocketFactory implements LayeredSocketFactory {
-
+ private static final String TAG = SSLSocketFactory.class.getSimpleName();
public static final String TLS = "TLS";
public static final String SSL = "SSL";
public static final String SSLV2 = "SSLv2";
@@ -341,13 +343,17 @@ public class SSLSocketFactory implements LayeredSocketFactory {
@SuppressWarnings("cast")
public Socket createSocket(final HttpParams params) throws IOException {
// the cast makes sure that the factory is working as expected
- return (SSLSocket) this.socketfactory.createSocket();
+ SSLSocket sslsocket = (SSLSocket) this.socketfactory.createSocket();
+ sslsocket.setEnabledProtocols(sslsocket.getSupportedProtocols());
+ return sslsocket;
}
@SuppressWarnings("cast")
public Socket createSocket() throws IOException {
// the cast makes sure that the factory is working as expected
- return (SSLSocket) this.socketfactory.createSocket();
+ SSLSocket sslSocket = (SSLSocket) this.socketfactory.createSocket();
+ sslSocket.setEnabledProtocols(sslSocket.getSupportedProtocols());
+ return sslSocket;
}
/**
@@ -370,6 +376,7 @@ public class SSLSocketFactory implements LayeredSocketFactory {
sslsock.bind(localAddress);
}
+ setHostName(sslsock, remoteAddress.getHostName());
int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
int soTimeout = HttpConnectionParams.getSoTimeout(params);
@@ -437,6 +444,7 @@ public class SSLSocketFactory implements LayeredSocketFactory {
port,
autoClose
);
+ sslSocket.setEnabledProtocols(sslSocket.getSupportedProtocols());
if (this.hostnameVerifier != null) {
this.hostnameVerifier.verify(host, sslSocket);
}
@@ -491,7 +499,18 @@ public class SSLSocketFactory implements LayeredSocketFactory {
final Socket socket,
final String host, int port,
boolean autoClose) throws IOException, UnknownHostException {
- return createLayeredSocket(socket, host, port, autoClose);
+ SSLSocket sslSocket = (SSLSocket) this.socketfactory.createSocket(socket, host, port, autoClose);
+ sslSocket.setEnabledProtocols(sslSocket.getSupportedProtocols());
+ setHostName(sslSocket, host);
+ return sslSocket;
}
+ private void setHostName(SSLSocket sslsock, String hostname){
+ try {
+ java.lang.reflect.Method setHostnameMethod = sslsock.getClass().getMethod("setHostname", String.class);
+ setHostnameMethod.invoke(sslsock, hostname);
+ } catch (Exception e) {
+ Log.w(TAG, "SNI not useable", e);
+ }
+ }
}