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


Java AssetFileDescriptor類代碼示例

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


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

示例1: buildMediaPlayer

import android.content.res.AssetFileDescriptor; //導入依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    try {
        AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
        } finally {
            file.close();
        }
        mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
        mediaPlayer.prepare();
        return mediaPlayer;
    } catch (IOException ioe) {
        Log.w(TAG, ioe);
        mediaPlayer.release();
        return null;
    }
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:22,代碼來源:BeepManager.java

示例2: buildMediaPlayer

import android.content.res.AssetFileDescriptor; //導入依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
  MediaPlayer mediaPlayer = new MediaPlayer();
  try {
    AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
    try {
      mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
    } finally {
      file.close();
    }
    mediaPlayer.setOnErrorListener(this);
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setLooping(false);
    mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
    mediaPlayer.prepare();
    return mediaPlayer;
  } catch (IOException ioe) {
    Log.w(TAG, ioe);
    mediaPlayer.release();
    return null;
  }
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:22,代碼來源:BeepManager.java

示例3: decodeBitmap

import android.content.res.AssetFileDescriptor; //導入依賴的package包/類
private static Bitmap decodeBitmap(Context context, Uri theUri, int sampleSize) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = sampleSize;

    AssetFileDescriptor fileDescriptor = null;
    try {
        fileDescriptor = context.getContentResolver().openAssetFileDescriptor(theUri, "r");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    Bitmap actuallyUsableBitmap = BitmapFactory.decodeFileDescriptor(
            fileDescriptor.getFileDescriptor(), null, options);

    Log.d(TAG, options.inSampleSize + " sample method bitmap ... " +
            actuallyUsableBitmap.getWidth() + " " + actuallyUsableBitmap.getHeight());

    return actuallyUsableBitmap;
}
 
開發者ID:AppHero2,項目名稱:Raffler-Android,代碼行數:20,代碼來源:ImagePicker.java

示例4: openOutputStream

import android.content.res.AssetFileDescriptor; //導入依賴的package包/類
/**
 * Opens a stream to the given URI.
 * @return Never returns null.
 * @throws Throws an InvalidArgumentException for relative URIs. Relative URIs should be
 *     resolved before being passed into this function.
 * @throws Throws an IOException if the URI cannot be opened.
 */
public OutputStream openOutputStream(Uri uri, boolean append) throws IOException {
    assertBackgroundThread();
    switch (getUriType(uri)) {
        case URI_TYPE_FILE: {
            File localFile = new File(uri.getPath());
            File parent = localFile.getParentFile();
            if (parent != null) {
                parent.mkdirs();
            }
            return new FileOutputStream(localFile, append);
        }
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE: {
            AssetFileDescriptor assetFd = contentResolver.openAssetFileDescriptor(uri, append ? "wa" : "w");
            return assetFd.createOutputStream();
        }
    }
    throw new FileNotFoundException("URI not supported by CordovaResourceApi: " + uri);
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:27,代碼來源:CordovaResourceApi.java

示例5: buildMediaPlayer

import android.content.res.AssetFileDescriptor; //導入依賴的package包/類
MediaPlayer buildMediaPlayer(Context activity) {
	MediaPlayer mediaPlayer = new MediaPlayer();
	mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
	mediaPlayer.setOnCompletionListener(this);
	mediaPlayer.setOnErrorListener(this);
	try {
		AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
		try {
			mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
		} finally {
			file.close();
		}
		mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
		mediaPlayer.prepare();
		return mediaPlayer;
	} catch (IOException ioe) {
		Log.w(TAG, ioe);
		mediaPlayer.release();
		return null;
	}
}
 
開發者ID:StickyTolt,項目名稱:ForeverLibrary,代碼行數:22,代碼來源:BeepManager.java

示例6: buildMediaPlayer

import android.content.res.AssetFileDescriptor; //導入依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
  MediaPlayer mediaPlayer = new MediaPlayer();
  try {
    AssetFileDescriptor file = activity.getResources().openRawResourceFd(this.rawBeep);
    try {
      mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
    } finally {
      file.close();
    }
    mediaPlayer.setOnErrorListener(this);
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setLooping(false);
    mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
    mediaPlayer.prepare();
    return mediaPlayer;
  } catch (IOException ioe) {
    Log.w(TAG, ioe);
    mediaPlayer.release();
    return null;
  }
}
 
開發者ID:10045125,項目名稱:QrCode,代碼行數:22,代碼來源:BeepManager.java

示例7: openTypedAssetFileImpl

import android.content.res.AssetFileDescriptor; //導入依賴的package包/類
private final AssetFileDescriptor openTypedAssetFileImpl(
        Uri uri, String mimeTypeFilter, Bundle opts, CancellationSignal signal)
        throws FileNotFoundException {
    enforceTree(uri);
    final String documentId = getDocumentId(uri);
    if (opts != null && opts.containsKey(ContentResolver.EXTRA_SIZE)) {
        final Point sizeHint = opts.getParcelable(ContentResolver.EXTRA_SIZE);
        return openDocumentThumbnail(documentId, sizeHint, signal);
    }
    if ("*/*".equals(mimeTypeFilter)) {
         // If they can take anything, the untyped open call is good enough.
         return openAssetFile(uri, "r");
    }
    final String baseType = getType(uri);
    if (baseType != null && ClipDescription.compareMimeTypes(baseType, mimeTypeFilter)) {
        // Use old untyped open call if this provider has a type for this
        // URI and it matches the request.
        return openAssetFile(uri, "r");
    }
    // For any other yet unhandled case, let the provider subclass handle it.
    return openTypedDocument(documentId, mimeTypeFilter, opts, signal);
}
 
開發者ID:medalionk,項目名稱:simple-share-android,代碼行數:23,代碼來源:DocumentsProvider.java

示例8: initBeepSound

import android.content.res.AssetFileDescriptor; //導入依賴的package包/類
private void initBeepSound() {
    this.playBeep = true;
    if (((AudioManager) getSystemService("audio")).getRingerMode() != 2) {
        this.playBeep = false;
    }
    if (this.playBeep && this.mediaPlayer == null) {
        setVolumeControlStream(3);
        this.mediaPlayer = new MediaPlayer();
        this.mediaPlayer.setAudioStreamType(3);
        this.mediaPlayer.setOnCompletionListener(this.beepListener);
        AssetFileDescriptor file = getResources().openRawResourceFd(R.raw.beep);
        try {
            this.mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
            file.close();
            this.mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
            this.mediaPlayer.prepare();
        } catch (IOException e) {
            this.mediaPlayer = null;
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:22,代碼來源:SweepActivity.java

示例9: buildMediaPlayer

import android.content.res.AssetFileDescriptor; //導入依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    try {
        AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
        } finally {
            file.close();
        }
        mediaPlayer.setOnErrorListener(this);
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.setLooping(false);
        mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
        mediaPlayer.prepare();
        return mediaPlayer;
    } catch (IOException ioe) {
        Log.w(TAG, ioe);
        mediaPlayer.release();
        return null;
    }
}
 
開發者ID:xiong-it,項目名稱:ZXingAndroidExt,代碼行數:22,代碼來源:BeepManager.java

示例10: buildMediaPlayer

import android.content.res.AssetFileDescriptor; //導入依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    try {
        AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.qr_sacn);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
        } finally {
            file.close();
        }
        mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
        mediaPlayer.prepare();
        return mediaPlayer;
    } catch (IOException ioe) {
        Log.w(TAG, ioe);
        mediaPlayer.release();
        return null;
    }
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:22,代碼來源:BeepManager.java

示例11: getAssetsIgnoreCaseAfd

import android.content.res.AssetFileDescriptor; //導入依賴的package包/類
/**
 * find path of an asset from a mediaPath using case-insensitive comparison,
 * return AssetFileDescriptor of that asset
 * Throws IOException if there is no matching path
 * @param form the Form
 * @param mediaPath the path to the media
 */
private static AssetFileDescriptor getAssetsIgnoreCaseAfd(Form form, String mediaPath)
    throws IOException{
  try {
    return form.getAssets().openFd(mediaPath);

  } catch (IOException e) {
    String path = findCaseinsensitivePath(form, mediaPath);
    if (path == null){
      throw e;
    } else {
    return form.getAssets().openFd(path);
    }
  }
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:22,代碼來源:MediaUtil.java

示例12: buildMediaPlayer

import android.content.res.AssetFileDescriptor; //導入依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
    mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    // mediaPlayer.setOnErrorListener(this);
    try {
        AssetFileDescriptor file = activity.getResources()
                .openRawResourceFd(R.raw.beep);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(),
                    file.getStartOffset(), file.getLength());
        } finally {
            file.close();
        }
        mediaPlayer.setVolume(0.10f, 0.10f);
        mediaPlayer.prepare();
        return mediaPlayer;
    } catch (IOException ioe) {
        mediaPlayer.release();
        return null;
    }
}
 
開發者ID:c3cashdesk,項目名稱:postixdroid,代碼行數:23,代碼來源:MainActivity.java

示例13: openAssetFile

import android.content.res.AssetFileDescriptor; //導入依賴的package包/類
@Override
public AssetFileDescriptor openAssetFile(Uri uri, String mode)
		throws FileNotFoundException {
       initIfNecessary();
	String path = uri.getEncodedPath();
	if ( path.startsWith("/") ) {
		path = path.substring(1);
	}
	return mAPKExtensionFile.getAssetFileDescriptor(path);		
}
 
開發者ID:12d,項目名稱:react-native-videoplayer,代碼行數:11,代碼來源:APEZProvider.java

示例14: openFile

import android.content.res.AssetFileDescriptor; //導入依賴的package包/類
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode)
		throws FileNotFoundException {
       initIfNecessary();
	AssetFileDescriptor af = openAssetFile(uri, mode);
	if ( null != af ) {
		return af.getParcelFileDescriptor();
	}
	return null;
}
 
開發者ID:12d,項目名稱:react-native-videoplayer,代碼行數:11,代碼來源:APEZProvider.java

示例15: testLoadResource_returnsFileDescriptor

import android.content.res.AssetFileDescriptor; //導入依賴的package包/類
@Test
public void testLoadResource_returnsFileDescriptor() throws Exception {
  Context context = RuntimeEnvironment.application;
  Uri uri = Uri.parse("file://nothing");

  ContentResolver contentResolver = context.getContentResolver();
  ContentResolverShadow shadow = (ContentResolverShadow) Shadow.extract(contentResolver);

  AssetFileDescriptor assetFileDescriptor = mock(AssetFileDescriptor.class);
  ParcelFileDescriptor parcelFileDescriptor = mock(ParcelFileDescriptor.class);
  when(assetFileDescriptor.getParcelFileDescriptor()).thenReturn(parcelFileDescriptor);
  shadow.registerFileDescriptor(uri, assetFileDescriptor);

  FileDescriptorLocalUriFetcher fetcher =
      new FileDescriptorLocalUriFetcher(context.getContentResolver(), uri);
  fetcher.loadData(Priority.NORMAL, callback);
  verify(callback).onDataReady(eq(parcelFileDescriptor));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:FileDescriptorLocalUriFetcherTest.java


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