Search in sources :

Example 1 with OnInfoListener

use of android.media.MediaPlayer.OnInfoListener in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class FingerprintLocationAnimationVideoView method onFinishInflate.

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    setSurfaceTextureListener(new SurfaceTextureListener() {

        private SurfaceTexture mTextureToDestroy = null;

        @Override
        public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
            setVisibility(View.INVISIBLE);
            Uri videoUri = getFingerprintLocationAnimation();
            if (mMediaPlayer != null) {
                mMediaPlayer.release();
            }
            if (mTextureToDestroy != null) {
                mTextureToDestroy.release();
                mTextureToDestroy = null;
            }
            mMediaPlayer = MediaPlayer.create(mContext, videoUri);
            mMediaPlayer.setSurface(new Surface(surfaceTexture));
            mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {

                @Override
                public void onPrepared(MediaPlayer mediaPlayer) {
                    mediaPlayer.setLooping(true);
                }
            });
            mMediaPlayer.setOnInfoListener(new OnInfoListener() {

                @Override
                public boolean onInfo(MediaPlayer mediaPlayer, int what, int extra) {
                    if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
                        // Keep the view hidden until video starts
                        setVisibility(View.VISIBLE);
                    }
                    return false;
                }
            });
            mAspect = (float) mMediaPlayer.getVideoHeight() / mMediaPlayer.getVideoWidth();
            requestLayout();
            startAnimation();
        }

        @Override
        public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width, int height) {
        }

        @Override
        public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
            mTextureToDestroy = surfaceTexture;
            return false;
        }

        @Override
        public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
        }
    });
}
Also used : OnInfoListener(android.media.MediaPlayer.OnInfoListener) SurfaceTexture(android.graphics.SurfaceTexture) OnPreparedListener(android.media.MediaPlayer.OnPreparedListener) Uri(android.net.Uri) Surface(android.view.Surface) MediaPlayer(android.media.MediaPlayer)

Aggregations

SurfaceTexture (android.graphics.SurfaceTexture)1 MediaPlayer (android.media.MediaPlayer)1 OnInfoListener (android.media.MediaPlayer.OnInfoListener)1 OnPreparedListener (android.media.MediaPlayer.OnPreparedListener)1 Uri (android.net.Uri)1 Surface (android.view.Surface)1