Search in sources :

Example 6 with IllegalArgumentException

use of java.lang.IllegalArgumentException in project android_frameworks_base by ParanoidAndroid.

the class MediaSource method setupMediaPlayer.

/** Creates a media player, sets it up, and calls prepare */
private synchronized boolean setupMediaPlayer(boolean useUrl) {
    mPrepared = false;
    mGotSize = false;
    mPlaying = false;
    mPaused = false;
    mCompleted = false;
    mNewFrameAvailable = false;
    if (mLogVerbose)
        Log.v(TAG, "Setting up playback.");
    if (mMediaPlayer != null) {
        // Clean up existing media players
        if (mLogVerbose)
            Log.v(TAG, "Resetting existing MediaPlayer.");
        mMediaPlayer.reset();
    } else {
        // Create new media player
        if (mLogVerbose)
            Log.v(TAG, "Creating new MediaPlayer.");
        mMediaPlayer = new MediaPlayer();
    }
    if (mMediaPlayer == null) {
        throw new RuntimeException("Unable to create a MediaPlayer!");
    }
    // Set up data sources, etc
    try {
        if (useUrl) {
            if (mLogVerbose)
                Log.v(TAG, "Setting MediaPlayer source to URI " + mSourceUrl);
            if (mContext == null) {
                mMediaPlayer.setDataSource(mSourceUrl);
            } else {
                mMediaPlayer.setDataSource(mContext, Uri.parse(mSourceUrl.toString()));
            }
        } else {
            if (mLogVerbose)
                Log.v(TAG, "Setting MediaPlayer source to asset " + mSourceAsset);
            mMediaPlayer.setDataSource(mSourceAsset.getFileDescriptor(), mSourceAsset.getStartOffset(), mSourceAsset.getLength());
        }
    } catch (IOException e) {
        mMediaPlayer.release();
        mMediaPlayer = null;
        if (useUrl) {
            throw new RuntimeException(String.format("Unable to set MediaPlayer to URL %s!", mSourceUrl), e);
        } else {
            throw new RuntimeException(String.format("Unable to set MediaPlayer to asset %s!", mSourceAsset), e);
        }
    } catch (IllegalArgumentException e) {
        mMediaPlayer.release();
        mMediaPlayer = null;
        if (useUrl) {
            throw new RuntimeException(String.format("Unable to set MediaPlayer to URL %s!", mSourceUrl), e);
        } else {
            throw new RuntimeException(String.format("Unable to set MediaPlayer to asset %s!", mSourceAsset), e);
        }
    }
    mMediaPlayer.setLooping(mLooping);
    mMediaPlayer.setVolume(mVolume, mVolume);
    // Bind it to our media frame
    Surface surface = new Surface(mSurfaceTexture);
    mMediaPlayer.setSurface(surface);
    surface.release();
    // Connect Media Player to callbacks
    mMediaPlayer.setOnVideoSizeChangedListener(onVideoSizeChangedListener);
    mMediaPlayer.setOnPreparedListener(onPreparedListener);
    mMediaPlayer.setOnCompletionListener(onCompletionListener);
    // Connect SurfaceTexture to callback
    mSurfaceTexture.setOnFrameAvailableListener(onMediaFrameAvailableListener);
    if (mLogVerbose)
        Log.v(TAG, "Preparing MediaPlayer.");
    mMediaPlayer.prepareAsync();
    return true;
}
Also used : IOException(java.io.IOException) IllegalArgumentException(java.lang.IllegalArgumentException) MediaPlayer(android.media.MediaPlayer) Surface(android.view.Surface)

Example 7 with IllegalArgumentException

use of java.lang.IllegalArgumentException in project robovm by robovm.

the class RC2ParameterSpecTest method testRC2ParameterSpec1.

/**
     * RC2ParameterSpec(int effectiveKeyBits, byte[] iv) method testing.
     * Tests that IllegalArgumentException is thrown in the case of
     * inappropriate constructor parameters and that input iv array is
     * copied to protect against subsequent modification.
     */
public void testRC2ParameterSpec1() {
    int effectiveKeyBits = 10;
    byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8 };
    try {
        new RC2ParameterSpec(effectiveKeyBits, null);
        fail("An IllegalArgumentException should be thrown " + "in the case of null iv.");
    } catch (IllegalArgumentException e) {
    }
    try {
        new RC2ParameterSpec(effectiveKeyBits, new byte[] { 1, 2, 3, 4, 5 });
        fail("An IllegalArgumentException should be thrown " + "in the case of short iv.");
    } catch (IllegalArgumentException e) {
    }
    RC2ParameterSpec ps = new RC2ParameterSpec(effectiveKeyBits, iv);
    iv[0]++;
    assertFalse("The change of iv specified in the constructor " + "should not cause the change of internal array.", iv[0] == ps.getIV()[0]);
}
Also used : RC2ParameterSpec(javax.crypto.spec.RC2ParameterSpec) IllegalArgumentException(java.lang.IllegalArgumentException)

Example 8 with IllegalArgumentException

use of java.lang.IllegalArgumentException in project platform_frameworks_base by android.

the class MediaSource method setupMediaPlayer.

/** Creates a media player, sets it up, and calls prepare */
private synchronized boolean setupMediaPlayer(boolean useUrl) {
    mPrepared = false;
    mGotSize = false;
    mPlaying = false;
    mPaused = false;
    mCompleted = false;
    mNewFrameAvailable = false;
    if (mLogVerbose)
        Log.v(TAG, "Setting up playback.");
    if (mMediaPlayer != null) {
        // Clean up existing media players
        if (mLogVerbose)
            Log.v(TAG, "Resetting existing MediaPlayer.");
        mMediaPlayer.reset();
    } else {
        // Create new media player
        if (mLogVerbose)
            Log.v(TAG, "Creating new MediaPlayer.");
        mMediaPlayer = new MediaPlayer();
    }
    if (mMediaPlayer == null) {
        throw new RuntimeException("Unable to create a MediaPlayer!");
    }
    // Set up data sources, etc
    try {
        if (useUrl) {
            if (mLogVerbose)
                Log.v(TAG, "Setting MediaPlayer source to URI " + mSourceUrl);
            if (mContext == null) {
                mMediaPlayer.setDataSource(mSourceUrl);
            } else {
                mMediaPlayer.setDataSource(mContext, Uri.parse(mSourceUrl.toString()));
            }
        } else {
            if (mLogVerbose)
                Log.v(TAG, "Setting MediaPlayer source to asset " + mSourceAsset);
            mMediaPlayer.setDataSource(mSourceAsset.getFileDescriptor(), mSourceAsset.getStartOffset(), mSourceAsset.getLength());
        }
    } catch (IOException e) {
        mMediaPlayer.release();
        mMediaPlayer = null;
        if (useUrl) {
            throw new RuntimeException(String.format("Unable to set MediaPlayer to URL %s!", mSourceUrl), e);
        } else {
            throw new RuntimeException(String.format("Unable to set MediaPlayer to asset %s!", mSourceAsset), e);
        }
    } catch (IllegalArgumentException e) {
        mMediaPlayer.release();
        mMediaPlayer = null;
        if (useUrl) {
            throw new RuntimeException(String.format("Unable to set MediaPlayer to URL %s!", mSourceUrl), e);
        } else {
            throw new RuntimeException(String.format("Unable to set MediaPlayer to asset %s!", mSourceAsset), e);
        }
    }
    mMediaPlayer.setLooping(mLooping);
    mMediaPlayer.setVolume(mVolume, mVolume);
    // Bind it to our media frame
    Surface surface = new Surface(mSurfaceTexture);
    mMediaPlayer.setSurface(surface);
    surface.release();
    // Connect Media Player to callbacks
    mMediaPlayer.setOnVideoSizeChangedListener(onVideoSizeChangedListener);
    mMediaPlayer.setOnPreparedListener(onPreparedListener);
    mMediaPlayer.setOnCompletionListener(onCompletionListener);
    // Connect SurfaceTexture to callback
    mSurfaceTexture.setOnFrameAvailableListener(onMediaFrameAvailableListener);
    if (mLogVerbose)
        Log.v(TAG, "Preparing MediaPlayer.");
    mMediaPlayer.prepareAsync();
    return true;
}
Also used : IOException(java.io.IOException) IllegalArgumentException(java.lang.IllegalArgumentException) MediaPlayer(android.media.MediaPlayer) Surface(android.view.Surface)

Example 9 with IllegalArgumentException

use of java.lang.IllegalArgumentException in project translationstudio8 by heartsome.

the class FastIntBuffer method getIntArray.

/**
 * Returns a single int array representing every int in this buffer instance
 * @return int[]  (null if there isn't anything left in the buffer   
 * @param startingOffset int
 * @param len int
 * @return int[]
 */
public int[] getIntArray(int startingOffset, int len) {
    if (size <= 0 || startingOffset < 0) {
        throw (new IllegalArgumentException());
    }
    if ((startingOffset + len) > size) {
        throw (new IndexOutOfBoundsException());
    }
    // allocate result array
    int[] result = new int[len];
    //    int first_index = (int) (startingOffset / pageSize);
    //    int last_index = (int) ((startingOffset + len) / pageSize);
    //    if ((startingOffset + len) % pageSize == 0) {
    //        last_index--;
    //    }
    int first_index = startingOffset >> exp;
    int last_index = (startingOffset + len) >> exp;
    if (((startingOffset + len) & r) == 0) {
        last_index--;
    }
    if (first_index == last_index) {
        // to see if there is a need to go across buffer boundry
        System.arraycopy((int[]) (bufferArrayList.get(first_index)), //            startingOffset % pageSize,
        startingOffset & r, result, 0, len);
    } else {
        int int_array_offset = 0;
        for (int i = first_index; i <= last_index; i++) {
            int[] currentChunk = (int[]) bufferArrayList.get(i);
            if (// first section
            i == first_index) {
                System.arraycopy(currentChunk, //                  startingOffset % pageSize,
                startingOffset & r, result, 0, //                  pageSize - (startingOffset % pageSize));
                pageSize - (startingOffset & r));
                //                int_array_offset += pageSize - (startingOffset) % pageSize;
                int_array_offset += pageSize - (startingOffset & r);
            } else if (// last sections
            i == last_index) {
                System.arraycopy(currentChunk, 0, result, int_array_offset, len - int_array_offset);
            } else {
                System.arraycopy(currentChunk, 0, result, int_array_offset, pageSize);
                int_array_offset += pageSize;
            }
        }
    }
    return result;
}
Also used : IndexOutOfBoundsException(java.lang.IndexOutOfBoundsException) IllegalArgumentException(java.lang.IllegalArgumentException)

Example 10 with IllegalArgumentException

use of java.lang.IllegalArgumentException in project translationstudio8 by heartsome.

the class FastLongBuffer method getLongArray.

/**
 * Return a selected chuck of long buffer as a long array.
 * @return long[]
 * @param startingOffset int
 * @param len int
 */
public long[] getLongArray(int startingOffset, int len) {
    if (size <= 0 || startingOffset < 0) {
        throw (new IllegalArgumentException());
    }
    if ((startingOffset + len) > size) {
        throw (new IndexOutOfBoundsException());
    }
    // allocate result array
    long[] result = new long[len];
    int first_index = (startingOffset >> exp);
    int last_index = ((startingOffset + len) >> exp);
    //if ((startingOffset + len) % pageSize == 0) {
    if (((startingOffset + len) & r) == 0) {
        last_index--;
    }
    if (first_index == last_index) {
        // to see if there is a need to go across buffer boundry
        System.arraycopy((long[]) (bufferArrayList.oa[first_index]), //            startingOffset % pageSize,
        startingOffset & r, result, 0, len);
    } else {
        int long_array_offset = 0;
        for (int i = first_index; i <= last_index; i++) {
            long[] currentChunk = (long[]) bufferArrayList.oa[i];
            if (// first section
            i == first_index) {
                System.arraycopy(currentChunk, //                  startingOffset % pageSize,
                startingOffset & r, result, 0, //                  pageSize - (startingOffset % r));
                pageSize - (startingOffset & r));
                long_array_offset += pageSize - (startingOffset & r);
            } else if (// last sections
            i == last_index) {
                System.arraycopy(currentChunk, 0, result, long_array_offset, len - long_array_offset);
            } else {
                System.arraycopy(currentChunk, 0, result, long_array_offset, pageSize);
                long_array_offset += pageSize;
            }
        }
    }
    return result;
}
Also used : IndexOutOfBoundsException(java.lang.IndexOutOfBoundsException) IllegalArgumentException(java.lang.IllegalArgumentException)

Aggregations

IllegalArgumentException (java.lang.IllegalArgumentException)30 MediaPlayer (android.media.MediaPlayer)6 Surface (android.view.Surface)6 IOException (java.io.IOException)6 IndexOutOfBoundsException (java.lang.IndexOutOfBoundsException)4 RC2ParameterSpec (javax.crypto.spec.RC2ParameterSpec)2 ArrayIndexOutOfBoundsException (java.lang.ArrayIndexOutOfBoundsException)1 Integer (java.lang.Integer)1 NullPointerException (java.lang.NullPointerException)1 URI (java.net.URI)1 SimpleDateFormat (java.text.SimpleDateFormat)1 IvParameterSpec (javax.crypto.spec.IvParameterSpec)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 JobConf (org.apache.hadoop.mapred.JobConf)1