1

我正在尝试在我的应用程序中实现 DRM。
但我面临一个问题。canHandle()总是返回假。
DrmManagerClient.getOriginalMimeType(Uri); http 链接总是返回 null。
但是对于存储中的文件,一切正常。

DrmManagerClient mDrmManager;
mDrmManager = new DrmManagerClient(this);
String testUri = myUrl;
String mimeType = getOriginalMimeType( testUri );

下面是获取 mimetype 的方法,但不幸的是 canHandle() 总是返回 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;
}

我错过了什么吗?
显而易见的是,我使用的 url 可能不好,但我尝试了在另一个应用程序中工作的不同 url,但结果是相同的。
我也在清单文件中设置了 INTERNET 权限。我已经没有想法了,这是什么问题。
在深入研究 DrmManagerClient 源代码后,我注意到 canHandle() 定义如下:

/**
 * 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);
}

canHandle(Uri uri , String mimeType)基本相同,因为canHandle( String path, mimeType )它是将 Uri 转换为 Path。
这是否意味着 Http Urls 不起作用?

4

1 回答 1

0

我发现问题出在网址上。
我用这两个链接进行了测试,现在一切都很好。

流 1:http ://commondatastorage.googleapis.com/wvmedia/sintel_main_720p_4br_tp.wvm

流 2:http ://commondatastorage.googleapis.com/wvmedia/starz_main_720p_6br_tp.wvm

希望它对将来的人有所帮助。

于 2014-06-23T06:12:11.063 回答