本文整理汇总了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;
}
}
示例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;
}
}
示例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;
}
示例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);
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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;
}
}
}
示例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;
}
}
示例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;
}
}
示例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);
}
}
}
示例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;
}
}
示例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);
}
示例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;
}
示例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));
}