I am recording audio using Audio recorder (native app) of android.Using following code :
final Intent audioIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
String path = Environment.getExternalStorageDirectory()
.toString();
File AudioFolder = new File(path + "/MyFolder/",
"RecordedAudio");
File audioFile = new File(AudioFolder, "myaudio.mp4");
Uri audioFileUri = Uri.fromFile(audioFile);
audioIntent.putExtra(MediaStore.EXTRA_OUTPUT, audioFileUri);
startActivityForResult(audioIntent, 0);
Audio recording is working fine with me. After successful recording It has been stored default in sdcard. I am not able to store it with my particular folder "MyFolder" that is located in sdcard so It might be store in /sdcard/Myfolder/RecordedAudio/myaudio.mp4.
What is going wrong with my above code.?
Please help me with your suggestions.
Thanks
Related
I am trying the app for speech synthesis by using some DSP approach. Fortunately, the TrasosDSP supports most of these approaches for android.TrasosDSP for Android. But I cannot play audio with AndroidAudioPlayer in TrasosDSP although I tested according to their sample code. I cannot able to trace it is why? Here is the sample code from TrasosDSP for Android.
With the TarsosDSP Android library the following code plays an MP3 from external storage:
new AndroidFFMPEGLocator(this);
new Thread(new Runnable() {
#Override
public void run() {
File externalStorage = Environment.getExternalStorageDirectory();
File mp3 = new File(externalStorage.getAbsolutePath() , "/audio.mp3");
AudioDispatcher adp;
adp = AudioDispatcherFactory.fromPipe(mp3.getAbsolutePath(),44100,5000,2500);
adp.addAudioProcessor(new AndroidAudioPlayer(adp.getFormat(),5000, AudioManager.STREAM_MUSIC));
adp.run();
}
}).start();
Provided your music is in the Music folder, try replacing:
File externalStorage = Environment.getExternalStorageDirectory();
File mp3 = new File(externalStorage.getAbsolutePath() , "/audio.mp3");
with
File mp3 = new File(Environment.getExternalStorageDirectory(), "Music/audio.mp3");
For some reason this way it works, but it took me 2 weeks of puzzling.
I want to implement a simple Media Player.How can i retrieve the full path of Mp3 songs from internal storage in android.
mpintro = MediaPlayer.create(this, Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/Music/intro.mp3"));
mpintro.setLooping(true);
mpintro.start();
If you have any problem search first. do your efforts you'll find it...
here's a link try it Get Mp3 from SD card
Try this check for file if it exists or not
public static String rootPath = Environment.getExternalStorageDirectory() + "/YourDirectory/";
File file = new File(Environment.getExternalStorageDirectory()
+ "/YourDirectoryFolder/Audio/" + NmaeofFile + "/");
if (!file.exists())
return false;
else{
//Do your work here
}
And then simply start media player
player.setDataSource(rootPath);//rootpath is the path of your file
player.prepare();
player.start();
I'm using this piece of code to try and open a .mp4 video:
VideoView videoView=(VideoView)findViewById(R.id.videoView1);
MediaController mediaController=new MediaController(this);
mediaController.setAnchorView(videoView) ;
videoView.setVideoPath("R.raw.videoname");
videoView.setMediaController(mediaController) ;
videoView.start();
However, whenever I try to run the app, I get a message saying "Can't play this video". I am using a new Nexus 7 tablet if that means anything.
Also, when I try to open the same file that I have stored in with my movies, the video runs perfectly normally when I use Gallery or Video Player to open it.
Any help is much appreciated.
File file = new File(getFilePath());//file path of your video
MimeTypeMap map = MimeTypeMap.getSingleton();
String ext = MimeTypeMap.getFileExtensionFromUrl(file.getName());
String type = map.getMimeTypeFromExtension(ext);
if (type == null)
type = "*/*";
Uri uri = Uri.parse("www.google.com");
Intent type_intent = new Intent(Intent.ACTION_VIEW, uri);
Uri data = Uri.fromFile(file);
type_intent.setDataAndType(data, type);
startActivity(type_intent);
Make sure there will be no space in video name, otherwise it will not
be played by android VideoView.
If not solved then let me know.
I'm using MediaRecorder class to record an audio file and I used
final String MEDIA_OUTPUT_FILE = "MyOutPutFile";
mediaRecorder.setOutputFile(MEDIA_OUTPUT_FILE);'
to give a name to my output file.
I also know how to Play an Audio File from Resources:
MediaPlayer mpRes = MediaPlayer.create(getApplicationContext(), R.raw.audiofile);
mpRes.start();'
My Question Is, Now, how to play the recorded file while I dont know where my MEDIA_OUTPUT_FILE is saved?
Instead of using constant as argument for mediaRecorder.setOutputFile() use a variable like below.
private String filePath;
filePath = Environment.getExternalStorageDirectory().getAbsolutePath();
filePath += "/myrecording.mpeg";
Then pass the filePath variable as the argument as follow;
mediaRecorder.setOutputFile(filePath);
Then you can play the recorded file as follows;
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(filePath);
mediaPlayer.start();
That's it.
I am trying to save video to specific folder like
Intent captureVideoIntent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
File videosFolder = new File(Environment.getExternalStorageDirectory(), "Videos");
if (!videosFolder.exists()) {
videosFolder.mkdirs(); // <----
}
String sfx = getNextName(ConstantData.RESPONSE_TYPE_VIDEO);
videoUri = Uri.fromFile(new File(videosFolder, sfx));
captureVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT,videoUri);
captureVideoIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivityForResult(captureVideoIntent,1277);
videoUri is fine, folder Videos is created and on result when I try to read file like
InputStream inputStream = this.getContentResolver().openInputStream(videoUri);
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(8 * 8192);
....
I am getting exception FileNotFound, what is true, there is Videos folder but there is no saved video inside. Does anybody know what is problem and why I cannot save video to specific folder ? Video has extension .3gp and folder is always empty.
You can specify your new file name instead of the "sfx"
remove the below line and put "test.mp4" instead of the "sfx" variable, it will work
String sfx = getNextName(ConstantData.RESPONSE_TYPE_VIDEO);