I am trying to implement DRM in my application.
But I am facing a problem. canHandle()
always returns false.
And DrmManagerClient.getOriginalMimeType(Uri)
; always returns null for http links.
But for files in the storage, everything is working fine.
DrmManagerClient mDrmManager;
mDrmManager = new DrmManagerClient(this);
String testUri = myUrl;
String mimeType = getOriginalMimeType( testUri );
Below is the method to get mimetype but unfortunately canHandle() always return false.
// get MimeType
public String getOriginalMimeType(String uri){
String mime = null;
try {
if( mDrmManager.canHandle(Uri.parse(uri), null) ){
mime = mDrmManager.getOriginalMimeType(Uri.parse(uri));
}
} catch (Exception e) {
Log.w(TAG, e.toString());
}
return mime;
}
Am I missing something?
The obvious would have been that probably the url I am using is not good, but
I have tried different urls which work in another application but the outcome is the same.
I have set INTERNET permission in the manifest file too. I am running out of ideas what is the problem.
After digging into DrmManagerClient source code, I noticed that canHandle() is defined as follows:
/**
* Checks whether the given MIME type or URI can be handled.
*
* @param uri URI for the content to be handled.
* @param mimeType MIME type of the object to be handled
*
* @return True if the given MIME type or URI can be handled; false if they cannot be handled.
*/
public boolean canHandle(Uri uri, String mimeType) {
if ((null == uri || Uri.EMPTY == uri) && (null == mimeType || mimeType.equals(""))) {
throw new IllegalArgumentException("Uri or the mimetype should be non null");
}
return canHandle(convertUriToPath(uri), mimeType);
}
What canHandle(Uri uri , String mimeType)
is basically the same as canHandle( String path, mimeType )
because it is converting Uri to Path.
Does this mean that Http Urls wont work?
I have found that the problem lies in the urls.
I tested with these two links and everything is fine now.
Stream 1: http://commondatastorage.googleapis.com/wvmedia/sintel_main_720p_4br_tp.wvm
Stream 2: http://commondatastorage.googleapis.com/wvmedia/starz_main_720p_6br_tp.wvm
Hope it helps someone in the future.