I have a 'Play'button set up in an XML layout file,
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="play"
android:onClick="playButton"
/>
and I want to make it so that when I click on the button, an action dialog shows in which there are two buttons that say 'Play' and 'Stop'.
When I click on the Play button I want the app to record whatever the user is saying to the microphone and when the 'Stop' button is pressed, save that mp3 into resources.
How can I make this? I'm right now really confused because my
and yes, I've seen the Android documentation & sample codes on Media Recorder and I still don't get it...
try to see this resource on Github android-MediaRecorder
make something similar that you dear, but use camera of the devices. By the way you can start from here and make some adjustment
By the way , you can find more project like this, ad example this AndroidAudioRecorder
that are already did.
Maybe this can be help you
Have a nice work!
Related
I have been following an online tutorial on how to play sound on button click. I am getting no errors with my Java code which leads me to believe that the code is correct.
However, they did not provide a tutorial on what the xml should read. So I left it as it is but when the Activity loads nothing is occuring and I'm left with the Hello World Template.
Could somebody advise me how to get this code to run in the view and if so how. If not could they maybe provide me with an alternate option.
Currently in your XML you have a TextView, you should add a Button (actually you can just change TextView to Button in this case). After that you need to either add
android:onClick="onClick"
under the button.
Or you can use a onClickListener for the button.
I have an AppWidget (part of my app). I want there to be no sound when the user clicks a button in the widget.
How do I do this?
CommonsWare answered it:
This is not a method on RemoteViews, and setSoundEffectsEnabled() is not a RemotableViewMethod, so the literal answer is incorrect. However, android:soundEffectsEnabled="false" in the layout file may work.
setting android:soundEffectsEnabled="false" in the xml layout file does indeed work!
As far as I know, you have to turn off notification sounds (pressing volume down, then selecting settings on it). The click sound is usually created by the OS (Samsung Android will have a click but google Nexus will not). The only other way I can think of is, if the widget is yours, create a custom button that overrides that particular functionality.
Add the following line of code to disable the click sound,
yourbutton.setSoundEffectsEnabled(false);
How can one create a wave like animation, like the one which appears when one touches the screen on an Android 4.0 lock screen.
I have something similar in one of my app. The way I did is putting the whole wave as one big image then you repeatedly change it's source in background to give it animated look & feel.
Basically, when onTouchUp you start the animation and have it loop and update the image sources until finish. Then you switch its source to the original image in onAnimationFinish.
That's just from the top of my head so I'm not sure if it's accurate or not. I reckon you get the idea anyway. If there's easier way to pull it off then I'm willing to listen as well.
here is the solution you want to implement let me know if it doesn't work.
Code sample :-
Add a TitanicTextView to your layout:
<com.romainpiel.titanic.TitanicTextView
android:id="#+id/titanic_tv"
android:text="#string/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#212121"
android:textSize="70sp"/>
To start the animation:
titanic = new Titanic();
titanic.start(myTitanicTextView);
You may want to keep track of the titanic instance after the animation is started if you want to stop it.
To stop it:
titanic.cancel();
So I have seen some other posts similar, but not quite answering what I am looking for.
Basically onCreate is loading in the content (being textviews and image) and it also opens up another thread to prepare the media player so that when the button is pressed it plays a specific song. If this activity is opened and the button is pressed quickly it does not play anything (which I am assuming because it hasn't had a chance to prepare). If I open the activity and give it a few moments it works just fine. I do realize that it is not best to run the content being loaded in onCreate, but I have tried to get it to load in other threads and it failed miserably. It is all fine with me what I really want to happen is this.
I need some way to prevent use of the button or let them know it is loading for about 3-5 seconds. So either make the button be faded out and unusable for 3-5 seconds and then it becomes active or a loading screen that is some what transparent that covers the activity for about 3-5 seconds. If you mention using other threads could you please demonstrate it if it isn't asking to much or show me something like a tutorial (other than googles notes). I don't understand threads very well yet (pretty new to them) and the AsyncThread is pretty confusing to me.
If you need code let me know what you would want posted. Thanks and I appreciate any help.
You can set an setOnPreparedListener on your MediaPlayer, in this listener you enable your button and be save that the song can be played.
Docs
I would create an xml selector file governing button behaviour. Something like:
<?xml version="1.0" encoding="utf-8"?>
<item android:state_enabled="true" android:drawable="#drawable/lbl_black_matte" />
<item android:state_enabled="false" android:drawable="#android:color/transparent">
</item>
Then, in your activity:
private Button mActivate;
mActivate = (Button) findViewById(R.id.activate);
mActivate.setOnClickListener(this);
Then somewhere, you'll check to see if the magic is ready, and activate the button if so:
if (mEnabled) {
mActivate.setEnabled(true);
}
Finally, you'll have to reference the button behaviour selector in the xml document in which the button is created.
android:layout_width="match_parent">
<Button android:id="#+id/activate"
android:background="#drawable/b_behaviour" android:layout_height="wrap_content"
android:layout_margin="8dip" android:layout_width="match_parent"
android:text="#string/setup_label_enable" android:textColor="#android:color/white"
android:textStyle="bold">
</Button>
Please let me know if that's clear or if you need me to explain how to create the click listener.
Good luck!
(I am an extreme newbie, my knowledge is of basic programming ideas, i.e. a click executes a command, basic cause and effect)
I am wanting to test out a simple idea of having an image (for example sake imagine one page of "Where's Waldo!?") where you open the app and you have an image, (also this is aimed at android tablets) and this image has many details and lots of different focal points going on, so i want the end-user to be able to look through this image and see, (again for example sake) waldo, and then to be able to click on waldo and a text bubble to pop up with "you win!
" or some info about waldo, or any other details on the page.
so far all i have been able to do is make the entire image one button, which is undesirable seeing as i would prefer there to be about 20-30 randomly placed buttons each with their own synopsis of the section of the image being clicked on.
using android app inventor...
A site explaining how to make specific parts of an image into clickable areas can be found here...it worked for me..
The link is also summarized at this SO question.
How about add a small 'Buttons' on the image with transparent background and make sure you add button after image so that it will not be covered by image. Then try and see if you get onClick when you hit button. If this works, may be you can have such multiple buttons over image and user will not notice that he is actually hitting button instead of image.
A button with a transparent background will surely work.
<Button
android:layout_height="50dip"
android:layout_width="50dip"
android:background="#00000000">
</Button>