[android-developers] Re: Strange behaviour with mediaplayer and seekTo (on start-up)
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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com 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 android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[android-developers] Re: Strange behaviour with mediaplayer and seekTo (on start-up)
Did you solve this problem? I ve modified videoview to implement the onSeekCompleteListener but this still occurs 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Strange behaviour with mediaplayer and seekTo (on start-up)
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 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en