当前位置: 首页>>代码示例>>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;未经允许,请勿转载。