the seekTo() function doesn't work in VideoView - android

There is a problem in my application,I want to use the seekTo() function with VideoView like this:
videoView.seekTo(time);
videoView.start();
It works well in android 2.2 ,but doesn't work in android 2.3 or higher version...
Some body will tell me why? It troubles me for serval days.

The call to VideoView.start() should be made only after the seek has completed. The call to VideoView.seekTo() initiates a seek but unfortunately VideoView does not support OnSeekCompleteListener needed to notify the seek is actually done.
You can customize VideoView to support OnSeekCompleteListener as shown in my answer to 7990784.
Then you can register to receive onSeekComplete() by calling setOnSeekCompleteListener(). Your implementation of the listener should then call VideoView.start().

Have you tried VideoView class from Vitamio library?
Vitamio

For proper operation of the method seekTo(),the video state should be in PlaybackState.
Checkout the VideoView source here for get more information.

This solution should work.
The problem may be that the mediaplayer inside videoView has not been created.
It's easy to test, by changing the orientation of the device. That's how I tested it.
videoView.setOnPreparedListener(onPreparedListener);
private MediaPlayer.OnPreparedListener onPreparedListener = new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mp.seekTo(videoPosition);
}
};

Related

How to play two sounds at the same time?

I've been trying a few things with sounds in flutter lately . Using audioPlayer plugin.
But I'm facing a wall. I have both a background music, and small sounds effects.
The problem is that I can't play both at once. If I play the background music, then the sound effect won't play. And the opposite works too.
Any idea about how to solve that issue ?
This is an issue with the audioplayer plugin and there's an issue open for it already. The author has indicated that he's open to pull requests if you'd like to take a crack at implementing it.
Use media players. Use this code to set up the background music:
MediaPlayer backgroundMediaPlayer = MediaPlayer.create(getApplicationContext(), Uri.parse(PATH_TO_BACKGROUND_MUSIC));
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayer) {
mediaPlayer.start();
}
});
Then replace PATH_TO_BACKGROUND_MUSIC with the background music path.
Then when you want your sound effect to happen, use this code:
MediaPlayer soundEffectMediaPlayer = MediaPlayer.create(getApplicationContext(), Uri.parse(PATH_TO_SOUND_EFFECT));
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayer) {
mediaPlayer.start();
}
});
Then replace PATH_TO_SOUND_EFFECT with the background music path.
You can learn for about media players here.
Hope this helps!

Rewind functionality in Brightcove player

In my app I implement the brightcove video player.
I am working on customizing brightcove.
I successfully implemented the play/pause option, and I am trying the same for the rewind option, but to no avail.
Here is my code
BrightcoveVideoView commonVideoView = (BrightcoveVideoView)view.findViewById(R.id.commonVideoViewId);
BrightcoveMediaController mediaController = new BrightcoveMediaController(commonVideoView, R.layout.media_controllers);
How can I solve this issue?
You can use the seekTo method for achieving the same.
brightcoveVideoView.seekTo(value);

The play/pause buttons on MediaController doesn't refresh alone for audio player

I followed this tutorial http://code.tutsplus.com/tutorials/create-a-music-player-on-android-user-controls--mobile-22787 to build an audio player.
All works fine, but my MediaController behave oddly. In fact the controller's seekbar does not update until the user interacts with it.
I tested with API 16 to 19 without success, i have the same problem.
I tested many solution on topics i found on stackoverflow without success also.
Has anyone an idea?
It's odd, but I found that you should update start()/pause() methods of MediaPlayerControl in such way:
#Override
public void pause() {
musicSrv.pausePlayer();
controller.show();
}
#Override
public void start() {
musicSrv.go();
controller.show();
}

Stopping the youtube player playback custom view

I am using a com.google.android.youtube.player.YouTubePlayerView to play my youtube videos, I extend YouTubeBaseActivity. I am having an issue where I call .pause() on the youtube player instance and and set the view VISIBILITY to View.GONE but it keeps buffering after the view has been set to View.GONE and throws and error because it cannot play in a hidden view. I called YouTubePlayer.pause() before hiding the view. Is there another way to stop playback? I want to stop the player and remove the com.google.android.youtube.player.YouTubePlayerView when a button is pressed. Thanks for taking a look.
if(youTubePlayer.isPlaying()){
youTubePlayer.pause();
youTubePlayerView.setVisibility(View.GONE); }
The pause function will will not stop it. You should try to release it for stopping it. Try the following code
youTubePlayer.release();
It's too late to answer - But still, someone might be benefited -
You can set player style in youtube player.
youtubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT) // To set player as youtube provided.
youtubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL) // To set minimal version of the youtube player. In this style you'll not get the player control options.
youtubePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.MINIMAL) This line will do the work of Stopping the youtube player playback custom view

How to play ringtone once through MediaPlayer?

I can't play a ringtone once even if mediaplayer looping property is set to false. It looks like this property was overriden by the ringtone URIused. So onCompletion is never fired.
Curiously, if the URI corresponds to a notification tone, looping behaves according to setLooping. It works well here.
So is there a way to play a ringtone once?
I faced this problem before and solved it by using OnSeekCompleteListener:
mMediaPlayer.setOnSeekCompleteListener(new OnSeekCompleteListener() {
public void onSeekComplete(MediaPlayer mp) {
//Your stuff
}});
I don't know if it's the best way to solve this, but it worked for me.
Edit: BTW, I use both listeners, oncompletionlistener AND onseekcompletelistener. Hope this helps!

Categories

Resources