Android MediaPlayer Seekto Tuning instructions on version 8.0

Source: Internet
Author: User

When Android uses MediaPlayer to play video video, when the user exits the current play and resumes playback from the background, it needs to jump to the point where it left off before resuming playback. The method used is basically the point of time before the Seekto, but often encountered the problem of the position is not allowed to resume playback, and even began to play the phenomenon. This is due to the fact that the seekto is going back to the keyframe near the previous time point.

To address this issue, new solutions have been available on the latest Android 8.0 platforms:

The Seekto () method adds a multi-parameter method to the Android O platform:

void Seekto (longint mode)

Here's the mode incoming

Int

There will be no playback of the video location is inaccurate.

/*** Seek modes used in method Seekto (long, int.) to move media position * to a specified location.     These mode values without updating their counterparts * in include/media/imediasource.h! */    /*** This mode was used with {@link#seekTo (long, int)} to move media position to * a sync (or key) frame associated with a data source this is Locat     Ed * right before or at the given time. *     * @see#seekTo (long, int)*/     Public Static Final intSeek_previous_sync = 0x00; /*** This mode was used with {@link#seekTo (long, int)} to move media position to * a sync (or key) frame associated with a data source this is Locat     Ed * right after or at the given time. *     * @see#seekTo (long, int)*/     Public Static Final intSeek_next_sync = 0x01; /*** This mode was used with {@link#seekTo (long, int)} to move media position to * a sync (or key) frame associated with a data source this is Locat     Ed * closest to (in time) or at the given time. *     * @see#seekTo (long, int)*/     Public Static Final intSeek_closest_sync = 0x02; /*** This mode was used with {@link#seekTo (long, int)} to move media position to * a frame (not necessarily a key frame) associated with a data sour     Ce that's located closest to or at the given time. *     * @see#seekTo (long, int)*/     Public Static Final intSeek_closest = 0x03; /**@hide*/@IntDef (Value={seek_previous_sync, Seek_next_sync, Seek_closest_sync, Seek_closest, }) @Retention (Retentionpolicy.source) Public@InterfaceSeekmode {}Private native Final void_seekto (Longmsecintmode); /*** Moves The media to specified time position by considering the given mode.     * <p> * When Seekto is finished, the user would be notified via Onseekcomplete supplied by the user. * There is at the most one active seekto processed in any time.     If there is a to-be-completed * seekto, new Seekto requests would be queued in such a The * is kept. When current Seekto is completed, the queued request would be a processed if * that request was different from Just-finish     Ed Seekto operation, i.e, the requested * position or mode is different. *     * @parammsec The offset in milliseconds from the start to seek. * When seeking to the given time position, there are no guarantee that the data source * have a frame located at the Pos Ition.     When this happens, a frame nearby'll be rendered.     * If msec is negative, time position zero would be used.     * If msec is larger than duration, duration would be used. * @parammode the mode indicating where exactly to seek. * Use {@link#SEEK_PREVIOUS_SYNC} If one wants to SEEK to a SYNC frame * This has a timestamp earlier than or the same as msec . Use * {@link#SEEK_NEXT_SYNC} If one wants to SEEK for a SYNC frame * that have a timestamp later than or the same as msec. Use * {@link#SEEK_CLOSEST_SYNC} If one wants to SEEK for a SYNC frame * that have a timestamp CLOSEST to or the same as msec. U SE * {@link#SEEK_CLOSEST} If one wants to SEEK to a frame, the May * or could not be a sync frame but was CLOSEST to or the SAM     e as msec. * {@link#SEEK_CLOSEST} often have larger performance overhead compared * to the other options if there is no sync frame lo     cated at msec. * @throwsIllegalStateException If the internal player engine has a not been * initialized *@throwsIllegalArgumentException If the mode is invalid. */     Public voidSeekto (Longmsec, @SeekModeintmode) {        if(Mode < Seek_previous_sync | | mode >seek_closest) {            FinalString msg = "Illegal seek mode:" +mode; Throw Newillegalargumentexception (msg); }        //Todo:pass long to native, instead of truncating.        if(msec >integer.max_value) {LOG.W (TAG,"Seekto offset" + msec + "is too large, cap to" +integer.max_value); msec=Integer.max_value; } Else if(Msec <integer.min_value) {LOG.W (TAG,"Seekto offset" + msec + "is too small, cap to" +integer.min_value); msec=Integer.min_value;    } _seekto (msec, mode); }

Android MediaPlayer Seekto Tuning instructions on version 8.0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.