文件管理器中打开录音文件修改为音乐播放器播放

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/FreelingJun/article/details/53307094

在文件系统中播放录音文件(.3gp或者.ogg)时,默认是用video player播放,如何修改使其可以选择音乐播放器播放?

解决方法如下:

1. vendor/mediatek/proprietary/packages/apps/FileManager/src/com/mediatek/filemanager/service/FileManagerService.java

恢复FileManagerService.java中被注释掉的函数及其函数体

public String update3gppMimetype(FileInfo fileInfo) {
        LogUtils.d(TAG, "update3gppMimetype...");
        String mimeType = FileInfo.MIMETYPE_3GPP_VIDEO;
        ContentResolver resolver = getContentResolver();
        if (resolver != null && fileInfo != null) {
           // fileInfo.setFileMimeType(FileInfo.MIMETYPE_3GPP_VIDEO);
            final Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            final String[] projection = new String[] { MediaStore.MediaColumns.MIME_TYPE };
            final String selection = MediaStore.MediaColumns.DATA + "=?";
            final String[] selectionArgs = new String[] { fileInfo
                    .getFileAbsolutePath() };
            Cursor cursor = null;
            try {
                cursor = resolver.query(uri, projection, selection,
                        selectionArgs, null);
                LogUtils.d(TAG, "update3gppMimetype,file:" + fileInfo.getFileAbsolutePath());
                if (cursor != null && cursor.moveToFirst()) {
                     mimeType = cursor.getString(cursor
                            .getColumnIndex(MediaStore.MediaColumns.MIME_TYPE));
                    LogUtils.d(TAG, "update3gppMimetype mimeType: " + mimeType);
                } else {
                    mimeType = fileInfo.getFileOriginMimeType();
                    LogUtils.d(TAG, "update3gppMimetype, not find from media,origin mimeType: " + mimeType);
                    if (mimeType == null) {
                        mimeType = FileInfo.MIMETYPE_3GPP_VIDEO;
                    }
                }
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }
        }

        return mimeType;
    }

2.vendor/mediatek/proprietary/packages/apps/FileManager/src/com/mediatek/filemanager/FileInfo.java

恢复其中的部分代码:

1.恢复被注释掉的代码///M:@#3gp#@{the follow code is to handle the 3gp file.not do special handle now
  private static HashMap<String, String> sMimeType3GPPMap = new HashMap<String, String>();
    ///M:@{the top code is to handle the 3gp file.not do special handle now

2.恢复被注释掉的代码
public String getFileMimeType(FileManagerService service) {
        LogUtils.d(TAG, "getFileMimeType,service.");
        String mimeType = null;

        if (!isDirectory()) {
            if (!isDrmFile()) {
                mimeType = getMimeType(mFile);
                LogUtils.d(TAG, "getFileMimeType, mimetype is : " + mimeType);
            } else {
                mimeType = DrmManager.getInstance().getOriginalMimeType(mAbsolutePath);
                LogUtils.d(TAG, "getFileMimeType, is drm file,mimetype is: " + mimeType);
            }

          ///M:@#3gp#@{the follow code is to handle the 3gp file.not do special handle now
            if (mimeType.equalsIgnoreCase(FileInfo.MIMETYPE_3GPP_UNKONW)) {
                mimeType = service.update3gppMimetype(this);
            }

            if (mimeType.equalsIgnoreCase(FileInfo.MIMETYPE_3GPP_AUDIO)
                    || mimeType.equalsIgnoreCase(FileInfo.MIMETYPE_3GPP_VIDEO)
                    || mimeType.equalsIgnoreCase(FileInfo.MIMETYPE_3GPP2_VIDEO)) {
                String name = null;
                int sepIndex = mName.lastIndexOf("(");
                if (sepIndex > 0) {
                    name = mName.substring(0, sepIndex);
                } else {
                    name = mName.substring(0, mName.indexOf("."));
                }
                LogUtils.d(TAG, "getFileMimeType ,record the mimetype: " + mimeType + ",name = "
                        + name + ",mName = " + mName);

                sMimeType3GPPMap.put(name, mimeType);
            }
            ///@the top code is to handle the 3gp file.not do special handle now}
        }

        return mimeType;
    }

3.恢复被注释掉的代码
private String getMimeType(File file) {
        String fileName = getFileName();
        String extension = FileUtils.getFileExtension(fileName);
        LogUtils.d(TAG, "getMimeType fileName=" + fileName + ",extension = " + extension);

        if (extension == null) {
            return FileInfo.MIMETYPE_EXTENSION_NULL;
        }

        String mimeType = MediaFile.getMimeTypeForFile(fileName);
        LogUtils.d(TAG, "getMimeType mimeType =" + mimeType);
        if (mimeType == null) {
            return FileInfo.MIMETYPE_EXTENSION_UNKONW;
        }
      ///M:#3gp#@{the follow code is to handle the 3gp file.not do special handle now
        // sp ecial solution for checking 3gpp original mimetype
        // 3gpp extension could be video/3gpp or audio/3gpp
        if (mimeType.equalsIgnoreCase(FileInfo.MIMETYPE_3GPP_VIDEO)
                || mimeType.equalsIgnoreCase(FileInfo.MIMETYPE_3GPP2_VIDEO)) {
            LogUtils.d(TAG, "getMimeType, a 3gpp or 3g2 file,mimeType=" + mimeType);
            return FileInfo.MIMETYPE_3GPP_UNKONW;
        }
        ///M:@{the top code is to handle the 3gp file.not do special handle now
        return mimeType;
    }

4.全部恢复
///M:@#3gp#{the follow code is to handle the 3gp file.not do special handle now
    public String getFileOriginMimeType() {
        String key = null;
        LogUtils.d(TAG, "getFileOriginMimeType, mName =" + mName);
        int sepIndex = mName.lastIndexOf("(");
        if (sepIndex > 0) {
            key = mName.substring(0, sepIndex);
        } else {
            key = mName.substring(0, mName.indexOf("."));
        }
        LogUtils.d(TAG, "getFileOriginMimeType,key is:" + key);
        String orginalMimeType = sMimeType3GPPMap.get(key);
        LogUtils.d(TAG, "getFileOriginMimeType, OrginalMimeType=" + orginalMimeType);
        if (orginalMimeType != null) {
            sMimeType3GPPMap.remove(key);
        }
        return orginalMimeType;

    }
    ///M:@{the top code is to handle the 3gp file.not do special handle now

修改完这两支文件后可单编验证,希望对大家有所帮助。


阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页