當前位置: 首頁>>代碼示例>>Java>>正文


Java AssetFileDescriptor.getFileDescriptor方法代碼示例

本文整理匯總了Java中android.content.res.AssetFileDescriptor.getFileDescriptor方法的典型用法代碼示例。如果您正苦於以下問題:Java AssetFileDescriptor.getFileDescriptor方法的具體用法?Java AssetFileDescriptor.getFileDescriptor怎麽用?Java AssetFileDescriptor.getFileDescriptor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.res.AssetFileDescriptor的用法示例。


在下文中一共展示了AssetFileDescriptor.getFileDescriptor方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setDataSource

import android.content.res.AssetFileDescriptor; //導入方法依賴的package包/類
public void setDataSource(Context context, Uri uri)
    throws IllegalArgumentException, SecurityException {
    if (uri == null) {
        throw new IllegalArgumentException();
    }
    
    String scheme = uri.getScheme();
    if (SmbProxy.needToStream(scheme)){
        mSmbProxy = SmbProxy.setDataSource(uri, this, null);
        return;
    }
    if(scheme == null || scheme.equals("file")) {
        setDataSource(uri.getPath());
        return;
    }

    AssetFileDescriptor fd = null;
    try {
        ContentResolver resolver = context.getContentResolver();
        try {
            fd = resolver.openAssetFileDescriptor(uri, "r");
        } catch(FileNotFoundException e) {
            throw new IllegalArgumentException();
        }
        if (fd == null) {
            throw new IllegalArgumentException();
        }
        FileDescriptor descriptor = fd.getFileDescriptor();
        if (!descriptor.valid()) {
            throw new IllegalArgumentException();
        }
        // Note: using getDeclaredLength so that our behavior is the same
        // as previous versions when the content provider is returning
        // a full file.
        if (fd.getDeclaredLength() < 0) {
            setDataSource(descriptor);
        } else {
            setDataSource(descriptor, fd.getStartOffset(), fd.getDeclaredLength());
        }
        return;
    } catch (SecurityException ex) {
    } finally {
        try {
            if (fd != null) {
                fd.close();
            }
        } catch(IOException ioEx) {
        }
    }
    setDataSource(uri.toString(), null, null);
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:52,代碼來源:AvosMediaMetadataRetriever.java

示例2: open

import android.content.res.AssetFileDescriptor; //導入方法依賴的package包/類
@Override
public long open(DataSpec dataSpec) throws ContentDataSourceException {
  try {
    uriString = dataSpec.uri.toString();
    AssetFileDescriptor assetFd = resolver.openAssetFileDescriptor(dataSpec.uri, "r");
    inputStream = new FileInputStream(assetFd.getFileDescriptor());
    long skipped = inputStream.skip(dataSpec.position);
    if (skipped < dataSpec.position) {
      // We expect the skip to be satisfied in full. If it isn't then we're probably trying to
      // skip beyond the end of the data.
      throw new EOFException();
    }
    if (dataSpec.length != C.LENGTH_UNBOUNDED) {
      bytesRemaining = dataSpec.length;
    } else {
      bytesRemaining = inputStream.available();
      if (bytesRemaining == 0) {
        // FileInputStream.available() returns 0 if the remaining length cannot be determined, or
        // if it's greater than Integer.MAX_VALUE. We don't know the true length in either case,
        // so treat as unbounded.
        bytesRemaining = C.LENGTH_UNBOUNDED;
      }
    }
  } catch (IOException e) {
    throw new ContentDataSourceException(e);
  }

  opened = true;
  if (listener != null) {
    listener.onTransferStart();
  }

  return bytesRemaining;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:35,代碼來源:ContentDataSource.java

示例3: loadMediaPlayer

import android.content.res.AssetFileDescriptor; //導入方法依賴的package包/類
/**
 * Loads the audio or video specified by mediaPath into the given
 * MediaPlayer.
 *
 * @param mediaPlayer the MediaPlayer
 * @param form the Form
 * @param mediaPath the path to the media
 */
public static void loadMediaPlayer(MediaPlayer mediaPlayer, Form form, String mediaPath)
    throws IOException {
  MediaSource mediaSource = determineMediaSource(form, mediaPath);
  switch (mediaSource) {
    case ASSET:
      AssetFileDescriptor afd = getAssetsIgnoreCaseAfd(form,mediaPath);
      try {
        FileDescriptor fd = afd.getFileDescriptor();
        long offset = afd.getStartOffset();
        long length = afd.getLength();
        mediaPlayer.setDataSource(fd, offset, length);
      } finally {
        afd.close();
      }
      return;


    case REPL_ASSET:
      mediaPlayer.setDataSource(replAssetPath(mediaPath));
      return;

    case SDCARD:
      mediaPlayer.setDataSource(mediaPath);
      return;

    case FILE_URL:
      mediaPlayer.setDataSource(fileUrlToFilePath(mediaPath));
      return;

    case URL:
      // This works both for streaming and non-streaming.
      // TODO(halabelson): Think about whether we could get improved
      // performance if we did buffering control.
      mediaPlayer.setDataSource(mediaPath);
      return;

    case CONTENT_URI:
      mediaPlayer.setDataSource(form, Uri.parse(mediaPath));
      return;

    case CONTACT_URI:
      throw new IOException("Unable to load audio or video for contact " + mediaPath + ".");
  }
  throw new IOException("Unable to load audio or video " + mediaPath + ".");
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:54,代碼來源:MediaUtil.java


注:本文中的android.content.res.AssetFileDescriptor.getFileDescriptor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。