use of java.lang.IllegalArgumentException in project android_frameworks_base by ResurrectionRemix.
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;
}
use of java.lang.IllegalArgumentException in project android_frameworks_opt_telephony by LineageOS.
the class SubscriptionMonitor method registerForDefaultDataSubscriptionChanged.
public void registerForDefaultDataSubscriptionChanged(int phoneId, Handler h, int what, Object o) {
if (invalidPhoneId(phoneId)) {
throw new IllegalArgumentException("Invalid PhoneId");
}
Registrant r = new Registrant(h, what, o);
mDefaultDataSubChangedRegistrants[phoneId].add(r);
r.notifyRegistrant();
}
use of java.lang.IllegalArgumentException in project commoncrawl-examples by commoncrawl.
the class ArcRecord method setArcRecordHeader.
/**
* <p>Parses and sets the ARC record header fields.</p>
* <p>Currently, this method expects the ARC record header string to contain
* the following fields, in order, separated by space:
* <ul>
* <li>URL</li>
* <li>IP Address</li>
* <li>Archive Date</li>
* <li>Content Type</li>
* <li>Content Length</li>
* </ul>
* </p>
* <p>For more information on the arc file format, see
* {@link http://www.archive.org/web/researcher/ArcFileFormat.php}.</p>
*
* @param arcRecordHeader The first line of an ARC file entry - the header
* line for an ARC file item.
*/
public void setArcRecordHeader(String arcRecordHeader) throws IllegalArgumentException, ParseException {
if (arcRecordHeader == null || arcRecordHeader.equals(""))
throw new IllegalArgumentException("ARC v1 record header string is empty.");
String[] metadata = arcRecordHeader.split(" ");
if (metadata.length != 5) {
LOG.info(" [ " + arcRecordHeader + " ] ");
throw new IllegalArgumentException("ARC v1 record header must be 5 fields.");
}
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
this._url = metadata[0];
this._ipAddress = metadata[1];
this._archiveDate = format.parse(metadata[2]);
this._contentType = metadata[3];
this._contentLength = (new Integer(metadata[4])).intValue();
}
use of java.lang.IllegalArgumentException in project commoncrawl-examples by commoncrawl.
the class ArcRecord method setPayload.
/**
* <p>Reads and sets the ARC record payload from an input stream.</p>
*
* @param in An input stream positioned at the start of the ARC record payload.
*/
public void setPayload(InputStream in) throws IllegalArgumentException, ParseException, IOException {
if (in == null)
throw new IllegalArgumentException("ArcRecord cannot be created from NULL/missing input stream.");
int bufferSize = this._contentLength;
this._payload = new byte[bufferSize];
int n = in.read(this._payload, 0, this._payload.length);
if (n < this._payload.length) {
LOG.warn("Expecting " + bufferSize + " bytes in ARC record payload, found " + n + " bytes. Performing array copy.");
this._payload = Arrays.copyOf(this._payload, n);
}
// After this, we should be at the end of this GZIP member. Let the
// calling function verify the position of the stream.
}
use of java.lang.IllegalArgumentException in project j2objc by google.
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]);
}
Aggregations