Pause/Stop MediaPlayer Android at given time programmatically

后端 未结 5 1938
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-09 12:23

I researched a little bit, but couldn\'t find any solutions to this problem: I would like to play a MediaPlayer and pause/stop it at a given time.. (ie: play from s

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-09 12:41

    I know this already has an answer but here is an alternative for anyone wanting to do this efficiently for a video with controls.

    I saw a different answer that involved constantly checking the position.

    Note that this assumes that you do not need a lot of different portions of one video. Even in that case I suggest to follow the below.

    If you only need to play a portion of the video and want it to end somewhere, then why not just use free video editing software and clip the end? You can still start it from anywhere using seekTo() but this way you don't have to waste resources checking for a certain position (video with controls).

    If you do not have video player controls the accepted answer will work. But if you do have player controls then it would not since a user could pause and play the video.

提交回复
热议问题