uset setDataSource(FileDescriptor) interface

This commit is contained in:
Adrian Ulrich 2015-11-12 21:04:45 +01:00
parent cb6eb5c116
commit 939c59fe71

View File

@ -25,6 +25,7 @@ import android.media.MediaPlayer;
import android.media.audiofx.AudioEffect; import android.media.audiofx.AudioEffect;
import android.os.Build; import android.os.Build;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
public class VanillaMediaPlayer extends MediaPlayer { public class VanillaMediaPlayer extends MediaPlayer {
@ -65,9 +66,14 @@ public class VanillaMediaPlayer extends MediaPlayer {
/** /**
* Sets the data source to use * Sets the data source to use
*/ */
public void setDataSource(String dataSource) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException { public void setDataSource(String path) throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
mDataSource = dataSource; // The MediaPlayer function expects a file:// like string but also accepts *most* absolute unix paths (= paths with no colon)
super.setDataSource(mDataSource); // We could therefore encode the path into a full URI, but a much quicker way is to simply use
// setDataSource(FileDescriptor) as the framework code would end up calling this function anyways (MediaPlayer.java:1100 (6.0))
FileInputStream fis = new FileInputStream(path);
super.setDataSource(fis.getFD());
fis.close(); // this is OK according to the SDK documentation!
mDataSource = path;
} }
/** /**