In my application I am displaying around 30 animal images using viewpager. each page has full screen image and play sound button. Clicking on button will play displayed animals sound. So there are 30 different sound files in raw folder. how to play audio effectively when user press button? What to use mediaplayer or soundpool? and how to use it effectively? Please give me solution.
Keep the song files in the raw folder and then on the button's onClick method execute the songs play.
You can use a switch case for different id's of button.
Related
I am currently working on a snack.expo music app using expo-av. I am have trouble with the sound playing part.
Working
swipe for next/prev song(only changes image, name, artist)
use next/prev button(only changes image, name, artist)
Playing correct sound
Help Needed
pausing and playing sound
adding functionality to bottom buttons
implementing slider
I need to grab sound data from data.js and I need to play it based on which image is shown on screen. Right now there are just sample sounds and images.
snack link (almost full code)
I'm trying to implement built-in YouTube player in my app (API: https://developers.google.com/youtube/android/player/)
I load more than one video id for playback (list of video IDs)
youTubePlayer.loadVideos(idList)
But when player starts prev and next buttons aren't available until the first video finishes and switches to the next one, only then buttons appears and I can switch between videos from my video list
Whenever you got the answer.... please lemme know
It started to work normally after some time
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.
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.
I am trying to combine images in view-pager with mp3 audio file.
I have 26 images of ABC alphabets in view-pager, and a ABC song in mp3 audio file. I want that when i click start button mp3 song file play and alphabets images in view-pager changes.
I had searched a lot but didn't find any solution that i can understand. Can some one give me code of that?
Please help me.
Thanks
I think the best way to solve your problem would be to create a timer and to simply switch between the bitmap at regular intervals.
When the start button is clicked, just launch the timer using an handler, and inside the timer event, add your logic to switch images.