在以前的框架基础上加入光学变焦和蓝牙麦克风采集音频
目前两个功能都已经加入了。在spydroid 8.0版本对音视频同步做得比较好,暂且使用8.0版本的源代码。
蓝牙采集音频修改内容:
AACStream.java
public AACStream() throws IOException {
super();
mPacketizer = new AACADTSPacketizer();
setAudioSource(MediaRecorder.AudioSource.DEFAULT); //modify
try {
Field deprecatedName = MediaRecorder.OutputFormat.class.getField("AAC_ADTS");
setOutputFormat(deprecatedName.getInt(null));
} catch (Exception e) {
throw new AACNotSupportedException();
}
setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
setAudioSamplingRate(16000);
}
AudioStream.java
public void prepare() throws IllegalStateException, IOException {
// Resets the recorder in case it is in a bad state
mMediaRecorder.reset();
mMediaRecorder.setAudioSource(mAudioSource);
mMediaRecorder.setOutputFormat(mOutputFormat);
mMediaRecorder.setAudioEncoder(mAudioEncoder);
mMediaRecorder.setAudioChannels(1);
mMediaRecorder.setAudioSamplingRate(mSamplingRate);
/*
* add
*/
try {
super.prepare();
} catch (Exception e) {
Log.i("BlueT", "prepare() failed");
}
if (!SpydroidActivity.instance.mAudioManager.isBluetoothScoAvailableOffCall()) {
Log.i("BlueT", "No support bluetooth");
return;
}
Log.i("BlueT", "support bluetooth");
SpydroidActivity.instance.mAudioManager.stopBluetoothSco();
SpydroidActivity.instance.mAudioManager.startBluetoothSco();
/*
* add
*/
try {
Thread.sleep(1000);
} catch (Exception e) {
// TODO: handle exception
}
SpydroidActivity.instance.mAudioManager.setBluetoothScoOn(true);
Log.i("BlueT", "Routing:" + SpydroidActivity.instance.mAudioManager.isBluetoothScoOn());
SpydroidActivity.instance.mAudioManager.setMode(AudioManager.STREAM_MUSIC);
}
}
加上权限:
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BROADCAST_STICKY"/>
光学变焦修改内容:
public android.hardware.Camera mCamera = null; //add
public static SpydroidActivity instance = null; //add
public AudioManager mAudioManager = null; //add
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
switch (keyCode) {
case KeyEvent.KEYCODE_ZOOM_IN:
Log.i("ZOOM", "放大");
setZoom1();
break;
case KeyEvent.KEYCODE_ZOOM_OUT:
Log.i("ZOOM", "缩小");
setZoom2();
break;
default:
break;
}
return super.onKeyDown(keyCode, event);
}
public boolean isSupportZoom()
{
boolean isSuppport = false;
if (mCamera.getParameters().isZoomSupported())
{
isSuppport = true;
}
return isSuppport;
}
public void setZoom1()
{
if (isSupportZoom())
{
try
{
Parameters params = mCamera.getParameters();
final int MAX = params.getMaxZoom();
int zoomValue = params.getZoom();
Log.i("ZOOM", "-----------------MAX:"+MAX+" params : "+zoomValue);
if (zoomValue <= 14) {
zoomValue += 1;
params.setZoom(zoomValue);
mCamera.setParameters(params);
}
Log.i("ZOOM", "Is support Zoom " + params.isZoomSupported());
}
catch (Exception e)
{
Log.i("ZOOM", "--------exception zoom");
e.printStackTrace();
}
}
else
{
Log.i("ZOOM", "--------the phone not support zoom");
}
}
public void setZoom2()
{
if (isSupportZoom())
{
try
{
Parameters params = mCamera.getParameters();
final int MAX = params.getMaxZoom();
int zoomValue = params.getZoom();
Log.i("ZOOM", "-----------------MAX:"+MAX+" params : "+zoomValue);
if (zoomValue >= 1) {
zoomValue -= 1;
params.setZoom(zoomValue);
mCamera.setParameters(params);
}
Log.i("ZOOM", "Is support Zoom " + params.isZoomSupported());
}
catch (Exception e)
{
Log.i("ZOOM", "--------exception zoom");
e.printStackTrace();
}
}
else
{
Log.i("ZOOM", "--------the phone not support zoom");
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mApplication = (SpydroidApplication) getApplication();
setContentView(R.layout.spydroid);
mCamera = android.hardware.Camera.open(); //add
instance = this; //add
mAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE); //add
if (findViewById(R.id.handset_pager) != null) {
// Handset detected !
mAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.handset_pager);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
mSurfaceView = (SurfaceView)findViewById(R.id.handset_camera_view);
mSurfaceHolder = mSurfaceView.getHolder();
// We still need this line for backward compatibility reasons with android 2
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
SessionBuilder.getInstance().setSurfaceHolder(mSurfaceHolder);
} else {
// Tablet detected !
device = TABLET;
mAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.tablet_pager);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mApplication.videoQuality.orientation = 0;
}
mViewPager.setAdapter(mAdapter);
// Remove the ads if this is the donate version of the app.
if (mApplication.DONATE_VERSION) {
((LinearLayout)findViewById(R.id.adcontainer)).removeAllViews();
}
// Prevents the phone to go to sleep mode
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "net.majorkernelpanic.spydroid.wakelock");
// Starts the service of the RTSP server
this.startService(new Intent(this,CustomRtspServer.class));
}
加上权限:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" />