MediaRecorder.pause() in android - android

the pause method added to MediaRecorder in api 24
is there any way to use this in a older api?
here is android studio suggest
but i want use it in older devices

Simple answer for your question is NO YOU CAN'T
Once you are recording the only possible actions are stop and reset.
So try to save your Call to SDCard after you Stop , and then again start Fresh Record and Stop it. Finally Combine both Audio File into one Audio file.
Record the audio as .wav file and Combine using this way.

On older platforms there is no MediaRecorder.pause(). The only option is to record few separate files and then concatenate it by yourself with any available library (e.g. try FFmpeg-based). But note that there may be roughness due recorder may insert empty frames at the begin / end of files and concatenated media may contain artifacts like blinking, cracks so on.

Check out this library.
I have personally used this to add pause and resume functionalities to my android app. It supports all API levels.

Related

Integration between Android and Pure Data

I have written a Pure Data patch, which works on PC (Windows); when I integrate it with Android, an audio file is saved, but it contains no data. I confirmed that the file is there using ES file explorer, and I granted app permissions for recording audio in Android Studio.
Your patch has undefined trigger order issues. It is not clear from the visual patch if
in the recording section the filename gets passed first of the start message gets initiated first.
in the playback section the 0/1 from the toggle gets received by two receivers, one of which sets the filename, the other one passes the 0/1 to [readsf~]
Additionally you are recording a stereo file but playing back only mono.
I tried to stick to your patch as close as possible, but I use "bang" [bng] objects instead of "toggle" [tgl] objects because they are better suited for initiating things rather then switching between two states.
It's necessary to initialize the number of channels in the initPd function with Android Studio. It was set to 0. When changed to AudioParameters.suggestInputChannels();, I was able to get the audio.

Possible to Override system .so library in App

I have to modify the Http Live Streaming implementation of Android Media Player.
The implementation is under the stagefright library
http://androidxref.com/4.0.4/xref/frameworks/base/media/libstagefright/httplive/LiveDataSource.cpp
I think these library will compile to a libstagefright.so which should be part of the Android system.
My question is if I make some changes to this library and compile a new libstagefright.so.
If I load this new libstagefright.so in my new application and call up the media player, will it use the code in my new libstagefright.so?
You will not be able to replace the original library, since when you try to loadLibrary it will load the library from within /system/lib. So unless you replace that (which is not possible on unrooted devices), you won't be able to load your custom code.
https://github.com/android/platform_system_core/blob/66ed50af6870210ce013a5588a688434a5d48ee9/rootdir/init.environ.rc.in sets the LD_LIBRARY_PATH by default. And loads it from these paths if available. If not, then your application's lib directory will be searched; but not the other way around.
I tried this with libwebkit.so in the past on various mainstream devices and haven't had any luck getting it to load instead of the one in /system/lib.
You can learn more by looking at:
doLoad from here https://android.googlesource.com/platform/libcore/+/41d00b744b7772f9302fdb94dddadb165b951220/luni/src/main/java/java/lang/Runtime.java
findLibrary here http://developer.android.com/reference/dalvik/system/BaseDexClassLoader.html#findLibrary(java.lang.String)
I'm pretty sure you can't replace the default class loader either for security reasons.
What you can do, though, is a straightforward fork the Media Player and have it load your modified libstagefright-modified.so. There could be other solutions, haven't looked at Media Player's code.
Knowing that all you want to do is parse the data before it gets to the MediaPlayer, I suggest not trying to alter the Android libraries. As soulseekah mentioned, it's not going to work without a rooted device. There are other options, although they both have drawbacks.
1) If you are only targeting recent versions (4.2 or later, I believe), you can take a look at new classes added to the android.media package, like MediaExtractor and MediaCodec. I'm not greatly familiar with those because they aren't available on the hardware with which I work, but they could be useful in getting to the raw data. Here is a decent sample of using them to play video. The drawback is those classes aren't available in earlier versions.
2) The other option is to put a local proxy on the device. Connect the MediaPlayer to the proxy and make the request to the media server yourself. See my answer here for a little more info on that. With a proxy, you will see all the data that comes through, giving you a chance to parse the ID3 tags. There is the drawback that you will have to parse the TS packets to put together an elementary stream (essentially doing the demuxer's job), but it will work with any version of Android. TS streams aren't difficult to disassemble, and ID3 tags aren't time consuming to parse, so I think this is a reasonable approach.

android MediaPlayer from url make it sound louder/amplify (not just volume up)

I play an mp3 file from url with android MediaPlayer class.
(everything works fine)
I want to amplify the sound, make it sound louder.
I don't mean just raise the device volume but to actually amplify the sound.
even in cost of loosing some quality.
(I want it to be done in code and not with 3rd party software) maybe with some kind of java library.
MediaPlayer doesn't have a out-of-the-box method for this. Doing what you try to do really goes in the direction of audio-manipulation. This means, that you should get the byte stream and modify it for your needs. E.g. read the MP3 specification and try to rise the amplitude.
A better approach would be to edit your current mp3 files with a professional desktop editing program and play the files just the usual way.
As per my understanding, this may not be directly allowed in MediaPlayer and you may need some mp3- manipulation algorithm or library to do this. I am looking into this, but you can use the following as a starting point:
Audio Effect
Looks like you're not supposed to directly use, that but one of its subclasses:
Equalizer
Virtualizer
BassBoost
PresetVerb
EnvironmentalReverb
Maybe it will help you, but I'm not exactly sure how to implement it. Will look into it.

Android Audio effect on wav file and save it

Requirement
Android open a .wav file in sd card, play it , add some effect (like echo, pitch shift etc), save the file with effect. Simple :(
What I know
I can open and play file using Soundpool or MediaPlayer.
I can give some effect while playing using both. ie for Media Player
I can set Environmental Reverb effect. Using SoundPool I can set
playing rate, which is kind of like pitch shift. I am successful in
implementing these right now.
But either of this classes doesn't have any method to save the
played file. So I can only play, I cannot save the music with
effect.
What I want to know
Is there any other classes of interest, other than MediaPlayer or
SoundPool. Never mind about saving, you just mention the class, I will do the
research about saving file with them.
Any 3rd party libraries where I can add effects and save? Happy if
it is open source and free. But mention them even if it is
proprietary.
Any other areas where I can look into. Does OpenAL support voice
filtering along with voice positioning? Will it work with Android?
Ready to do the dirty work. You please lend me the path..
EDIT: Did some more searching, and come across AudioTrack. But it also won't support saving to a file. So no luck there also..
EDIT Ok, what if I do it myself? Get raw bytes from a wav file, and work on that. I recorded a wav file using AudioRecord, got a wav file. Is there any resource describing low level audio processing (I mean at the bytes level).
EDIT Well bounty time is up, and I am giving bounty to the only answer that I got. After 7 days, what I understood is
We can't save what we play using MediaPlayer, AudioTrack etc.
There is no audio processing libraries available to use.
You can get raw wav files, and do the audio processing yourself. The
answer gave a good wrapper class for reading/writing wav files. A
good java code to read and change pitch of wav files is here.
The WavFile class http://www.labbookpages.co.uk/audio/javaWavFiles.html claims to read and write wav files and allow per-sample manipulation through arrays of sample values. It's certainly reasonably small, 23kbytes total source code.
I did struggle for a while to build an android app with the Wavfile Class included. This turned out to be because both WavFile and ReadExample (from the above link) were intended as standalone java programs, so include a method main(String [] args){}. Eclipse sees this and thinks the Class is a standalone runnable program, and, when I click the run button, tries to execute just the one Class with the java in the development machine, instead of launching the whole app to my phone. When I take care to run the whole app with the little drop-down menu on the run button, I don't have any trouble, and the WavFile Class and examples drop straight in, give zero warnings in the IDE, and work as advertised running on my phone.

Dynamic Midi generation and playback on Android: Possible?

Strangely I find no support for Midi in Android.
The only thing that comes close is the Jetplayer, but this only takes a existing .jet file.
I want to dynamically generate a midi file with some intervals and play it.
I even thought about just manually creating a .jet file with a tone and then transposing it with the jet player, but it limits the transposing to -12, +12. Which is not so good for me.
There also is a ToneGenerator on Android, but it's limited to predefined tones with no way to transpose.
Does someone know how to achieve midi generation and playback on Android?
Perhaps this Pragmatic Programmer thread might be of interest.
I currently settled for the dynamic generation of midi files that then are fed to the MediaPlayer. It's quite easy to build a simple midi file generator and the MediaPlayer works correctly with it.
I do have opened a feature request for direct streaming access to the synthesizer. If you are interested in streaming midi, please rate, star, comment there.
Better late than never, but there's a bare-bones Java MIDI library on Google Code here: http://code.google.com/p/android-midi-lib/
That can handle MIDI file generation and you can use MediaPlayer to play it back supposedly.

Categories

Resources