使用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)的方法就可以解决问题了。
网友评论