How to connect Media Player to a SeekBar? - android

I want to show the progress of a media on a seekbar.
Also I want to allow user to "jump" within a medium.
I have a MediaPlayer, and a SeekBar. And as far as I see there is no an easy way to merge them.

You can use VideoView instead of MediaPlayer and you can have MediaController which can be set to VideoView.
Otherwise you have to get the progress at instances and update the seek bar you can use timers.

Related

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.

Create custom media player like Youtube in Android

I have to create media player like youtube player.Actually if i use VideoView for play video and MediaController for controll video(MediaController onlyu provides play,pause,next,pre and seek options).But in my player i have to add one more option i.e bandwidth(I would have three bandwidth and on clicking on bandwidth video will play).So please suggest me.
As far I know, MediaController doesn't give many opportunities to be customized. So, you have two options depending on your UI requirements and the effort you are willing to do.
The hard way: You can just get rid of Android MediaController and
implement your own media controller, since you are not bound to use
it. MediaPlayer (through VideoView) provides you the needed
functions to build it: pause(), play(), resume() methods and event
listeners like onPrepared, onStopped, etc. To display the progress
bar you can use SeekBar, but you will have to code the interaction
with MediaPlayer (this is, the progress bar will not move alone).
The easy way: you can find another place to put your bandwith
button, for instance, on the top of the screen. You might even place
your button over MediaController.
You just have to create a layout properly combining the GUI elements you need. VideoView can be used with other GUI elements like buttons and can be nested within layouts like RelativeLayout and LinearLayout.
So, if you want your bandwidth button adjacent to VideoView, you may use LinearLayout, if you want your bandwith button over the video surface, like MediaController, you may use RelativeLayout, managing properly the layers.
have a look at SurfaceView, that will give you an idea on not bounding your logic with player.

Android VideoView Update Subtitles

I'm trying to make a video player with VideoView that supports subtitles using a TextView on top of it.
I've already parsed the subtitles but now i need an event that runs every time a frame changes or so to update the subtitles with the current playing position.
I tried making a thread but I am not able to change my TextView in that separate thread. Is there an event on VideoView/MediaPlayer that runs every frame change that I can override to call my updateSubtitle method?
Starting with Android 4.4 , you can put subtitles from within the VideoView itself:
https://www.youtube.com/watch?v=hCRGc2PcmB8#t=130
Coming to your first question, there is no event that happens each video frame. Having said that there are ways of getting current time and synchronize subtitles to the current time. Below links might be of help
A white paper on how to support subtitles in Android

How do I set spinning ProgressBar to Media?

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.

Progress bar with Streaming Audio using MediaPlayer

Is there a way to show the progress of a song playing with a progress bar and possibly length in terms of minutes and seconds? I would like it in the status bar, but I know how to do that using a custom notification layout so if someone steers me in the right direction that would be nice. Either with some code or code examples, thanks.
You obviously have to tie in with the NotificationManager classes the progress of the player/mp3. There was a question on SO that may have what you need... Also take a look at this for just basic Progress bar. And of course read the documentation on ProgressBar and Status Bar
To get the minutes left to play song, I know VLC player doesn't do that for my SlimDevices server. If you want to do this from via streaming you will have to get the length of the song, then implement your own timer as I am pretty sure that streaming music does not give you the current time left to play song.

Categories

Resources