use of android.content.res.AssetFileDescriptor in project android-zxingLibrary by yipianfengye.
the class CaptureFragment method initBeepSound.
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;
}
}
}
use of android.content.res.AssetFileDescriptor in project robolectric by robolectric.
the class ShadowBitmapRegionDecoderTest method testNewInstance.
@Test
public void testNewInstance() throws Exception {
assertThat(BitmapRegionDecoder.newInstance(ByteStreams.toByteArray(getImageInputStream()), 0, 0, false)).isNotNull();
try (AssetFileDescriptor afd = getImageFd()) {
assertThat(BitmapRegionDecoder.newInstance(afd.getFileDescriptor(), false)).isNotNull();
}
try (InputStream inputStream = getImageInputStream()) {
assertThat(BitmapRegionDecoder.newInstance(inputStream, false)).isNotNull();
}
assertThat(BitmapRegionDecoder.newInstance(getGeneratedImageFile(), false)).isNotNull();
}
use of android.content.res.AssetFileDescriptor in project robolectric by robolectric.
the class ShadowMediaPlayerTest method testSetDataSourceAssetFileDescriptorDataSource.
@Config(minSdk = N)
@Test
public void testSetDataSourceAssetFileDescriptorDataSource() throws IOException {
Application context = ApplicationProvider.getApplicationContext();
try (AssetFileDescriptor fd = context.getResources().openRawResourceFd(R.drawable.an_image)) {
DataSource ds = toDataSource(fd);
ShadowMediaPlayer.addMediaInfo(ds, info);
mediaPlayer.setDataSource(fd);
assertWithMessage("dataSource").that(shadowMediaPlayer.getDataSource()).isEqualTo(ds);
}
}
use of android.content.res.AssetFileDescriptor in project robolectric by robolectric.
the class ShadowLegacyAssetManager method openFd.
@Implementation
protected final AssetFileDescriptor openFd(String fileName) throws IOException {
Path path = findAssetFile(fileName);
if (path.getFileSystem().provider().getScheme().equals("jar")) {
path = getFileFromZip(path);
}
ParcelFileDescriptor parcelFileDescriptor = ParcelFileDescriptor.open(path.toFile(), ParcelFileDescriptor.MODE_READ_ONLY);
return new AssetFileDescriptor(parcelFileDescriptor, 0, Files.size(path));
}
use of android.content.res.AssetFileDescriptor in project robolectric by robolectric.
the class ShadowLegacyResourcesImpl method openRawResourceFd.
/**
* 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(maxSdk = M)
public AssetFileDescriptor openRawResourceFd(int id) throws Resources.NotFoundException {
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);
}
}
Aggregations