admin
2021-07-15 49982f5a1a305c0cc7da04735e1c604b802d2a22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.yeshi.video.utils;
 
import android.content.Context;
import android.webkit.JavascriptInterface;
 
 
import com.yeshi.video.entity.UserInfoVO;
 
import org.json.JSONObject;
 
public class PPJavaInterface {
    private static final String TAG = "PPJavaInterface";
    private Context mContext;
    private IEventListener eventListener;
 
    public PPJavaInterface(Context context, IEventListener eventListener) {
        mContext = context;
        this.eventListener = eventListener;
    }
 
 
    /**
     * 跳转登录页
     */
    @JavascriptInterface
    public void login() {
        eventListener.onLogin();
    }
 
 
    /**
     * 返回用户信息(JSON格式)。
     * code为0标识用户未登录,data的值为空;
     * code为1表示用户已经登录,data为用户信息
     * 如: {"code":1,"data":{"code":"123","nickname":"昵称","isSVip":false,"isCoupon":false}}
     *
     * @return
     */
    @JavascriptInterface
    public String getUserInfo() {
        try {
            JSONObject root = new JSONObject();
            UserInfoVO user = null;//UserUtil.getLoginUserInfoDetail(mContext);
            if (user == null) {
                root.put("code", 0);
            } else {
                root.put("code", 1);
                JSONObject data = new JSONObject();
                data.put("code", user.getPptvCode());
                data.put("nickname", user.getNickName());
                data.put("isSVip", "false");
                data.put("isCoupon", false);
                root.put("data", data);
            }
            return root.toString();
        } catch (Exception e) {
 
        }
        return null;
    }
 
 
    /**
     * 试看结束
     */
    @JavascriptInterface
    public void tryPlayFinish() {
        eventListener.onTryPlayFinish();
    }
 
    /**
     * 视频播放完成
     */
    @JavascriptInterface
    public void playFinish() {
        eventListener.onPlayFinish();
    }
 
    /**
     * 视频信息回调
     *
     * @param name 视频名称
     * @param cid
     * @param vid
     */
    @JavascriptInterface
    public void videoInfo(String name, String cid, String vid) {
 
    }
 
    @JavascriptInterface
    public void stopPlay(String cid, String vid, int currentTime) {
 
    }
 
 
    public interface IEventListener {
        public void onLogin();
 
        public void onTryPlayFinish();
 
        public void onPlayFinish();
 
 
    }
 
}