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.
Related
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
Is there a way to have a media file (audio/video) running in a cardview layout? I want to have a video preview of the file inside a card layout, when the user clicks on the card the video/audio is taken fullscreen and played, just like Facebook's feed.
In order to get that kind of functionality you have to solve a few problems:
You cannot use VideoView in a list because it is extending SurfaceView, and if playback is on and user starts scrolling, the visual effect will look like video is trying to catch the scroll. So you need a special VideoView that is based on something else, for example TextureView.
Managing video player state:
in order to start/stop playback we need to call a few methods of MediaPlayer.class:
setDataSource()
prepare()
start()
stop()
reset()
release()
These methods are direct calls to hardware and it may take some time before hardware will respond. So we cannot call it in UI thread. It will block it for more than 16 milliseconds, so user will see a lagging scrolled list. We have to call it from a background thread.
You need to track in run time which view on the screen is active and this view should be playing.
I've created an opensource project called VideoPlayerManager.
It is thoroughly documented and some basic flows are handled in the demo application. It is not ready for production but if you need some reference of how to get this kind of functionality, you can find it there.
P.S. Regarding CardView: it is a regular view. You can put a video player into it and get video playback in CardView.
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.
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.
Hello
our tester want to stop function in video player.
so I add stop button and call seekto(0) and pause when user press stop key.
but I has one problem. videoview is not clear play screen.
please help me.
instead of using video view try media player present in android.mediaplayer.mediaplayer so when you need to stop the player you can just call mediaplayerobject.stop() and then mediaplayerobject.release() thats all it will be easy