예제 #1
0
  private void initModelFromUri(Uri uri) throws MmsException {
    ContentResolver cr = mContext.getContentResolver();
    Cursor c = SqliteWrapper.query(mContext, cr, uri, null, null, null, null);

    if (c != null) {
      try {
        if (c.moveToFirst()) {
          String path;
          boolean isFromMms = isMmsUri(uri);

          // FIXME We suppose that there should be only two sources
          // of the audio, one is the media store, the other is
          // our MMS database.
          if (isFromMms) {
            path = c.getString(c.getColumnIndexOrThrow(Part._DATA));
            mContentType = c.getString(c.getColumnIndexOrThrow(Part.CONTENT_TYPE));
          } else {
            path = c.getString(c.getColumnIndexOrThrow(Audio.Media.DATA));
            mContentType = c.getString(c.getColumnIndexOrThrow(Audio.Media.MIME_TYPE));
            // Get more extras information which would be useful
            // to the user.
            String album = c.getString(c.getColumnIndexOrThrow("album"));
            if (!TextUtils.isEmpty(album)) {
              mExtras.put("album", album);
            }

            String artist = c.getString(c.getColumnIndexOrThrow("artist"));
            if (!TextUtils.isEmpty(artist)) {
              mExtras.put("artist", artist);
            }
          }
          if (FeatureOption.MTK_DRM_APP) {
            if (MessageUtils.checkUriContainsDrm(mContext, uri)) {
              path += ".dcf";
            }
          }

          mSrc = path.substring(path.lastIndexOf('/') + 1).replace(' ', '_');
          Log.i(TAG, "path: " + path);
          Log.i(TAG, "mSrc: " + mSrc);

          if (TextUtils.isEmpty(mContentType)) {
            throw new MmsException("Type of media is unknown.");
          }

          if (LOCAL_LOGV) {
            Log.v(
                TAG,
                "New AudioModel created:"
                    + " mSrc="
                    + mSrc
                    + " mContentType="
                    + mContentType
                    + " mUri="
                    + uri
                    + " mExtras="
                    + mExtras);
          }
        } else {
          throw new MmsException("Nothing found: " + uri);
        }
      } finally {
        c.close();
      }
    } else {
      throw new MmsException("Bad URI: " + uri);
    }

    initMediaDuration();
  }