Basic knowledge about Android mediaplayer

Source: Internet
Author: User
Document directory
  • Valid and invalid states
  • How can I get the total length and current playback Time of the current video?

 

Valid and invalid states

Method Name

Valid Sates

Invalid states

Comments

Attachauxeffect

{Initialized, prepared, started, paused, stopped, playbackcompleted}

{Idle, error}

This method must be called after setdatasource. Calling it does not change the object state.

Getaudiosessionid

Any

{}

This method can be called in any state and calling it does not change the object state.

Getcurrentposition

{Idle, initialized, prepared, started, paused, stopped, playbackcompleted}

{Error}

Successful invoke of this method in a valid State does not change the state. Calling this method in an invalid state transfers the object toErrorState.

Getduration

{Prepared, started, paused, stopped, playbackcompleted}

{Idle, initialized, error}

Successful invoke of this method in a valid State does not change the state. Calling this method in an invalid state transfers the object toErrorState.

Getvideoheight

{Idle, initialized, prepared, started, paused, stopped, playbackcompleted}

{Error}

Successful invoke of this method in a valid State does not change the state. Calling this method in an invalid state transfers the object toErrorState.

Getvideowidth

{Idle, initialized, prepared, started, paused, stopped, playbackcompleted}

{Error}

Successful invoke of this method in a valid State does not change the state. Calling this method in an invalid state transfers the object toErrorState.

Isplaying

{Idle, initialized, prepared, started, paused, stopped, playbackcompleted}

{Error}

Successful invoke of this method in a valid State does not change the state. Calling this method in an invalid state transfers the object toErrorState.

Pause

{Started, paused}

{Idle, initialized, prepared, stopped, playbackcompleted, error}

Successful invoke of this method in a valid state transfers the object toPausedState. Calling this method in an invalid state transfers the object toErrorState.

Prepare

{Initialized, stopped}

{Idle, prepared, started, paused, playbackcompleted, error}

Successful invoke of this method in a valid state transfers the object toPreparedState. Calling this method in an invalid state throws an illegalstateexception.

Prepareasync

{Initialized, stopped}

{Idle, prepared, started, paused, playbackcompleted, error}

Successful invoke of this method in a valid state transfers the object toPreparingState. Calling this method in an invalid state throws an illegalstateexception.

Release

Any

{}

Afterrelease(), The object is no longer available.

Reset

{Idle, initialized, prepared, started, paused, stopped, playbackcompleted, error}

{}

Afterreset(), The object is like being just created.

Seekto

{Prepared, started, paused, playbackcompleted}

{Idle, initialized, stopped, error}

Successful invoke of this method in a valid State does not change the state. Calling this method in an invalid state transfers the object toErrorState.

Setaudiosessionid

{Idle}

{Initialized, prepared, started, paused, stopped, playbackcompleted, error}

This method must be called in idle state as the audio session ID must be known before calling setdatasource. Calling it does not change the object state.

Setaudiostreamtype

{Idle, initialized, stopped, prepared, started, paused, playbackcompleted}

{Error}

Successful invoke of this method does not change the State. In order for the target audio stream type to become valid tive, this method must be called before prepare () or prepareasync ().

Setauxeffectsendlevel

Any

{}

Calling this method does not change the object state.

Setdatasource

{Idle}

{Initialized, prepared, started, paused, stopped, playbackcompleted, error}

Successful invoke of this method in a valid state transfers the object toInitializedState. Calling this method in an invalid state throws an illegalstateexception.

Setdisplay

Any

{}

This method can be called in any state and calling it does not change the object state.

Setsurface

Any

{}

This method can be called in any state and calling it does not change the object state.

Setlooping

{Idle, initialized, stopped, prepared, started, paused, playbackcompleted}

{Error}

Successful invoke of this method in a valid State does not change the state. Calling this method in an invalid state transfers the object toErrorState.

Islooping

Any

{}

This method can be called in any state and calling it does not change the object state.

Setonbufferingupdatelistener

Any

{}

This method can be called in any state and calling it does not change the object state.

Setoncompletionlistener

Any

{}

This method can be called in any state and calling it does not change the object state.

Setonerrorlistener

Any

{}

This method can be called in any state and calling it does not change the object state.

Setonpreparedlistener

Any

{}

This method can be called in any state and calling it does not change the object state.

Setonseekcompletelistener

Any

{}

This method can be called in any state and calling it does not change the object state.

Setscreenonwhileplaying </> Any

{}

This method can be called in any state and calling it does not change the object state.

Setvolume

{Idle, initialized, stopped, prepared, started, paused, playbackcompleted}

{Error}

Successful invoke of this method does not change the state.
Setwakemode

Any

{}

This method can be called in any state and calling it does not change the object state.

Start

{Prepared, started, paused, playbackcompleted}

{Idle, initialized, stopped, error}

Successful invoke of this method in a valid state transfers the object toStartedState. Calling this method in an invalid state transfers the object toErrorState.

Stop

{Prepared, started, stopped, paused, playbackcompleted}

{Idle, initialized, error}

Successful invoke of this method in a valid state transfers the object toStoppedState. Calling this method in an invalid state transfers the object toErrorState.

How can I get the total length and current playback Time of the current video?

1) Call mediaplayer. getduration () according to the status requirements in the preceding table to obtain the total duration.

2) create a new thread and call mediaplayer. getcurrentposition () every second to obtain the current playback time.

 

 

 

Related Article

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.