package com.wisewoods.eduandroid.ui;

import android.content.Intent;
import android.os.Bundle;

import com.blankj.utilcode.util.ActivityUtils;
import com.danikula.videocache.HttpProxyCacheServer;
import com.wisewoods.base.base.BaseActivity;
import com.wisewoods.eduandroid.view.cache.ProxyVideoCacheManager;

import xyz.doikki.videocontroller.StandardVideoController;
import xyz.doikki.videoplayer.player.VideoView;

public class JzVideoActivity extends BaseActivity {

    private VideoView jzVideo;

    public static void start(String url) {
        Intent intent = new Intent(ActivityUtils.getTopActivity(), JzVideoActivity.class);
        intent.putExtra("url", url);
        ActivityUtils.startActivity(intent);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        String url = getIntent().getStringExtra("url");
        jzVideo = new VideoView(this);
        setContentView(jzVideo);

        HttpProxyCacheServer cacheServer = ProxyVideoCacheManager.getProxy(activity);
        String proxyUrl = cacheServer.getProxyUrl(url);
        jzVideo.setUrl(proxyUrl);
        StandardVideoController controller = new StandardVideoController(activity);
        controller.addDefaultControlComponent("", false);
        jzVideo.setVideoController(controller);
        jzVideo.start(); //开始播放，不调用则不自动播放
    }

    @Override
    protected void onPause() {
        super.onPause();
        jzVideo.pause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        jzVideo.resume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        jzVideo.release();
    }


    @Override
    public void onBackPressed() {
        if (!jzVideo.onBackPressed()) {
            super.onBackPressed();
        }
    }
}
