android.content.res.AssetFileDescriptor Java Examples

The following examples show how to use android.content.res.AssetFileDescriptor. 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: SystemServices.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
public static FileInfo getContactAsVCardFile(Context context, Uri uri) {
    AssetFileDescriptor fd;
    try {
        fd = context.getContentResolver().openAssetFileDescriptor(uri, "r");
        java.io.FileInputStream in = fd.createInputStream();
        byte[] buf = new byte[(int) fd.getDeclaredLength()];
        in.read(buf);
        in.close();
        String vCardText = new String(buf);
        Log.d("Vcard", vCardText);
        List<String> pathSegments = uri.getPathSegments();
        String targetPath = "/" + pathSegments.get(pathSegments.size() - 1) + ".vcf";
        SecureMediaStore.copyToVfs(buf, targetPath);
        FileInfo info = new FileInfo();
        info.stream = new info.guardianproject.iocipher.FileInputStream(SecureMediaStore.vfsUri(targetPath).getPath());
        info.type = "text/vcard";
        return info;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #2
Source File: StorageProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
protected AssetFileDescriptor openVideoThumbnailCleared(long id, CancellationSignal signal)
        throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    Cursor cursor = null;
    try {
        cursor = resolver.query(Video.Thumbnails.EXTERNAL_CONTENT_URI,
                VideoThumbnailQuery.PROJECTION, Video.Thumbnails.VIDEO_ID + "=" + id, null,
                null);
        if (cursor.moveToFirst()) {
            final String data = cursor.getString(VideoThumbnailQuery._DATA);
            return new AssetFileDescriptor(ParcelFileDescriptor.open(
                    new File(data), ParcelFileDescriptor.MODE_READ_ONLY), 0,
                    AssetFileDescriptor.UNKNOWN_LENGTH);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
    return null;
}
 
Example #3
Source File: StorageProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
protected AssetFileDescriptor openVideoThumbnailCleared(long id, CancellationSignal signal)
        throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    Cursor cursor = null;
    try {
        cursor = resolver.query(Video.Thumbnails.EXTERNAL_CONTENT_URI,
                VideoThumbnailQuery.PROJECTION, Video.Thumbnails.VIDEO_ID + "=" + id, null,
                null);
        if (cursor.moveToFirst()) {
            final String data = cursor.getString(VideoThumbnailQuery._DATA);
            return new AssetFileDescriptor(ParcelFileDescriptor.open(
                    new File(data), ParcelFileDescriptor.MODE_READ_ONLY), 0,
                    AssetFileDescriptor.UNKNOWN_LENGTH);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
    return null;
}
 
Example #4
Source File: CordovaResourceApi.java    From cordova-amazon-fireos with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #5
Source File: Game.java    From SchoolQuest with GNU General Public License v3.0 6 votes vote down vote up
public void changeBGM(final int newBGM, final int... pos) {
    BGMFader.stop(bgm, 400, new Runnable() {
        @Override
        public void run() {
            bgm.reset();

            bgmId = newBGM;
            AssetFileDescriptor afd = GameActivity.getInstance().getResources().
                    openRawResourceFd(bgmId);
            if (afd == null) return;

            try {
                bgm.setDataSource(
                        afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
                afd.close();
                bgm.prepare();
            } catch (IOException | IllegalStateException e) {
                e.printStackTrace();
            }

            bgm.setLooping(true);
            if (pos.length > 0) { bgm.seekTo(pos[0]); }
        }
    });
}
 
Example #6
Source File: FileUtils.java    From AndroidUtilCode with Apache License 2.0 6 votes vote down vote up
private static boolean isFileExistsApi29(String filePath) {
    if (Build.VERSION.SDK_INT >= 29) {
        try {
            Uri uri = Uri.parse(filePath);
            ContentResolver cr = Utils.getApp().getContentResolver();
            AssetFileDescriptor afd = cr.openAssetFileDescriptor(uri, "r");
            if (afd == null) return false;
            try {
                afd.close();
            } catch (IOException ignore) {
            }
        } catch (FileNotFoundException e) {
            return false;
        }
        return true;
    }
    return false;
}
 
Example #7
Source File: ContentUriUtils.java    From cronet with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Check whether a content URI exists.
 *
 * @param uriString the content URI to query.
 * @return true if the URI exists, or false otherwise.
 */
@CalledByNative
public static boolean contentUriExists(String uriString) {
    AssetFileDescriptor asf = null;
    try {
        asf = getAssetFileDescriptor(uriString);
        return asf != null;
    } finally {
        // Do not use StreamUtil.closeQuietly here, as AssetFileDescriptor
        // does not implement Closeable until KitKat.
        if (asf != null) {
            try {
                asf.close();
            } catch (IOException e) {
                // Closing quietly.
            }
        }
    }
}
 
Example #8
Source File: BeepManager.java    From reacteu-app with MIT License 6 votes vote down vote up
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() {
    @Override
    public void onCompletion(MediaPlayer player) {
      player.seekTo(0);
    }
  });

  AssetFileDescriptor file = activity.getResources().openRawResourceFd(fakeR.getId("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;
}
 
Example #9
Source File: DynamicWallPaper.java    From LiveWallPaper with Apache License 2.0 6 votes vote down vote up
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 #10
Source File: CordovaResourceApi.java    From ultimate-cordova-webview-app with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example #11
Source File: AlertPlugin.java    From microbit with Apache License 2.0 6 votes vote down vote up
public static int getDuration(MediaPlayer mediaPlayer, AssetFileDescriptor afd) {
    int duration = 500;

    try {
        mediaPlayer.reset();
        mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
        afd.close();
        mediaPlayer.prepare();
        duration = mediaPlayer.getDuration();
    } catch(IOException e) {
        Log.e(TAG, e.toString());
    }

    mediaPlayer.reset();

    return duration;
}
 
Example #12
Source File: Game.java    From SchoolQuest with GNU General Public License v3.0 6 votes vote down vote up
public void playJingle(int jingleId) {
    jingle.reset();

    bgm.setVolume(0, 0);

    AssetFileDescriptor afd = GameActivity.getInstance().getResources().
            openRawResourceFd(jingleId);
    if (afd == null) return;

    try {
        jingle.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
        afd.close();
        jingle.prepare();
    } catch (IOException e) {
        e.printStackTrace();
    }
    jingle.start();

    jingle.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            bgm.setVolume(1, 1);
        }
    });
}
 
Example #13
Source File: BeepManager.java    From AndroidWallet with GNU General Public License v3.0 6 votes vote down vote up
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;
    }
}
 
Example #14
Source File: SurfaceActivity.java    From AndroidOpenGLVideoDemo with Apache License 2.0 6 votes vote down vote up
private void startPlaying(SurfaceTexture surfaceTexture)
{
    renderer = new VideoTextureRenderer(surfaceTexture, surfaceWidth, surfaceHeight, videoTexture -> {
        // This runs on background thread as well.
        player = new MediaPlayer();
        try
        {
            AssetFileDescriptor afd = getAssets().openFd("big_buck_bunny.mp4");
            player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
            player.setSurface(new Surface(videoTexture));
            player.setLooping(true);
            player.prepare();
            renderer.setVideoSize(player.getVideoWidth(), player.getVideoHeight());
            player.start();

        }
        catch (IOException e)
        {
            throw new RuntimeException("Could not open input video!");
        }
    });
}
 
Example #15
Source File: United.java    From United4 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Makes a new sound pool, loads the requested sound and plays it once it's loaded
 * Could be made a LOT better by reusing the same pool and checking if it's already loaded
 *
 * @param file the sound to play
 */
public static void playSound(String file) {
    if (P.getBool("mute_sounds")) return;
    SoundPool pool = buildPool();
    try {
        AssetFileDescriptor fd = getContext().getAssets().openFd(file);
        pool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
            @Override
            public void onLoadComplete(SoundPool soundPool, int i, int i1) {
                soundPool.play(i, 1, 1, 1, 0, 1);
            }
        });
        pool.load(fd, 1);
    } catch (Exception ignored) {
        //
    }
}
 
Example #16
Source File: OBAudioManager.java    From GLEXP-Team-onebillion with Apache License 2.0 6 votes vote down vote up
public void startPlaying (String fileName, String channel)
{
    OBGeneralAudioPlayer player = playerForChannel(channel);
    if (fileName == null)
        player.stopPlaying();
    else
    {
        AssetFileDescriptor fd = getAudioPathFD(fileName);
        if (fd != null)
        {
            player.startPlaying(fd);
        }
        else
        {
            MainActivity.log("Error caught in OBAudioManager.startPlaying [" + fileName + "] returned a null file descriptor");
        }
    }
}
 
Example #17
Source File: OC_BedtimeStory.java    From GLEXP-Team-onebillion with Apache License 2.0 6 votes vote down vote up
public Boolean processAndPlayFile(String fileName)
{
    try
    {
        setStatus(STATUS_STARTING_FILE);
        player = new OBAudioBufferPlayer(true);
        AssetFileDescriptor afd = OBAudioManager.audioManager.getAudioPathFD(fileName);
        if (afd == null)
        {
            allFilesDone = true;
            return false;
        }
        player.startPlaying(afd);
    }
    catch (Exception e)
    {
        allFilesDone = true;
        return false;
    }
    return true;
}
 
Example #18
Source File: CordovaResourceApi.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example #19
Source File: CordovaResourceApi.java    From phonegapbootcampsite with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example #20
Source File: BeepManager.java    From BarcodeEye with Apache License 2.0 6 votes vote down vote up
private MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);

    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;
}
 
Example #21
Source File: CordovaResourceApi.java    From keemob with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example #22
Source File: CordovaResourceApi.java    From reader with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example #23
Source File: OC_PrepMWithVideo.java    From GLEXP-Team-onebillion with Apache License 2.0 6 votes vote down vote up
public void loadVideoPlayer()
{
    OBControl videoBox = objectDict.get("video_box");
    String videoFilePath = getLocalPath(String.format("%s.mp4",videoName));
    videoPlayer = new OBVideoPlayer(videoBox.frame(), this, false, false);
    AssetFileDescriptor afd = OBUtils.getAssetFileDescriptorForPath(videoFilePath);
    videoPlayer.prepareForPlaying(afd,0,null);
    videoPlayer.playAfterPrepare = false;
    videoPlayer.stopOnCompletion = false;
    videoBox.hide();
    videoPlayer.hide();
    attachControl(videoPlayer);
    OBPath path = (OBPath)objectDict.get("video_frame");
    path.sizeToBoundingBoxIncludingStroke();
    path.setZPosition(9);
    videoPlayer.setZPosition(10);
}
 
Example #24
Source File: TestTvInputService.java    From androidtv-sample-inputs with Apache License 2.0 6 votes vote down vote up
private boolean playMediaUrl(String mediaUrl) {
    getTvPlayer();
    Log.d(TAG, "Play " + mediaUrl);
    try {
        if (mediaUrl.startsWith("assets://")) {
            AssetFileDescriptor fileDescriptor = getAssets().openFd(mediaUrl.substring(9));
            mMockTvPlayer.playMediaFromAssets(fileDescriptor);
        } else {
            mMockTvPlayer.playMedia(mediaUrl);
        }
    } catch (IOException e) {
        e.printStackTrace();
        notifyVideoUnavailable(TvInputManager.VIDEO_UNAVAILABLE_REASON_UNKNOWN);
        return false;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_AVAILABLE);
    }
    notifyVideoAvailable();
    return true;
}
 
Example #25
Source File: Cocos2dxMusic.java    From Earlybird with Apache License 2.0 6 votes vote down vote up
/**
 * create mediaplayer for music
 * 
 * @param pPath
 *            the pPath relative to assets
 * @return
 */
private MediaPlayer createMediaplayer(final String pPath) {
	MediaPlayer mediaPlayer = new MediaPlayer();

	try {
		if (pPath.startsWith("/")) {
			final FileInputStream fis = new FileInputStream(pPath);
			mediaPlayer.setDataSource(fis.getFD());
			fis.close();
		} else {
			final AssetFileDescriptor assetFileDescritor = this.mContext.getAssets().openFd(pPath);
			mediaPlayer.setDataSource(assetFileDescritor.getFileDescriptor(), assetFileDescritor.getStartOffset(), assetFileDescritor.getLength());
		}

		mediaPlayer.prepare();

		mediaPlayer.setVolume(this.mLeftVolume, this.mRightVolume);
	} catch (final Exception e) {
		mediaPlayer = null;
		Log.e(Cocos2dxMusic.TAG, "error: " + e.getMessage(), e);
	}

	return mediaPlayer;
}
 
Example #26
Source File: SpeaktoitRecognitionServiceImpl.java    From dialogflow-android-client with Apache License 2.0 6 votes vote down vote up
@Override
public void cancel() {
    synchronized (recognizerLock) {
        if (isRecording) {
            audioRecord.stop();
            isRecording = false;

            final AssetFileDescriptor cancelSound = config.getRecognizerCancelSound();
            if (cancelSound != null) {
                playSound(cancelSound);
            }
        }
        if (recognizeTask != null) {
            recognizeTask.cancel(true);
        }
        onListeningCancelled();
    }
}
 
Example #27
Source File: SoundFile.java    From MusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
public static SoundFile create(long audioId, String dataColumn,
                               ProgressListener progressListener)
    throws java.io.FileNotFoundException,
           java.io.IOException, InvalidInputException {

    Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, String.valueOf(audioId));
    AssetFileDescriptor file;

    // will throw FileNotFoundException if file does not exist
    file = App.getInstance().getContentResolver().openAssetFileDescriptor(uri, "r");

    String name = dataColumn.toLowerCase();
    String[] components = name.split("\\.");
    if (components.length < 2) {
        return null;
    }
    if (!Arrays.asList(getSupportedExtensions()).contains(components[components.length - 1])) {
        return null;
    }
    SoundFile soundFile = new SoundFile();
    soundFile.setProgressListener(progressListener);
    soundFile.ParseFile(uri, file, dataColumn);
    return soundFile;
}
 
Example #28
Source File: StorageProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
protected AssetFileDescriptor openVideoThumbnailCleared(long id, CancellationSignal signal)
        throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    Cursor cursor = null;
    try {
        cursor = resolver.query(Video.Thumbnails.EXTERNAL_CONTENT_URI,
                VideoThumbnailQuery.PROJECTION, Video.Thumbnails.VIDEO_ID + "=" + id, null,
                null);
        if (cursor.moveToFirst()) {
            final String data = cursor.getString(VideoThumbnailQuery._DATA);
            return new AssetFileDescriptor(ParcelFileDescriptor.open(
                    new File(data), ParcelFileDescriptor.MODE_READ_ONLY), 0,
                    AssetFileDescriptor.UNKNOWN_LENGTH);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
    return null;
}
 
Example #29
Source File: CordovaResourceApi.java    From react-native-cordova with MIT License 5 votes vote down vote up
public OpenForReadResult(Uri uri, InputStream inputStream, String mimeType, long length, AssetFileDescriptor assetFd) {
    this.uri = uri;
    this.inputStream = inputStream;
    this.mimeType = mimeType;
    this.length = length;
    this.assetFd = assetFd;
}
 
Example #30
Source File: ExternalStorageProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@Override
public AssetFileDescriptor openDocumentThumbnail(
        String documentId, Point sizeHint, CancellationSignal signal)
        throws FileNotFoundException {
    if (mArchiveHelper.isArchivedDocument(documentId)) {
        return mArchiveHelper.openDocumentThumbnail(documentId, sizeHint, signal);
    }

    return openOrCreateDocumentThumbnail(documentId, sizeHint, signal);
}