@Override GifInfoHandle open() throws IOException { return new GifInfoHandle(mResources.openRawResourceFd(mResourceId)); } }
/** * Retrieves from resource. * * @param res Resources to read from * @param id resource id * @throws android.content.res.Resources.NotFoundException if the given ID does not exist. * @throws java.io.IOException when opening failed * @throws NullPointerException if res is null */ public GifAnimationMetaData(@NonNull Resources res, @RawRes @DrawableRes int id) throws Resources.NotFoundException, IOException { this(res.openRawResourceFd(id)); }
public AssetFileDescriptor openFileDescriptor() { android.content.res.Resources androidResources = JmeAndroidSystem.getView().getContext().getResources(); if (resourceId == 0) { try { return androidResources.getAssets().openFd(assetPath); } catch (IOException ex) { throw new AssetLoadException("Failed to open asset " + assetPath, ex); } } else { try { return androidResources.openRawResourceFd(resourceId); } catch (Resources.NotFoundException ex) { throw new AssetLoadException("Failed to open asset " + assetPath, ex); } } } }
private static MediaPlayer buildMediaPlayer(Context activity) { MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); // When the beep has finished playing, rewind to queue up another one. mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { public void onCompletion(MediaPlayer player) { player.seekTo(0); } }); AssetFileDescriptor file = activity.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 ioe) { Log.w(TAG, ioe); mediaPlayer = null; } return mediaPlayer; }
assetFileDescriptor = resources.openRawResourceFd(resourceId); inputStream = new FileInputStream(assetFileDescriptor.getFileDescriptor()); inputStream.skip(assetFileDescriptor.getStartOffset());
AssetFileDescriptor file = context.getResources().openRawResourceFd(R.raw.zxing_beep); try { mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
@Test public void openRawResourceFd_returnsNull_todo_FIX() throws Exception { if (useLegacy()) { assertThat(resources.openRawResourceFd(R.raw.raw_resource)).isNull(); } else { assertThat(resources.openRawResourceFd(R.raw.raw_resource)).isNotNull(); } }
/** * Creates drawable from resource. * * @param res Resources to read from * @param id resource id (raw or drawable) * @throws NotFoundException if the given ID does not exist. * @throws IOException when opening failed * @throws NullPointerException if res is null */ public GifDrawable(@NonNull Resources res, @RawRes @DrawableRes int id) throws NotFoundException, IOException { this(res.openRawResourceFd(id)); final float densityScale = GifViewUtils.getDensityScale(res, id); mScaledHeight = (int) (mNativeInfoHandle.getHeight() * densityScale); mScaledWidth = (int) (mNativeInfoHandle.getWidth() * densityScale); }
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; } } }
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; } } }
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.qrcode_completed); try { mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength()); file.close(); mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME); mediaPlayer.prepare(); } catch (IOException e) { mediaPlayer = null; } } }
AssetFileDescriptor descriptor = context.getResources().openRawResourceFd(id); fileLength = descriptor.getLength(); } catch (Exception e) {
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. getActivity().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 openRawResourceFd_withNonFile_throwsNotFoundException() throws Exception { try { resources.openRawResourceFd(R.string.hello); fail("should throw"); } catch (Resources.NotFoundException e) { // cool } try { resources.openRawResourceFd(-1234); fail("should throw"); } catch (Resources.NotFoundException e) { // cool } }
@Test @Ignore("todo: incorrect behavior on robolectric vs framework?") public void openRawResourceFd_returnsNull_todo_FIX() throws Exception { assertThat(resources.openRawResourceFd(R.raw.raw_resource)).isNull(); }
/** * Since {@link AssetFileDescriptor}s are not yet supported by Robolectric, {@code null} will be * returned if the resource is found. If the resource cannot be found, {@link * Resources.NotFoundException} will be thrown. */ @Implementation protected AssetFileDescriptor openRawResourceFd(int id) throws Resources.NotFoundException { if (isLegacyAssetManager()) { InputStream inputStream = openRawResource(id); if (!(inputStream instanceof FileInputStream)) { // todo fixme return null; } FileInputStream fis = (FileInputStream) inputStream; try { return new AssetFileDescriptor(ParcelFileDescriptor.dup(fis.getFD()), 0, fis.getChannel().size()); } catch (IOException e) { throw newNotFoundException(id); } } else { return directlyOn(realResources, Resources.class).openRawResourceFd(id); } }
@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); } }
Resources res = getResources(); AssetFileDescriptor afd = res.openRawResourceFd(R.raw.alarm); mp.reset(); mp.setAudioStreamType(AudioManager.STREAM_ALARM); mp.setLooping(true); mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); mp.prepare(); mp.start();
public void setRawData(@RawRes int id) throws IOException { AssetFileDescriptor afd = getResources().openRawResourceFd(id); setDataSource(afd); }
public void setRawData(@RawRes int id) throws IOException { AssetFileDescriptor afd = getResources().openRawResourceFd(id); setDataSource(afd); }