summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorAndy Hung <hunga@google.com>2015-06-17 19:21:50 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-06-17 19:21:53 +0000
commit90b3b93de460ccd1fc1116154f5d61bd2bc93d25 (patch)
tree6f13b8eb1cd850496b8260a05e1a2719e640fce5 /media
parenta56eadb2737288091dc111a886ae83ae066317fa (diff)
parent2d2d89363f0b794cbb63f389584fa4c5557ff51a (diff)
downloadframeworks_base-90b3b93de460ccd1fc1116154f5d61bd2bc93d25.zip
frameworks_base-90b3b93de460ccd1fc1116154f5d61bd2bc93d25.tar.gz
frameworks_base-90b3b93de460ccd1fc1116154f5d61bd2bc93d25.tar.bz2
Merge "AudioTrack.Builder should throw exception on failure." into mnc-dev
Diffstat (limited to 'media')
-rw-r--r--media/java/android/media/AudioTrack.java13
1 files changed, 10 insertions, 3 deletions
diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java
index f395cb3..62810c6 100644
--- a/media/java/android/media/AudioTrack.java
+++ b/media/java/android/media/AudioTrack.java
@@ -661,9 +661,10 @@ public class AudioTrack
/**
* Builds an {@link AudioTrack} instance initialized with all the parameters set
* on this <code>Builder</code>.
- * @return a new {@link AudioTrack} instance.
+ * @return a new successfully initialized {@link AudioTrack} instance.
* @throws UnsupportedOperationException if the parameters set on the <code>Builder</code>
- * were incompatible, or if they are not supported by the device.
+ * were incompatible, or if they are not supported by the device,
+ * or if the device was not available.
*/
public @NonNull AudioTrack build() throws UnsupportedOperationException {
if (mAttributes == null) {
@@ -686,7 +687,13 @@ public class AudioTrack
mBufferSizeInBytes = mFormat.getChannelCount()
* mFormat.getBytesPerSample(mFormat.getEncoding());
}
- return new AudioTrack(mAttributes, mFormat, mBufferSizeInBytes, mMode, mSessionId);
+ final AudioTrack track = new AudioTrack(
+ mAttributes, mFormat, mBufferSizeInBytes, mMode, mSessionId);
+ if (track.getState() == STATE_UNINITIALIZED) {
+ // release is not necessary
+ throw new UnsupportedOperationException("Cannot create AudioTrack");
+ }
+ return track;
} catch (IllegalArgumentException e) {
throw new UnsupportedOperationException(e.getMessage());
}