Skip to content

Commit f7d3bdf

Browse files
James DongAndroid (Google) Code Review
authored andcommitted
Merge "AddExternalSource(String path) needs to turn the path to fd if it is a file"
2 parents 420489c + c4c0284 commit f7d3bdf

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

media/java/android/media/MediaPlayer.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,18 +1619,22 @@ private boolean availableMimeTypeForExternalSource(String mimeType) {
16191619
// FIXME: define error codes and throws exceptions according to the error codes.
16201620
// (IllegalStateException, IOException).
16211621
public void addExternalSource(String path, String mimeType)
1622-
throws IllegalArgumentException {
1622+
throws IOException, IllegalArgumentException {
16231623
if (!availableMimeTypeForExternalSource(mimeType)) {
1624-
throw new IllegalArgumentException("Illegal mimeType for external source: " + mimeType);
1624+
final String msg = "Illegal mimeType for external source: " + mimeType;
1625+
throw new IllegalArgumentException(msg);
16251626
}
16261627

1627-
Parcel request = Parcel.obtain();
1628-
Parcel reply = Parcel.obtain();
1629-
request.writeInterfaceToken(IMEDIA_PLAYER);
1630-
request.writeInt(INVOKE_ID_ADD_EXTERNAL_SOURCE);
1631-
request.writeString(path);
1632-
request.writeString(mimeType);
1633-
invoke(request, reply);
1628+
File file = new File(path);
1629+
if (file.exists()) {
1630+
FileInputStream is = new FileInputStream(file);
1631+
FileDescriptor fd = is.getFD();
1632+
addExternalSource(fd, mimeType);
1633+
is.close();
1634+
} else {
1635+
// We do not support the case where the path is not a file.
1636+
throw new IOException(path);
1637+
}
16341638
}
16351639

16361640
/**
@@ -1671,8 +1675,6 @@ public void addExternalSource(Context context, Uri uri, String mimeType)
16711675
fd.close();
16721676
}
16731677
}
1674-
1675-
// TODO: try server side.
16761678
}
16771679

16781680
/* Do not change these values without updating their counterparts
@@ -1732,6 +1734,7 @@ public void addExternalSource(FileDescriptor fd, long offset, long length, Strin
17321734
if (!availableMimeTypeForExternalSource(mimeType)) {
17331735
throw new IllegalArgumentException("Illegal mimeType for external source: " + mimeType);
17341736
}
1737+
17351738
Parcel request = Parcel.obtain();
17361739
Parcel reply = Parcel.obtain();
17371740
request.writeInterfaceToken(IMEDIA_PLAYER);

0 commit comments

Comments
 (0)