3434import android .graphics .SurfaceTexture ;
3535import android .media .AudioManager ;
3636
37+ import java .io .File ;
3738import java .io .FileDescriptor ;
39+ import java .io .FileInputStream ;
3840import java .io .IOException ;
3941import java .net .InetSocketAddress ;
4042import java .util .Map ;
@@ -847,8 +849,10 @@ public void setDataSource(Context context, Uri uri, Map<String, String> headers)
847849 * As an alternative, the application could first open the file for reading,
848850 * and then use the file descriptor form {@link #setDataSource(FileDescriptor)}.
849851 */
850- public native void setDataSource (String path )
851- throws IOException , IllegalArgumentException , SecurityException , IllegalStateException ;
852+ public void setDataSource (String path )
853+ throws IOException , IllegalArgumentException , SecurityException , IllegalStateException {
854+ setDataSource (path , null , null );
855+ }
852856
853857 /**
854858 * Sets the data source (file-path or http/rtsp URL) to use.
@@ -875,7 +879,20 @@ public void setDataSource(String path, Map<String, String> headers)
875879 ++i ;
876880 }
877881 }
878- _setDataSource (path , keys , values );
882+ setDataSource (path , keys , values );
883+ }
884+
885+ private void setDataSource (String path , String [] keys , String [] values )
886+ throws IOException , IllegalArgumentException , SecurityException , IllegalStateException {
887+ File file = new File (path );
888+ if (file .exists ()) {
889+ FileInputStream is = new FileInputStream (file );
890+ FileDescriptor fd = is .getFD ();
891+ setDataSource (fd );
892+ is .close ();
893+ } else {
894+ _setDataSource (path , keys , values );
895+ }
879896 }
880897
881898 private native void _setDataSource (
0 commit comments