How do I set spinning ProgressBar to Media? - android

I'm creating a soundboard application. Im new to developing but I have my whole app running perfectly exept for one last thing. I have it so I have multiple buttons and each button plays a different sound. I want to have a spinning progressbar on my button while the sound is playing, but then dissappear when the sound is done. How would I do this easily?

so i'm not sure how you're playing your sounds, whether its just one line of code that actually PLAYS the sound. In my opinion, you have two options
If your method returns something once the sound stops playing, I'd do something like
while (myapp.playSound() != -1){ //implement spin bar }
Or you can use AsyncTask -- http://developer.android.com/reference/android/os/AsyncTask.html
AsyncTask would probably be your best bet

Add a OnCompletionListener to the mediaplayer, so when you play the sound (or click the button) start the progress bar, and when the track is complete remove/stop it.

Related

Play specific sound when specific button is pressed

I'm really new to Android Studio, and am trying to make a simple app which plays specific sounds when a specific button is pressed. I have looked up many tutorials on YouTube, stack and other websites, but all of them seem to either give me a lot of errors or are too hard for me too understand (as I am too unexperienced).
All I have now are a lot of buttons on the screen which do nothing.
So can someone show me how to make something like this:
When button 1 is pressed, sound 1 plays, and when button 2 is pressed, sound 2 plays. (And that has to go on like that for about 20/30 buttons and sounds)
Thanks in advance,
-Spickle
Create a MediaPlayer mp object and use this in your onClick methods:
mp = MediaPlayer.create(context, R.raw.SoundForSpecificButton);
mp.start();
Then create a raw folder inside a res folder and put there your sounds.
Here is good documentation about this:
http://developer.android.com/guide/topics/media/mediaplayer.html#mediaplayer
If you are having problems please put your code here for review.
If you want to audio for a very short duration for example a 'click' sound when you press a button look for SoundPool class in android.
Play sound using soundpool example
If you want to stream a bigger audio file you will have to implement MediaPlayer.

mediaplayer.pause() not working

I am playing audios in a gridview.I am having issue that once the audio starts it not pausing or stopping.On clicking on pause button I see the pause image changing to play but still the audio keeps playing.If i click on another item's play button then multiple audio plays.I failed to understand why mp.pause() not working?
You are creating a MediaPlayer for each item of your GridView. If you scroll, it will mess up the references to your view and you won't be able to handle your MediaPlayer. You should use only one MediaPlayer, like the one you already have declared mMediaPlayer. Try using it instead of creating one for each item.

If using MediaPlayer to play Button click sound, what happens to default click sound?

For the record, I am not asking how to play a sound programmatically with the MediaPlayer. I know how to do that quite well.
I first searched how to replace the default click sound of a Button in the XML. But I have not found out if that is possible. Most answers suggest to use the MediaPlayer to play a sound effect somewhere in/from the onClick() event of the Button, so I assume that's the best way to go?
If I use the MediaPlayer to play a sound when a Button is clicked, do I have to disable the default click sound as well, or will both play, or will Android just know to ignore the default click sound? Should I call setSoundEffectsEnabled(false) on the Button before I play my own sound?
It seems very strange to me that I can't just replace the default click sound of a Button (is it possible to do that?)
Just set android:soundEffectsEnabled=false in your theme defined into your res/styles.xml
or programatically:
myButton.setSoundEffectsEnabled(false);
you may wish to check this link as well: Playing sound effect (CLICK/NAVIGATION_RIGHT) for button clicks - Android
seems that sound effects are kept as android.view.SoundEffectConstants.<value>
correspondingly, there might be a way of adding your own custom sound
it is all about passing the value of sound effect you'd like to hear, into <view variable>.playSoundEffect(<sound effect value>); so you may try to add your sound into res and call that method with its R value

Add custom audible feedback to Android button

I want to add custom audible feedback to a button press (various click sounds encoded as *.ogg) I've done this by using the RingtoneManager to create Ringtones for each of the clicks and then .play() them in the onClick() method. This works but seems a little sluggish. This leaves me wondering if there is a better way to attach a custom sound effect to a button press. I've scanned the Button reference page and all I found was playSoundEffect() which seems to handle only system defined sounds.
thanks,
hank
Use a SoundPool- they work it preloads the data into memory (so no file reads which cause sluggishness). Ringtones are definitely not what you want to be using here- those are typically much longer and not time critical (delaying a ringtone by a second or so isn't a problem, whereas delaying a button sound effect by that long is).

How to create ProgressDialog with pause and resume

I currently have url for an audio file. I'd like to create audio player like that in Evernote.
I have tried to create a ProgressDialog where the maximum value equals the player duration. But I have no idea how to add a pause/resume Button to work with both progress bar and audio. So basically this divided into three sub-questions:
How can I add a Button to ProgressDialog?
How to pause and resume the a) ProgressDialog and b) audio?
How to detect that the user tabs outside of the ProgressDialog in which case the audio should be stopped?
You cannot user a pre-defined dialog for that. Create your own custom one. Here can you find everything you need to know about that.

Categories

Resources