Search in sources :

Example 11 with AssetFileDescriptor

use of android.content.res.AssetFileDescriptor in project VideoPlayerManager by danylovolokh.

the class MediaPlayerWrapperStopTest method testStopStopped.

@Test
public void testStopStopped() throws Exception {
    mMediaPlayerWrapper.setDataSource(new AssetFileDescriptor(ParcelFileDescriptor.adoptFd(0), 0, 0));
    mMediaPlayerWrapper.prepare();
    mMediaPlayerWrapper.start();
    mMediaPlayerWrapper.stop();
    assertEquals(MediaPlayerWrapper.State.STOPPED, mMediaPlayerWrapper.getCurrentState());
    tryToFailStop(MediaPlayerWrapper.State.STOPPED);
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) Test(org.junit.Test)

Example 12 with AssetFileDescriptor

use of android.content.res.AssetFileDescriptor in project VideoPlayerManager by danylovolokh.

the class MediaPlayerWrapperStopTest method testStopInitialized.

@Test
public void testStopInitialized() throws Exception {
    mMediaPlayerWrapper.setDataSource(new AssetFileDescriptor(ParcelFileDescriptor.adoptFd(0), 0, 0));
    assertEquals(MediaPlayerWrapper.State.INITIALIZED, mMediaPlayerWrapper.getCurrentState());
    tryToFailStop(MediaPlayerWrapper.State.INITIALIZED);
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) Test(org.junit.Test)

Example 13 with AssetFileDescriptor

use of android.content.res.AssetFileDescriptor in project android-app by eoecn.

the class CaptureActivity method initBeepSound.

/**
     * 扫描正确后的震动声音,如果感觉apk大了,可以删除
     */
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;
        }
    }
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) IOException(java.io.IOException) MediaPlayer(android.media.MediaPlayer)

Example 14 with AssetFileDescriptor

use of android.content.res.AssetFileDescriptor in project android_frameworks_base by ParanoidAndroid.

the class ContentProviderProxy method openAssetFile.

public AssetFileDescriptor openAssetFile(String callingPkg, Uri url, String mode) throws RemoteException, FileNotFoundException {
    Parcel data = Parcel.obtain();
    Parcel reply = Parcel.obtain();
    try {
        data.writeInterfaceToken(IContentProvider.descriptor);
        data.writeString(callingPkg);
        url.writeToParcel(data, 0);
        data.writeString(mode);
        mRemote.transact(IContentProvider.OPEN_ASSET_FILE_TRANSACTION, data, reply, 0);
        DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(reply);
        int has = reply.readInt();
        AssetFileDescriptor fd = has != 0 ? AssetFileDescriptor.CREATOR.createFromParcel(reply) : null;
        return fd;
    } finally {
        data.recycle();
        reply.recycle();
    }
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) Parcel(android.os.Parcel)

Example 15 with AssetFileDescriptor

use of android.content.res.AssetFileDescriptor in project android_frameworks_base by ParanoidAndroid.

the class SoundPool method load.

/**
     * Load the sound from the specified APK resource.
     *
     * Note that the extension is dropped. For example, if you want to load
     * a sound from the raw resource file "explosion.mp3", you would specify
     * "R.raw.explosion" as the resource ID. Note that this means you cannot
     * have both an "explosion.wav" and an "explosion.mp3" in the res/raw
     * directory.
     * 
     * @param context the application context
     * @param resId the resource ID
     * @param priority the priority of the sound. Currently has no effect. Use
     *                 a value of 1 for future compatibility.
     * @return a sound ID. This value can be used to play or unload the sound.
     */
public int load(Context context, int resId, int priority) {
    AssetFileDescriptor afd = context.getResources().openRawResourceFd(resId);
    int id = 0;
    if (afd != null) {
        id = _load(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength(), priority);
        try {
            afd.close();
        } catch (java.io.IOException ex) {
        //Log.d(TAG, "close failed:", ex);
        }
    }
    return id;
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) IOException(java.io.IOException)

Aggregations

AssetFileDescriptor (android.content.res.AssetFileDescriptor)187 IOException (java.io.IOException)98 ParcelFileDescriptor (android.os.ParcelFileDescriptor)49 FileNotFoundException (java.io.FileNotFoundException)41 Test (org.junit.Test)28 MediaPlayer (android.media.MediaPlayer)27 ContentResolver (android.content.ContentResolver)26 RemoteException (android.os.RemoteException)19 File (java.io.File)18 FileInputStream (java.io.FileInputStream)16 Nullable (android.annotation.Nullable)15 Parcel (android.os.Parcel)14 Bitmap (android.graphics.Bitmap)13 FileDescriptor (java.io.FileDescriptor)13 DeadObjectException (android.os.DeadObjectException)12 Resources (android.content.res.Resources)11 FileOutputStream (java.io.FileOutputStream)11 InputStream (java.io.InputStream)11 Uri (android.net.Uri)10 Bundle (android.os.Bundle)10