public void initModelFromFileUri(Uri uri) { String path = uri.getPath(); mSrc = path.substring(path.lastIndexOf('/') + 1); Log.i(TAG, "AudioModel mSrc: " + mSrc); if (mSrc.startsWith(".") && mSrc.length() > 1) { mSrc = mSrc.substring(1); } // Some MMSCs appear to have problems with filenames // containing a space. So just replace them with // underscores in the name, which is typically not // visible to the user anyway. mSrc = mSrc.replace(' ', '_'); // mUri = uri; MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); String extension = MimeTypeMap.getFileExtensionFromUrl(path).toLowerCase(); if (TextUtils.isEmpty(extension)) { // getMimeTypeFromExtension() doesn't handle spaces in filenames nor can it handle // urlEncoded strings. Let's try one last time at finding the extension. int dotPos = path.lastIndexOf('.'); if (0 <= dotPos) { extension = path.substring(dotPos + 1); extension = extension.toLowerCase(); } } Log.i(TAG, "AudioModel extension: " + extension); mContentType = mimeTypeMap.getMimeTypeFromExtension(extension); if (mContentType == null && extension.equals("dcf")) { DrmManagerClient drmManager = new DrmManagerClient(mContext); mContentType = drmManager.getOriginalMimeType(path); } Log.i(TAG, "VideoModel got mContentType: " + mContentType); if (mContentType.startsWith("video/")) { String temp = mContentType.substring(mContentType.lastIndexOf('/') + 1); mContentType = "audio/"; mContentType += temp; } Log.i(TAG, "AudioModel mContentType: " + mContentType); }
public void initModelFromFileUri(Uri uri) throws MmsException { String path = uri.getPath(); mSrc = path.substring(path.lastIndexOf('/') + 1); Xlog.i(TAG, "AudioModel mSrc: " + mSrc); if (mSrc.startsWith(".") && mSrc.length() > 1) { mSrc = mSrc.substring(1); } // Some MMSCs appear to have problems with filenames // containing a space. So just replace them with // underscores in the name, which is typically not // visible to the user anyway. mSrc = mSrc.replace(' ', '_'); // mUri = uri; MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); String extension = MimeTypeMap.getFileExtensionFromUrl(path).toLowerCase(); if (TextUtils.isEmpty(extension)) { // getMimeTypeFromExtension() doesn't handle spaces in filenames nor can it handle // urlEncoded strings. Let's try one last time at finding the extension. int dotPos = path.lastIndexOf('.'); if (0 <= dotPos) { extension = path.substring(dotPos + 1); extension = extension.toLowerCase(); } } Xlog.i(TAG, "AudioModel extension: " + extension); mContentType = mimeTypeMap.getMimeTypeFromExtension(extension); if (mContentType == null) { // set default content type to "application/octet-stream" mContentType = "application/octet-stream"; if (extension != null && extension.equals("dcf")) { DrmManagerClient drmManager = new DrmManagerClient(mContext); mContentType = drmManager.getOriginalMimeType(path); } } Xlog.i(TAG, "AudioModel got mContentType: " + mContentType); if (mContentType != null && mContentType.startsWith("video/")) { String temp = mContentType.substring(mContentType.lastIndexOf('/') + 1); mContentType = "audio/"; mContentType += temp; } Xlog.i(TAG, "AudioModel mContentType: " + mContentType); // initMediaDuration if (path != null) { Xlog.i(TAG, "Audio Path: " + path); ContentResolver cr = mContext.getContentResolver(); Cursor c = cr.query( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] {MediaStore.MediaColumns._ID}, MediaStore.MediaColumns.DATA + "=?", new String[] {path}, null); if (c != null) { try { if (c.moveToFirst()) { Uri audioUri = Uri.withAppendedPath(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, c.getString(0)); Xlog.i(TAG, "Get audio id in MediaStore:" + c.getString(0)); initMediaDuration(audioUri); } else { Xlog.i(TAG, "MediaStore has not this audio"); } } finally { c.close(); } } else { throw new MmsException("Bad URI: " + uri); } } }