美文网首页
Android MediaPlayer SeekTo方法调用后会

Android MediaPlayer SeekTo方法调用后会

作者: 没有小叮当的大雄 | 来源:发表于2021-01-19 19:32 被阅读0次

使用Android原生的MediaPlayer时调用默认的seekTo(long time)的时候,播放器会在设置的时间点往回退一点时间。查看源码之后如下:

public void seekTo(int msec) throws IllegalStateException {
        seekTo(msec, SEEK_PREVIOUS_SYNC /* mode */);
    }

默认是调用了两个参数的seekTo方法,第二个参数一共由四种mode,源码中注释也很清楚。

 /**
     * This mode is used with {@link #seekTo(long, int)} to move media position to
     * a sync (or key) frame associated with a data source that is located
     * right before or at the given time.
     *
     * @see #seekTo(long, int)
     */
    public static final int SEEK_PREVIOUS_SYNC    = 0x00;
/**
     * This mode is used with {@link #seekTo(long, int)} to move media position to
     * a sync (or key) frame associated with a data source that is located
     * right after or at the given time.
     *
     * @see #seekTo(long, int)
     */
    public static final int SEEK_NEXT_SYNC        = 0x01;
/**
     * This mode is used with {@link #seekTo(long, int)} to move media position to
     * a sync (or key) frame associated with a data source that is located
     * closest to (in time) or at the given time.
     *
     * @see #seekTo(long, int)
     */
    public static final int SEEK_CLOSEST_SYNC     = 0x02;
/**
     * This mode is used with {@link #seekTo(long, int)} to move media position to
     * a frame (not necessarily a key frame) associated with a data source that
     * is located closest to or at the given time.
     *
     * @see #seekTo(long, int)
     */
    public static final int SEEK_CLOSEST          = 0x03;

在系统大于等于8.0的手机上只要调用seekTo(time,SEEK_CLOSEST)的方法就可以解决问题了。

相关文章

网友评论

      本文标题:Android MediaPlayer SeekTo方法调用后会

      本文链接:https://www.haomeiwen.com/subject/bleczktx.html