I'm writing a video player using the VideoView class. I have a "forward" button and I want the player to seek a 10 seconds further, when a user presses it:
if (mVideoView.canSeekForward()) {
int position = mVideoView.getCurrentPosition() + SEEK_TIME;
mVideoView.seekTo(position);
}
But almost always the position after seeking differs much from the desired: for example if position was 33458 in the code above, in my OnSeekCompleteListener.onSeekComplete I would get something like 29742 after calling mVideoView.getCurrentPosition()
This happens with this video and any other m3u8 videos I tried (on Nexus 7, API 19 and Xperia Z, API 17). But with some other streaming videos I don't encounter this bug.
Are there any workarounds? When I tried to play this video in MX Player, it had no problems with seeking, but probably it doesn't use the standard components
Related
Setting position (rewind) does not work properly while playing RTMP streams (static files, not live stream) in the VLC player.
The problem was discovered when developing an Android application to work with video archive by RTMP. The application uses a LibVLC player (de.mrmaffen: vlc-android-sdk: 1.9.0). To set the position, use the following code:
if (length == 0f)
mMediaPlayer.setTime(position);
else
mMediaPlayer.setPosition(position / length);
If position is right of the current, the player "waiting" until it comes to this position, focusing on the last frame, and can then start / not start playing from the desired position. If position left of the current, it is reset to the current and will continue to play with it.
If you specify a different stream format (eg, http://html5demos.com/assets/dizzy.mp4), the setting position is working properly. On the PC in the normal media player VLC problem also occurs. In other players the setting position of RTMP streams works fine.
Can you do something about this bug or work around it to begin to setting position in LibVLC?
We are trying play audio from url (m3u8 file). Media player starts fine no issues. Audio also plays cleanly. Issue starts when do seek in the player. Behavior very strange. it seeks to the proper position then starts playing audio. After while it seeks again like couples seconds (better word is skips some seconds since it jumps to the position directly) and can be observed in the media playback time counter, again plays for a while again jumps some seconds and this continues till end of the media.
We have our custom seek bar which is nothing but a progressbar, and when we do seek the progress bar we send same seek position to media player by calling onseek() method.
Note: Issue Happens only Lollipop nexus devices(tablet and phone).
Strange observation jump happens only if the time counters last position 9
(i.e if mediaplayed 12:29[mm:ss] then will jump to some other random place 12:3X[mm:ss],again mediaplayed 12:39[mm:ss] then will jump to some other random place 12:4X [mm:ss] )
Why is it happening?
You should pass the outer manifest to the player. This should resolve your issue.
I am trying to find a video player library that I can add to my Android App source that will allow the user to play the video at a slower speed, ideally adjustable by the user.
Also, I need the player to allow for two videos to be on screen at once, with separate controls.
I have looked at a couple of players available http://www.vitamio.org/ (can't play two videos), and http://wiki.videolan.org/AndroidCompile (I don't have access/experience on Linux machine to compile source for Android).
Android 6.0 added PlaybackParams class to control playback behavior. -
Use setPlaybackParams method of MediaPlayer as given below -
videoview = (VideoView)findViewById(R.id.videoview);
videoview.setVideoURI("Your Video URI");
videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
//works only from api 23
PlaybackParams myPlayBackParams = new PlaybackParams();
myPlayBackParams.setSpeed(0.5f); //here set speed eg. 0.5 for slow 2 for fast mode
mp.setPlaybackParams(myPlayBackParams);
videoview.start();//start your video.
}
});
You can adjust speed of video by using setSpeed method of PlaybackParams .
I try to stream (progressive e.g: http://server.com/video.mp4)
when i use the standard google mediaplayer (VideoView from android package) and register an onBufferingUpdateListener then i get the bufferpercentage that refers to the download state of the hole video. This player has also a loading view where i can see the buffer state.
This bufferpercentage and view shows me how much of the video has been downloaded.
Now when i use the Vitamio player, the onBufferingUpdateListener shows me after a few seconds 99 percent of buffering and there is no loading view too. And when i pause the playback it stops buffering immediately instead of continue buffering like the google videoview does. This is very usefull if you have a slow http stream.
Is there a way to make the vitamio-videoplayer buffer the videofiles in the same way as the google videoplayer does?
thank you
daniel
Sorry i posted that question as wrong user. Here the Answer of what i tried:
VideoView (android default - just plays few video formats) from inside the android.widget and from io.vov.vitamio.widget (vitamio - plays most video formats) package has the same structure. In both you can register an OnBufferingUdateListener that returns the bufferstate in percent:
videoview.setOnBufferingUpdateListener(new io.vov.vitamio.MediaPlayer.OnBufferingUpdateListener() {
public void onBufferingUpdate(io.vov.vitamio.MediaPlayer mp, int i) {
Log.v(TAG, "Buffer percentage done: "+i);
}
});
or with the android default VideoView:
videoview.setOnBufferingUpdateListener(new android.media.MediaPlayer.OnBufferingUpdateListener() {
public void onBufferingUpdate(android.media.MediaPlayer mp, int i) {
Log.v(TAG, "Buffer percentage done: "+i);
}
});
If i use android.widget.VideoView the buffer percentage slowly increases until it reaches 100% - The video file has been downloaded completely. And it continues updating BufferingUpdate when i press the pause button.
When i use io.vov.vitamio.widget.VideoView the percentage reaches 100% within seconds. Then the video starts and the OnBufferingUpdateListener never gets called again (when i call getBufferPercentage it is always at 99 percent. That seems to be the reason). And as i sayed: It seems to stop buffering when i press the pause button.
I think the buffering works different in vitamio. But that's crap. Especially when i stream videos from the web and the video datarate is higher than the download speed i need to prebuffer the video by pressing pause and wait until it has downloaded enough data to watch it smoothly. Hope you got what i mean. thank you
I'm working on an app in which the video is paused at 3 different intervals. After the second pause, if a button is clicked, it should start back from the previous location.
Eg. if it is currently paused at 1:30, then on click of a button, it goes to the previous bookmark, i.e. 00:45.
I thought using MediaPlayer.seekTo() will help me achieve this. But, seekTo() doesn't seek the position at all. The currentPosition stays the same even after a call to seekTo();
Here's my code.
mediaPlayer.setOnSeekCompleteListener(new OnSeekCompleteListener() {
#Override
public void onSeekComplete(MediaPlayer mp) {
Log.d("VID_PLAYER","Seek Complete. Current Position: " + mp.getCurrentPosition());
mp.start();
}
});
and somewhere below, I have this...
mediaPlayer.seekTo(45000);
What is the problem? Why isn't seekTo(); working?
Any help would be appreciated.
I am currently testing it on Android v4.0.3 (ICS)
Try the code snippet given below to achieve more accuracy in seeking to specific positions of the media.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
mediaPlayer.seekTo(seekPosition,MediaPlayer.SEEK_CLOSEST);
else
mediaPlayer.seekTo((int)seekPosition);
Keep in mind that - as the accuracy increases, speed of seeking decreases. So while playing high resolution videos its advised not to use MediaPlayer.SEEK_CLOSESTmore often.
One of the reasons why Android is not able to do seekTo is because of strange encoding of the videos. For example in MP4 format so called "seek points" (i.e. search index) can be specified at the begining and at the end of the file. If they are specified at the begining of the file then seekTo will behave correctly. But if they are specified at the end of the file then seekTo will do nothing and video will start from the begining after seekTo.
This is confirmed bug-or-feature in Android 4.4.2.
P.S. On Youtube all videos are encoded with "seek points" at the begining of the file. So if you have this problem with seekTo in your app first of all check your app with some video files from Youtube. Perhaps you'll need to reencode your videos...
Does your problem have something to do with this bug:
https://code.google.com/p/android/issues/detail?id=4124
I recall encountering this about a year ago. I don't think I found a workaround at the time.
Since API 26, Android added a
seekTo(long msec, int mode);
By specifying a mode, we are able to tell to our MediaPlayer how to seek:
SEEK_PREVIOUS_SYNC: Has the same behavior as seekTo(int msec). It looks for the nearest 'seek point' (i.e. sync frame) backwards.
SEEK_NEXT_SYNC: Same as PREVIOUS, but looks forwards.
SEEK_CLOSEST_SYNC: This looks for the nearest sync frame given a msec time.
SEEK_CLOSEST: This seeks for the nearest frame given a msec time.
I faced a similar problem a couple days ago and by using SEEK_CLOSEST mode, this problem was solved.
For reference, check out these links: https://developer.android.com/reference/android/media/MediaPlayer.html#seekTo(long,%20int)
https://en.wikipedia.org/wiki/Video_compression_picture_types