IT_Programming/Android_Java

[Android] MediaPlayer with SurfaceHolder

JJun ™ 2014. 8. 16. 18:30



 출처: http://yhcting.tistory.com/m/post/309




Sometimes developer may need to use MediaPlayer directly instead of using VideoView.

In this case, developer should keep belows in his/her mind.


<NOTE : Gingerbread and ICS are a little different (ICS is more flexible. But, the more strict is the better.)>

 - setDisplay Should be called after surface of SurfaceHolder is created.

 - video should be started after it's video size is known (after onVideoSizeChanged is called.)

 - setDisplay() should be called before prepare()


Let's summarize it.


onSurfaceCreate -> setDisplay() -> prepare()/prepareAsync()

: onVideoSizechanged

: onPrepared


→ Now, MediaPlayer is fully prepared to be started.