Furthermore, the problem described below also occurs when using a
VideoView instead of a surface + mediaplayer. Below is the code for
this example.
(I am also wondering, why does VideoView not provide a
setOnSeekCompletionListener like the MediaPlayer? I assume that seekTo
is asynchronous here as well, not?)
public class VideoTest extends Activity {
VideoView vidView;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
vidView = (VideoView) findViewById(R.id.vidView);
vidView.setVideoPath("/sdcard/myapp/main/videos/main.mp4");
vidView.seekTo(16000);
vidView.start();
}
}
On Jun 16, 12:53 pm, Mathias Lin <[email protected]> wrote:
> I'm implementing a custom video player because I need custom video
> controls. I have an app with only one activity, which on start-up
> shall starts playing a video right away.
>
> Now, the problem I have (on my Nexus One):
>
> I don't want the video to start from the beginning, but from a later
> position. Therefore I do a seekTo(16867). Since seekTo is
> asynchronous, I place the start call of the mediaplayer
> (player.start()) in the onSeekComplete of the onSeekCompleteListener.
>
> **The strange behaviour I experience though is that I can see/hear the
> video playing from the beginning for a few millisecs before it
> actually plays from/jumps to the position I seeked to.
> But - on the other hand - the Log output I call before the
> player.start returns the correct position 16867, where I seeked to.**
>
> Below is the relevant code section, the complete class is
> athttp://pastebin.com/jqAAFsuX
>
> private void playVideo(String url) {
> try {
> btnVideoPause.setEnabled(false);
> if (player==null) {
> player=new MediaPlayer();
> player.setScreenOnWhilePlaying(true);
> }
> else {
> player.stop();
> player.reset();
> }
> url = "/sdcard/myapp/main/videos/main.mp4"; // <--- just
> for test purposes hardcoded here now
> player.setDataSource(url);
> player.setDisplay(holder);
> player.setAudioStreamType(AudioManager.STREAM_MUSIC);
> player.setOnCompletionListener(this);
> player.setOnPreparedListener(this);
>
> player.setOnSeekCompleteListener(new
> MediaPlayer.OnSeekCompleteListener() {
> public void onSeekComplete(MediaPlayer mediaPlayer) {
> Log.d("APP", "current pos... "+
> player.getCurrentPosition() );
> player.start(); //
> <------------------ start playback on seek completed
> player.setOnSeekCompleteListener(null);
> }
> });
> player.prepareAsync();
> }
> catch (Throwable t) {
> Log.e(TAG, "Exception in playVideo prep", t);
> }
> }
>
> public void onPrepared(MediaPlayer mediaplayer) {
> width=player.getVideoWidth();
> height=player.getVideoHeight();
> if (width!=0 && height!=0) {
> holder.setFixedSize(width, height);
> progressBar.setProgress(0);
> progressBar.setMax(player.getDuration());
> player.seekTo(16867); // <------------------ seeking
> to position
> }
> btnVideoPause.setEnabled(true);
> }
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en