Java Code Examples for android.content.res.AssetManager#openFd()
The following examples show how to use
android.content.res.AssetManager#openFd() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Helper.java From VIA-AI with MIT License | 6 votes |
public static void findAPKFile(String filepath, Context context) { String apkFilepath = getAPKFilepath(context); // Get the offset and length for the file: theUrl, that is in your // assets folder AssetManager assetManager = context.getAssets(); try { AssetFileDescriptor assFD = assetManager.openFd(filepath); if (assFD != null) { long offset = assFD.getStartOffset(); long fileSize = assFD.getLength(); assFD.close(); // **** offset and fileSize are the offset and size // **** in bytes of the asset inside the APK } } catch (IOException e) { e.printStackTrace(); } }
Example 2
Source File: AssetProvider.java From android-ActionBarCompat-ShareActionProvider with Apache License 2.0 | 6 votes |
@Override public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException { // The asset file name should be the last path segment final String assetName = uri.getLastPathSegment(); // If the given asset name is empty, throw an exception if (TextUtils.isEmpty(assetName)) { throw new FileNotFoundException(); } try { // Try and return a file descriptor for the given asset name AssetManager am = getContext().getAssets(); return am.openFd(assetName); } catch (IOException e) { e.printStackTrace(); return super.openAssetFile(uri, mode); } }
Example 3
Source File: MediaPlayerImpl.java From dcs-sdk-java with Apache License 2.0 | 6 votes |
private void playAsset(String resName) { LogUtil.d(TAG, "playAsset:" + resName); try { AssetManager am = context.getAssets(); AssetFileDescriptor afd = am.openFd(resName); mMediaPlayer.reset(); mMediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); mMediaPlayer.prepareAsync(); mCurrentState = IMediaPlayer.PlayState.PREPARING; } catch (IOException e) { e.printStackTrace(); LogUtil.d(TAG, "playAsset", e); mCurrentState = IMediaPlayer.PlayState.ERROR; fireOnError("IOException play playAsset", IMediaPlayer.ErrorType.MEDIA_ERROR_INTERNAL_DEVICE_ERROR); } }
Example 4
Source File: VideoLiveWallpaper.java From LiveWallPaper with Apache License 2.0 | 6 votes |
@Override public void onSurfaceCreated(SurfaceHolder holder) { L.d("VideoEngine#onSurfaceCreated "); super.onSurfaceCreated(holder); mMediaPlayer = new MediaPlayer(); mMediaPlayer.setSurface(holder.getSurface()); try { AssetManager assetMg = getApplicationContext().getAssets(); AssetFileDescriptor fileDescriptor = assetMg.openFd("test1.mp4"); mMediaPlayer.setDataSource(fileDescriptor.getFileDescriptor(), fileDescriptor.getStartOffset(), fileDescriptor.getLength()); mMediaPlayer.setLooping(true); mMediaPlayer.setVolume(0, 0); mMediaPlayer.prepare(); mMediaPlayer.start(); } catch (IOException e) { e.printStackTrace(); } }
Example 5
Source File: DynamicWallPaper.java From LiveWallPaper with Apache License 2.0 | 6 votes |
private void initMediaPlayer(SurfaceHolder holder){ mediaPlayer = new MediaPlayer(); try { AssetManager assetMg = getApplicationContext().getAssets(); AssetFileDescriptor fileDescriptor = assetMg.openFd(此处资源asset请从鸿洋大神那获取); mediaPlayer.setDataSource(fileDescriptor.getFileDescriptor(), fileDescriptor.getStartOffset(), fileDescriptor.getLength()); mediaPlayer.setDisplay(holder); mediaPlayer.prepare(); mediaPlayer.setLooping(true); mediaPlayer.setVolume(0, 0); mediaPlayer.prepare(); }catch (Exception e){ e.printStackTrace(); } }
Example 6
Source File: VideoLiveWallpaper.java From LLApp with Apache License 2.0 | 6 votes |
@Override public void onSurfaceCreated(SurfaceHolder holder) { LogUtils.d(TAG,"VideoEngine#onSurfaceCreated "); super.onSurfaceCreated(holder); mMediaPlayer = new MediaPlayer(); mMediaPlayer.setSurface(holder.getSurface()); try { AssetManager assetMg = getApplicationContext().getAssets(); AssetFileDescriptor fileDescriptor = assetMg.openFd("test1.mp4"); mMediaPlayer.setDataSource(fileDescriptor.getFileDescriptor(), fileDescriptor.getStartOffset(), fileDescriptor.getLength()); mMediaPlayer.setLooping(true); mMediaPlayer.setVolume(0, 0); mMediaPlayer.prepare(); mMediaPlayer.start(); } catch (IOException e) { e.printStackTrace(); } }
Example 7
Source File: MyUtil.java From Android-MobileFaceNet-MTCNN-FaceAntiSpoofing with MIT License | 5 votes |
/** * 加载模型文件 * @param assetManager * @param modelPath * @return * @throws IOException */ public static MappedByteBuffer loadModelFile(AssetManager assetManager, String modelPath) throws IOException { AssetFileDescriptor fileDescriptor = assetManager.openFd(modelPath); FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor()); FileChannel fileChannel = inputStream.getChannel(); long startOffset = fileDescriptor.getStartOffset(); long declaredLength = fileDescriptor.getDeclaredLength(); return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength); }
Example 8
Source File: StickerContentProvider.java From flutter_whatsapp_stickers with BSD 3-Clause "New" or "Revised" License | 5 votes |
private AssetFileDescriptor fetchAssetFile(@NonNull final Uri uri, @NonNull final AssetManager am, @NonNull final String fileName, @NonNull final String identifier) { try { return am.openFd(contentPath + identifier + "/" + fileName); } catch (final IOException e) { Log.e(Objects.requireNonNull(getContext()).getPackageName(), "IOException when getting asset file, uri:" + uri, e); return null; } }
Example 9
Source File: Classifier.java From yolov3-android-tflite with MIT License | 5 votes |
protected MappedByteBuffer loadModelFile(AssetManager assetManager, String modelPath) throws IOException { AssetFileDescriptor fileDescriptor = assetManager.openFd(modelPath); FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor()); FileChannel fileChannel = inputStream.getChannel(); long startOffset = fileDescriptor.getStartOffset(); long declaredLength = fileDescriptor.getDeclaredLength(); return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength); }
Example 10
Source File: QaClient.java From tflite-android-transformers with Apache License 2.0 | 5 votes |
/** Load tflite model from assets. */ public MappedByteBuffer loadModelFile(AssetManager assetManager) throws IOException { try (AssetFileDescriptor fileDescriptor = assetManager.openFd(MODEL_PATH); FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor())) { FileChannel fileChannel = inputStream.getChannel(); long startOffset = fileDescriptor.getStartOffset(); long declaredLength = fileDescriptor.getDeclaredLength(); return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength); } }
Example 11
Source File: TFLiteObjectDetectionAPIModel.java From ml with Apache License 2.0 | 5 votes |
/** Memory-map the model file in Assets. */ private static MappedByteBuffer loadModelFile(AssetManager assets, String modelFilename) throws IOException { AssetFileDescriptor fileDescriptor = assets.openFd(modelFilename); FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor()); FileChannel fileChannel = inputStream.getChannel(); long startOffset = fileDescriptor.getStartOffset(); long declaredLength = fileDescriptor.getDeclaredLength(); return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength); }
Example 12
Source File: SampleContentProvider.java From SafeContentResolver with Apache License 2.0 | 5 votes |
@Nullable @Override public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException { AssetManager assetManager = getContext().getAssets(); try { return assetManager.openFd("sample.txt"); } catch (IOException e) { throw new FileNotFoundException("Error: " + e.getMessage()); } }
Example 13
Source File: TensorFlowImageClassifier.java From Android-TensorFlow-Lite-Example with Apache License 2.0 | 5 votes |
private MappedByteBuffer loadModelFile(AssetManager assetManager, String modelPath) throws IOException { AssetFileDescriptor fileDescriptor = assetManager.openFd(modelPath); FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor()); FileChannel fileChannel = inputStream.getChannel(); long startOffset = fileDescriptor.getStartOffset(); long declaredLength = fileDescriptor.getDeclaredLength(); return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength); }
Example 14
Source File: TFLiteObjectDetectionAPIModel.java From PHONK with GNU General Public License v3.0 | 5 votes |
/** Memory-map the model file in Assets. */ private static MappedByteBuffer loadModelFile(AssetManager assets, String modelFilename) throws IOException { AssetFileDescriptor fileDescriptor = assets.openFd(modelFilename); FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor()); FileChannel fileChannel = inputStream.getChannel(); long startOffset = fileDescriptor.getStartOffset(); long declaredLength = fileDescriptor.getDeclaredLength(); return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength); }
Example 15
Source File: TFLiteObjectDetectionAPIModel.java From FimiX8-RE with MIT License | 4 votes |
private static MappedByteBuffer loadModelFile(AssetManager assets, String modelFilename) throws IOException { AssetFileDescriptor fileDescriptor = assets.openFd(modelFilename); return new FileInputStream(fileDescriptor.getFileDescriptor()).getChannel().map(MapMode.READ_ONLY, fileDescriptor.getStartOffset(), fileDescriptor.getDeclaredLength()); }
Example 16
Source File: GifDrawable.java From sketch with Apache License 2.0 | 2 votes |
/** * Creates drawable from asset. * * @param assets AssetManager to read from * @param assetName name of the asset * @throws IOException when opening failed * @throws NullPointerException if assets or assetName is null */ public GifDrawable(@NonNull AssetManager assets, @NonNull String assetName) throws IOException { this(assets.openFd(assetName)); }
Example 17
Source File: GifAnimationMetaData.java From sketch with Apache License 2.0 | 2 votes |
/** * Retrieves metadata from asset. * * @param assets AssetManager to read from * @param assetName name of the asset * @throws IOException when opening failed * @throws NullPointerException if assets or assetName is null */ public GifAnimationMetaData(@NonNull AssetManager assets, @NonNull String assetName) throws IOException { this(assets.openFd(assetName)); }
Example 18
Source File: GifDrawable.java From meatspace-android with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Creates drawable from asset. * @param assets AssetManager to read from * @param assetName name of the asset * @throws java.io.IOException when opening failed * @throws NullPointerException if assets or assetName is null */ public GifDrawable ( AssetManager assets, String assetName ) throws IOException { this( assets.openFd( assetName ) ); }
Example 19
Source File: GifAnimationMetaData.java From android-gif-drawable-eclipse-sample with MIT License | 2 votes |
/** * Retrieves metadata from asset. * * @param assets AssetManager to read from * @param assetName name of the asset * @throws IOException when opening failed * @throws NullPointerException if assets or assetName is null */ public GifAnimationMetaData(@NonNull AssetManager assets, @NonNull String assetName) throws IOException { this(assets.openFd(assetName)); }
Example 20
Source File: GifDrawable.java From android-gif-drawable-eclipse-sample with MIT License | 2 votes |
/** * Creates drawable from asset. * * @param assets AssetManager to read from * @param assetName name of the asset * @throws IOException when opening failed * @throws NullPointerException if assets or assetName is null */ public GifDrawable(@NonNull AssetManager assets, @NonNull String assetName) throws IOException { this(assets.openFd(assetName)); }