Fix failure from setDataSource(String path) when path is a local file

o the failure was because the mediaserver does not have read permission to sdcard
o related-to-bug: 6325960,6322913

Change-Id: I4feec01b8165c78563eee8aab69cb24df3244d03
This commit is contained in:
James Dong
2012-04-11 21:18:43 -07:00
parent 54ae14749b
commit e00b6f3a57
2 changed files with 20 additions and 11 deletions

View File

@ -34,7 +34,9 @@ import android.graphics.Bitmap;
import android.graphics.SurfaceTexture;
import android.media.AudioManager;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Map;
@ -847,8 +849,10 @@ public class MediaPlayer
* As an alternative, the application could first open the file for reading,
* and then use the file descriptor form {@link #setDataSource(FileDescriptor)}.
*/
public native void setDataSource(String path)
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException;
public void setDataSource(String path)
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
setDataSource(path, null, null);
}
/**
* Sets the data source (file-path or http/rtsp URL) to use.
@ -875,7 +879,20 @@ public class MediaPlayer
++i;
}
}
_setDataSource(path, keys, values);
setDataSource(path, keys, values);
}
private void setDataSource(String path, String[] keys, String[] values)
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
File file = new File(path);
if (file.exists()) {
FileInputStream is = new FileInputStream(file);
FileDescriptor fd = is.getFD();
setDataSource(fd);
is.close();
} else {
_setDataSource(path, keys, values);
}
}
private native void _setDataSource(