Trouble getting location to recorded audio

All your problems with Audio, Video and Images.

Trouble getting location to recorded audio

Postby Pich » Wed Nov 25, 2009 8:59 pm

Hi,

I have to following code to launch and the audio recorder on Android:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. final Intent recordSoundIntent = new Intent("android.provider.MediaStore.RECORD_SOUND");
  2.  
  3. String fileName = Environment.getExternalStorageDirectory() + File.separator + UUID.randomUUID() + ".3gpp";
  4.  
  5. recordSoundIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(fileName)));
  6.  
  7. startActivityForResult(Intent.createChooser(recordSoundIntent, getString(R.string.record_sound_chooser)), INTENT_SOUND_RECORDING);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


And the following code to save the location to the newly recorded audio:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Uri uri = data.getData():
  2.  
  3. soundRecording.setLocation(uri.toString());
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


And this code to play (it works with no problem):

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. MediaPlayer mp = new MediaPlayer();
  2.  
  3. mp.setDataSource(soundRecording.getLocation());
  4.  
  5. mp.prepare();
  6.  
  7. mp.start();
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


My problem is the following:

1. My filename (fileName) has no effect, the Uri returned from data.getData() returns in my last test run: content://media/external/audio/media/41. However, this file is created on my sdcard: recording34485.3gpp. If it is not possible to set custom location upon creating sound it is the location to this file I would like.

2. I want to mail this recording using the ACTION_SEND, but I can't attach the audio file, I guess because soundRecording.getLocation() points to content://media/external/audio/media/41 and not recording34485.3gpp:
File file = new File(soundRecording.getLocation());
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));

Can anyone help me?

Best regards

Per Jansson
Pich
Junior Developer
Junior Developer
 
Posts: 17
Joined: Wed Nov 25, 2009 8:30 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 6 guests