diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-12-17 10:41:50 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-12-17 10:41:50 +0000 |
| commit | ab1f1dfee09a0b002b7af51492e2dc96e27a2a17 (patch) | |
| tree | 05c0895f2b6c2c3e4d2bc6999d0e7e93cc48290f /src/com/example/rotorm | |
| parent | c18a56debd8df68c5bd823576346e048fc8788ef (diff) | |
Diffstat (limited to 'src/com/example/rotorm')
| -rw-r--r-- | src/com/example/rotorm/CameraActivity.java | 57 |
1 files changed, 46 insertions, 11 deletions
diff --git a/src/com/example/rotorm/CameraActivity.java b/src/com/example/rotorm/CameraActivity.java index 220f2bf..85fd8ba 100644 --- a/src/com/example/rotorm/CameraActivity.java +++ b/src/com/example/rotorm/CameraActivity.java @@ -17,6 +17,7 @@ import android.content.pm.PackageManager; import android.hardware.Camera; import android.hardware.Camera.CameraInfo; import android.hardware.Camera.PreviewCallback; +import android.media.AudioManager; import android.media.CamcorderProfile; import android.media.MediaPlayer; import android.media.MediaRecorder; @@ -50,6 +51,9 @@ private MediaPlayer mp; private String filename=""; private String audiofilename; +private Uri audioUri; + +private boolean intentStarted=false; private static final String AWS_S3_BUCKET_NAME="rotor-development"; private static final String AWS_S3_BUCKET_ENDPOINT="s3-eu-west-1.amazonaws.com"; @@ -62,10 +66,25 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); - Intent intent = new Intent(); - intent.setAction(android.content.Intent.ACTION_PICK); - intent.setData(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI); - startActivityForResult(intent, 1234); //0 stops picker + //Intent intent = new Intent(); + //intent.setAction(android.content.Intent.ACTION_PICK); + //intent.setData(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI); + //startActivityForResult(intent, 1234); //0 stops picker + + if (!intentStarted){ //dirty hack, without this it does the intent twice for some reason? + intentStarted=true; + + Intent intent = new Intent(); + intent.setType("audio/*"); + intent.setAction(Intent.ACTION_GET_CONTENT); + + startActivityForResult(intent,1); + } + + //why does this get intent twice? + //and crash 2nd time? + + //final Uri uri=Uri.parse(Environment.getExternalStorageDirectory()+"/Audio/abc.mp3"); } @@ -74,7 +93,16 @@ public void mCallback() { } public void onActivityResult(int requestCode, int resultCode, Intent data){ - Uri audioUri = data.getData(); + + + if(resultCode != RESULT_OK){ + + Log.i("could not pick audio","ERROR"); + return; + } + + + audioUri = data.getData(); audiofilename=audioUri.toString(); Log.i("returned data from intent: "+audiofilename, "SUCCESS"); @@ -125,20 +153,22 @@ public void onActivityResult(int requestCode, int resultCode, Intent data){ // Camera is available and unlocked, MediaRecorder is prepared, // now you can start recording + //prepare to play audio - mp = new MediaPlayer(); + try { - mp.setDataSource(audiofilename); - mp.prepare(); + mp = MediaPlayer.create(getApplicationContext(),audioUri); + //mp.setDataSource(audiofilename); + //mp.prepare(); mp.start(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } + } //catch (IOException e) { + // e.printStackTrace(); + //} Log.i("starting to record", "BEGIN"); mMediaRecorder.start(); @@ -271,6 +301,11 @@ private boolean prepareVideoRecorder(){ mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString()); // Step 5: Set the preview output mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface()); + //mCamera.setPreviewCallback(new PreviewCallback() { + // public void onPreviewFrame(byte[] _data, Camera _camera) { + // Log.d("onPreviewFrame-surfaceChanged",String.format("Got %d bytes of camera data", _data.length)); + // } + //}); // Step 6: Prepare configured MediaRecorder try { mMediaRecorder.prepare(); |
