Did you solved this issue? On Wednesday, 16 June 2010 10:23:49 UTC+5:30, Mathias Lin 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 at > http://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 --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

