@Override protected void close(AssetFileDescriptor data) throws IOException { data.close(); }
@Override public void close() throws IOException { if(mDescriptor != null) mDescriptor.close(); mDescriptor = null; mMediaBytes = null; }
@Override public void close() throws IOException { if(mDescriptor != null) mDescriptor.close(); mDescriptor = null; mMediaBytes = null; }
@Override public void close() throws IOException { file.close(); afd.close(); } }
public long length () { if (type == FileType.Internal) { AssetFileDescriptor fileDescriptor = null; try { fileDescriptor = assets.openFd(file.getPath()); return fileDescriptor.getLength(); } catch (IOException ignored) { } finally { if (fileDescriptor != null) { try { fileDescriptor.close(); } catch (IOException e) { } ; } } } return super.length(); }
public long length () { if (type == FileType.Internal) { AssetFileDescriptor fileDescriptor = null; try { fileDescriptor = assets.openFd(file.getPath()); return fileDescriptor.getLength(); } catch (IOException ignored) { } finally { if (fileDescriptor != null) { try { fileDescriptor.close(); } catch (IOException e) { } ; } } } return super.length(); }
private void initialize() { path = file.getPath().replace('\\', '/'); expansionFile = ((AndroidFiles) Gdx.files).getExpansionFile(); AssetFileDescriptor assetFd = expansionFile.getAssetFileDescriptor(getPath()); if (assetFd != null) { hasAssetFd = true; fdLength = assetFd.getLength(); try { assetFd.close(); } catch (IOException e) {} } else { hasAssetFd = false; } // needed for listing entries and exists() of directories if (isDirectory()) path += "/"; }
private void initialize() { path = file.getPath().replace('\\', '/'); expansionFile = ((AndroidFiles) Gdx.files).getExpansionFile(); AssetFileDescriptor assetFd = expansionFile.getAssetFileDescriptor(getPath()); if (assetFd != null) { hasAssetFd = true; fdLength = assetFd.getLength(); try { assetFd.close(); } catch (IOException e) {} } else { hasAssetFd = false; } // needed for listing entries and exists() of directories if (isDirectory()) path += "/"; }
// MediaPlayer m; /*assume, somewhere in the global scope...*/ public void playBeep() { try { if (m.isPlaying()) { m.stop(); m.release(); m = new MediaPlayer(); } AssetFileDescriptor descriptor = getAssets().openFd("beepbeep.mp3"); m.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength()); descriptor.close(); m.prepare(); m.setVolume(1f, 1f); m.setLooping(true); m.start(); } catch (Exception e) { e.printStackTrace(); } }
GifInfoHandle(AssetFileDescriptor afd) throws IOException { try { gifInfoPtr = openFileDescriptor(afd.getFileDescriptor(), afd.getStartOffset(), false); } finally { try { afd.close(); } catch (IOException ignored) { //no-op } } }
@SuppressWarnings("Finally") @Override public void close() throws RawResourceDataSourceException { uri = null; try { if (inputStream != null) { inputStream.close(); } } catch (IOException e) { throw new RawResourceDataSourceException(e); } finally { inputStream = null; try { if (assetFileDescriptor != null) { assetFileDescriptor.close(); } } catch (IOException e) { throw new RawResourceDataSourceException(e); } finally { assetFileDescriptor = null; if (opened) { opened = false; transferEnded(); } } } }
@SuppressWarnings("Finally") @Override public void close() throws ContentDataSourceException { uri = null; try { if (inputStream != null) { inputStream.close(); } } catch (IOException e) { throw new ContentDataSourceException(e); } finally { inputStream = null; try { if (assetFileDescriptor != null) { assetFileDescriptor.close(); } } catch (IOException e) { throw new ContentDataSourceException(e); } finally { assetFileDescriptor = null; if (opened) { opened = false; transferEnded(); } } } }
AssetFileDescriptor descriptor = aHandle.getAssetFileDescriptor(); mediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength()); descriptor.close(); mediaPlayer.prepare(); AndroidMusic music = new AndroidMusic(this, mediaPlayer);
AssetFileDescriptor descriptor = aHandle.getAssetFileDescriptor(); mediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength()); descriptor.close(); mediaPlayer.prepare(); AndroidMusic music = new AndroidMusic(this, mediaPlayer);
AssetFileDescriptor afd = context.getResources().openRawResourceFd(resid); if (afd == null) return; mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); afd.close();
private void initBeepSound() { if (playBeep && mediaPlayer == null) { // The volume on STREAM_SYSTEM is not adjustable, and users found it // too loud, // so we now play on the music stream. setVolumeControlStream(AudioManager.STREAM_MUSIC); mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setOnCompletionListener(beepListener); AssetFileDescriptor file = getResources().openRawResourceFd( R.raw.beep); try { mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength()); file.close(); mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME); mediaPlayer.prepare(); } catch (IOException e) { mediaPlayer = null; } } }
@Test public void gifDrawableCreatedFromInputStream() throws Exception { final AssetFileDescriptor assetFileDescriptor = InstrumentationRegistry.getInstrumentation() .getContext().getResources().openRawResourceFd(R.raw.test); final byte[] buffer = new byte[(int) assetFileDescriptor.getDeclaredLength()]; final FileInputStream inputStream = assetFileDescriptor.createInputStream(); final int bufferedByteCount = inputStream.read(buffer); inputStream.close(); assetFileDescriptor.close(); assertThat(bufferedByteCount).isEqualTo(buffer.length); final InputStream responseStream = new ByteArrayInputStream(buffer); final GifDrawable gifDrawable = new GifDrawable(responseStream); assertThat(gifDrawable.getError()).isEqualTo(GifError.NO_ERROR); assertThat(gifDrawable.getIntrinsicWidth()).isEqualTo(278); assertThat(gifDrawable.getIntrinsicHeight()).isEqualTo(183); } }
/** {@inheritDoc} */ @Override public Sound newSound (FileHandle file) { if (soundPool == null) { throw new GdxRuntimeException("Android audio is not enabled by the application config."); } AndroidFileHandle aHandle = (AndroidFileHandle)file; if (aHandle.type() == FileType.Internal) { try { AssetFileDescriptor descriptor = aHandle.getAssetFileDescriptor(); AndroidSound sound = new AndroidSound(soundPool, manager, soundPool.load(descriptor, 1)); descriptor.close(); return sound; } catch (IOException ex) { throw new GdxRuntimeException("Error loading audio file: " + file + "\nNote: Internal audio files must be placed in the assets directory.", ex); } } else { try { return new AndroidSound(soundPool, manager, soundPool.load(aHandle.file().getPath(), 1)); } catch (Exception ex) { throw new GdxRuntimeException("Error loading audio file: " + file, ex); } } }
/** {@inheritDoc} */ @Override public Sound newSound (FileHandle file) { if (soundPool == null) { throw new GdxRuntimeException("Android audio is not enabled by the application config."); } AndroidFileHandle aHandle = (AndroidFileHandle)file; if (aHandle.type() == FileType.Internal) { try { AssetFileDescriptor descriptor = aHandle.getAssetFileDescriptor(); AndroidSound sound = new AndroidSound(soundPool, manager, soundPool.load(descriptor, 1)); descriptor.close(); return sound; } catch (IOException ex) { throw new GdxRuntimeException("Error loading audio file: " + file + "\nNote: Internal audio files must be placed in the assets directory.", ex); } } else { try { return new AndroidSound(soundPool, manager, soundPool.load(aHandle.file().getPath(), 1)); } catch (Exception ex) { throw new GdxRuntimeException("Error loading audio file: " + file, ex); } } }
@Test public void open_shouldProvideFileDescriptor() throws Exception { File file = new File( getTargetContext().getFilesDir() + File.separator + "open_shouldProvideFileDescriptor.txt"); FileOutputStream output = new FileOutputStream(file); output.write("hi".getBytes()); ParcelFileDescriptor parcelFileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); AssetFileDescriptor assetFileDescriptor = new AssetFileDescriptor(parcelFileDescriptor, 0, "hi".getBytes().length); assertThat( CharStreams.toString( new InputStreamReader(assetFileDescriptor.createInputStream(), UTF_8))) .isEqualTo("hi"); assertThat(assetFileDescriptor.getLength()).isEqualTo(2); assetFileDescriptor.close(); } }