aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-08-21 17:07:46 -0700
committerScott Jackson <daneren2005@gmail.com>2014-08-21 17:07:46 -0700
commit40f96d604812d3d2d1a0771933564d17e145a168 (patch)
treea7091803906bddecbfb392f49afd30a4855d78f4 /src
parentb9959f41efe45548757d0a7f1b1c9eb4ec9f9e92 (diff)
downloaddsub-40f96d604812d3d2d1a0771933564d17e145a168.tar.gz
dsub-40f96d604812d3d2d1a0771933564d17e145a168.tar.bz2
dsub-40f96d604812d3d2d1a0771933564d17e145a168.zip
Convert MediaPlayer over to use file descriptors instead of string paths
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/service/DownloadService.java31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java
index b311df6b..01d4aff0 100644
--- a/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/src/github/daneren2005/dsub/service/DownloadService.java
@@ -52,6 +52,7 @@ import github.daneren2005.dsub.util.compat.RemoteControlClientHelper;
import github.daneren2005.serverproxy.BufferProxy;
import java.io.File;
+import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -1360,20 +1361,29 @@ public class DownloadService extends Service {
} catch(Throwable e) {
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}
- String dataSource = file.getPath();
if(isPartial) {
if (proxy == null) {
proxy = new BufferProxy(this);
proxy.start();
}
proxy.setBufferFile(downloadFile);
- dataSource = proxy.getPrivateAddress(dataSource);
+ String dataSource = proxy.getPrivateAddress(dataSource);
Log.i(TAG, "Data Source: " + dataSource);
- } else if(proxy != null) {
- proxy.stop();
- proxy = null;
+ mediaPlayer.setDataSource(dataSource);
+ } else {
+ if(proxy != null) {
+ proxy.stop();
+ proxy = null;
+ }
+
+ RandomAccessFile accessFile;
+ try {
+ accessFile = new RandomAccessFile(file, "r");
+ mediaPlayer.setDataSource(accessFile.getFD());
+ } finally {
+ Util.close(accessFile);
+ }
}
- mediaPlayer.setDataSource(dataSource);
setPlayerState(PREPARING);
mediaPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
@@ -1440,7 +1450,14 @@ public class DownloadService extends Service {
} catch(Throwable e) {
nextMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}
- nextMediaPlayer.setDataSource(file.getPath());
+
+ RandomAccessFile accessFile;
+ try {
+ accessFile = new RandomAccessFile(file, "r");
+ nextMediaPlayer.setDataSource(accessFile.getFD());
+ } finally {
+ Util.close(accessFile);
+ }
setNextPlayerState(PREPARING);
nextMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {