summaryrefslogtreecommitdiffstats
path: root/variablespeed/src/com/android/ex
diff options
context:
space:
mode:
authorFlavio Lerda <flerda@google.com>2011-08-31 15:49:53 +0100
committerFlavio Lerda <flerda@google.com>2011-09-01 12:23:19 +0100
commitdc442b4d99512bf7c41ee5ceae6c93a3c3568b57 (patch)
treeeb6fdb06d27051aeb9b780f5b0074b537d49cb32 /variablespeed/src/com/android/ex
parentaabf88787c8edb2cc207ad8e94e2045bf727c60d (diff)
downloadandroid_frameworks_ex-dc442b4d99512bf7c41ee5ceae6c93a3c3568b57.tar.gz
android_frameworks_ex-dc442b4d99512bf7c41ee5ceae6c93a3c3568b57.tar.bz2
android_frameworks_ex-dc442b4d99512bf7c41ee5ceae6c93a3c3568b57.zip
Allows selecting the audio stream used for playback.
Adds setAudioStreamType() to the MediaPlayerProxy interface and implements it in the variable speed player. Bug: 5240848 Change-Id: I1bb9fdbee7aa6113c5d5d5a8000e9794800fad9f
Diffstat (limited to 'variablespeed/src/com/android/ex')
-rw-r--r--variablespeed/src/com/android/ex/variablespeed/EngineParameters.java19
-rw-r--r--variablespeed/src/com/android/ex/variablespeed/MediaPlayerProxy.java1
-rw-r--r--variablespeed/src/com/android/ex/variablespeed/SingleThreadedMediaPlayerProxy.java5
-rw-r--r--variablespeed/src/com/android/ex/variablespeed/VariableSpeed.java15
-rw-r--r--variablespeed/src/com/android/ex/variablespeed/VariableSpeedNative.java4
5 files changed, 39 insertions, 5 deletions
diff --git a/variablespeed/src/com/android/ex/variablespeed/EngineParameters.java b/variablespeed/src/com/android/ex/variablespeed/EngineParameters.java
index e57e9f9..1cc4012 100644
--- a/variablespeed/src/com/android/ex/variablespeed/EngineParameters.java
+++ b/variablespeed/src/com/android/ex/variablespeed/EngineParameters.java
@@ -16,6 +16,8 @@
package com.android.ex.variablespeed;
+import android.media.AudioManager;
+
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
@@ -35,6 +37,7 @@ import javax.annotation.concurrent.NotThreadSafe;
private final int mDecodeBufferInitialSize;
private final int mDecodeBufferMaxSize;
private final int mStartPositionMillis;
+ private final int mAudioStreamType;
public int getTargetFrames() {
return mTargetFrames;
@@ -68,9 +71,13 @@ import javax.annotation.concurrent.NotThreadSafe;
return mStartPositionMillis;
}
+ public int getAudioStreamType() {
+ return mAudioStreamType;
+ }
+
private EngineParameters(int targetFrames, int maxPlayBufferCount, float windowDuration,
float windowOverlapDuration, float initialRate, int decodeBufferInitialSize,
- int decodeBufferMaxSize, int startPositionMillis) {
+ int decodeBufferMaxSize, int startPositionMillis, int audioStreamType) {
mTargetFrames = targetFrames;
mMaxPlayBufferCount = maxPlayBufferCount;
mWindowDuration = windowDuration;
@@ -79,6 +86,7 @@ import javax.annotation.concurrent.NotThreadSafe;
mDecodeBufferInitialSize = decodeBufferInitialSize;
mDecodeBufferMaxSize = decodeBufferMaxSize;
mStartPositionMillis = startPositionMillis;
+ mAudioStreamType = audioStreamType;
}
/**
@@ -98,11 +106,13 @@ import javax.annotation.concurrent.NotThreadSafe;
private int mDecodeBufferInitialSize = 5 * 1024;
private int mDecodeBufferMaxSize = 20 * 1024;
private int mStartPositionMillis = 0;
+ private int mAudioStreamType = AudioManager.STREAM_MUSIC;
public EngineParameters build() {
return new EngineParameters(mTargetFrames, mMaxPlayBufferCount,
mWindowDuration, mWindowOverlapDuration, mInitialRate,
- mDecodeBufferInitialSize, mDecodeBufferMaxSize, mStartPositionMillis);
+ mDecodeBufferInitialSize, mDecodeBufferMaxSize, mStartPositionMillis,
+ mAudioStreamType);
}
public Builder maxPlayBufferCount(int maxPlayBufferCount) {
@@ -139,5 +149,10 @@ import javax.annotation.concurrent.NotThreadSafe;
mStartPositionMillis = startPositionMillis;
return this;
}
+
+ public Builder audioStreamType(int audioStreamType) {
+ mAudioStreamType = audioStreamType;
+ return this;
+ }
}
}
diff --git a/variablespeed/src/com/android/ex/variablespeed/MediaPlayerProxy.java b/variablespeed/src/com/android/ex/variablespeed/MediaPlayerProxy.java
index 76492c1..8489dc1 100644
--- a/variablespeed/src/com/android/ex/variablespeed/MediaPlayerProxy.java
+++ b/variablespeed/src/com/android/ex/variablespeed/MediaPlayerProxy.java
@@ -45,4 +45,5 @@ public interface MediaPlayerProxy {
boolean isPlaying();
int getCurrentPosition();
void pause();
+ void setAudioStreamType(int streamType);
}
diff --git a/variablespeed/src/com/android/ex/variablespeed/SingleThreadedMediaPlayerProxy.java b/variablespeed/src/com/android/ex/variablespeed/SingleThreadedMediaPlayerProxy.java
index 035bc0e..17692f7 100644
--- a/variablespeed/src/com/android/ex/variablespeed/SingleThreadedMediaPlayerProxy.java
+++ b/variablespeed/src/com/android/ex/variablespeed/SingleThreadedMediaPlayerProxy.java
@@ -102,4 +102,9 @@ public class SingleThreadedMediaPlayerProxy implements MediaPlayerProxy {
public synchronized void pause() {
mDelegate.pause();
}
+
+ @Override
+ public void setAudioStreamType(int streamType) {
+ mDelegate.setAudioStreamType(streamType);
+ }
}
diff --git a/variablespeed/src/com/android/ex/variablespeed/VariableSpeed.java b/variablespeed/src/com/android/ex/variablespeed/VariableSpeed.java
index 1f86a95..5c93d26 100644
--- a/variablespeed/src/com/android/ex/variablespeed/VariableSpeed.java
+++ b/variablespeed/src/com/android/ex/variablespeed/VariableSpeed.java
@@ -64,6 +64,7 @@ public class VariableSpeed implements MediaPlayerProxy {
@GuardedBy("lock") private float mCurrentPlaybackRate = 1.0f;
@GuardedBy("lock") private int mDuration;
@GuardedBy("lock") private MediaPlayer.OnCompletionListener mCompletionListener;
+ @GuardedBy("lock") private int mAudioStreamType;
private VariableSpeed(Executor executor) throws UnsupportedOperationException {
Preconditions.checkNotNull(executor);
@@ -213,15 +214,18 @@ public class VariableSpeed implements MediaPlayerProxy {
@Override
public void prepare() throws IOException {
MediaPlayerDataSource dataSource;
+ int audioStreamType;
synchronized (lock) {
check(!mHasBeenReleased, "has been released, reset before use");
check(mDataSource != null, "must setDataSource before you prepare");
check(!mIsPrepared, "cannot prepare more than once");
mIsPrepared = true;
dataSource = mDataSource;
+ audioStreamType = mAudioStreamType;
}
// NYI This should become another executable that we can wait on.
MediaPlayer mediaPlayer = new MediaPlayer();
+ mediaPlayer.setAudioStreamType(audioStreamType);
dataSource.setAsSourceFor(mediaPlayer);
mediaPlayer.prepare();
synchronized (lock) {
@@ -286,7 +290,9 @@ public class VariableSpeed implements MediaPlayerProxy {
mHasStartedPlayback = true;
EngineParameters engineParameters = new EngineParameters.Builder()
.initialRate(mCurrentPlaybackRate)
- .startPositionMillis(mStartPosition).build();
+ .startPositionMillis(mStartPosition)
+ .audioStreamType(mAudioStreamType)
+ .build();
VariableSpeedNative.initializeEngine(engineParameters);
VariableSpeedNative.startPlayback();
mEngineInitializedLatch.countDown();
@@ -387,4 +393,11 @@ public class VariableSpeed implements MediaPlayerProxy {
throw new IllegalArgumentException(argumentName + " must not be null");
}
}
+
+ @Override
+ public void setAudioStreamType(int audioStreamType) {
+ synchronized (lock) {
+ mAudioStreamType = audioStreamType;
+ }
+ }
}
diff --git a/variablespeed/src/com/android/ex/variablespeed/VariableSpeedNative.java b/variablespeed/src/com/android/ex/variablespeed/VariableSpeedNative.java
index ed7e80b..07195db 100644
--- a/variablespeed/src/com/android/ex/variablespeed/VariableSpeedNative.java
+++ b/variablespeed/src/com/android/ex/variablespeed/VariableSpeedNative.java
@@ -82,11 +82,11 @@ import java.lang.reflect.Field;
params.getWindowDuration(), params.getWindowOverlapDuration(),
params.getMaxPlayBufferCount(), params.getInitialRate(),
params.getDecodeBufferInitialSize(), params.getDecodeBufferMaxSize(),
- params.getStartPositionMillis());
+ params.getStartPositionMillis(), params.getAudioStreamType());
}
private static native void initializeEngine(int targetFrames,
float windowDuration, float windowOverlapDuration, int maxPlayBufferCount,
float initialRate, int decodeBufferInitialSize, int decodeBufferMaxSize,
- int startPositionMillis);
+ int startPositionMillis, int audioStreamType);
}