Threeivity.java
11.6 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package xdycom.abao.myapplication;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import com.eventhandle.SmartEventCallback;
import com.google.gson.Gson;
import com.mang.xdy.core.XdySdk;
import com.mang.xdy.utils.XdyLogUtil;
import com.mang.xdy.utils.XdyStringUtils;
import xdycom.abao.myapplication.entity.LiveBean;
import xdycom.abao.myapplication.utisl.StringUtils;
import static xdycom.abao.myapplication.MainActivity.stringToJson;
public class Threeivity extends AppCompatActivity implements View.OnClickListener{
private Button bt_three,bt_video
,bt_paudio,bt_stopaudiopub,bt_back,bt_stopReco;
private WebView webView;
private final static String URL="http://h5.test.3mang.com/web/";
private SurfaceView surface;
private Button bt_stop;
private XdySdk xdySdk;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_threeivity);
xdySdk=XdySdk.getXdyInstance();
bt_three= (Button) findViewById(R.id.bt_three);
bt_video= (Button) findViewById(R.id.bt_video);
surface= (SurfaceView) findViewById(R.id.surface);
bt_stop= (Button) findViewById(R.id.bt_stop);
bt_paudio= (Button) findViewById(R.id.bt_paudio);
bt_paudio.setOnClickListener(this);
bt_stopaudiopub= (Button) findViewById(R.id.bt_stopaudiopub);
bt_back= (Button) findViewById(R.id.bt_back);
bt_back.setOnClickListener(this);
bt_stopaudiopub.setOnClickListener(this);
bt_stopReco= (Button) findViewById(R.id.bt_stopReco);
bt_stopReco.setOnClickListener(this);
bt_three.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String id="init";
String jsonParmps="{\n" +
" \"classId\": 1184939098,\n" +
" \"portal\": \"112.126.80.182:90\",\n" +
" \"userRole\": \"normal\",\n" +
" \"userName\": \"\",\n" +
" \"userId\": 0\n" +
"}";
String jsonParmp= StringUtils.stringToJson(jsonParmps,true);
getSdySdk(id,jsonParmp);
}
});
bt_video.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String id = "joinClass";
String temp = "{\n" +
" \"userName\":\"base\",\n" +
" \"password\":\"123321\",\n" +
" \"hasCamera\":false,\n" +
" \"hasMicrophone\":false}";
// "}";
String jsonParmp = stringToJson(temp, true);
getSdySdk(id,jsonParmp);
// SmartPlayerNoLayout smartPlayerNoLayout=new SmartPlayerNoLayout(surface, Threeivity.this);
// startActivity(new Intent(Threeivity.this,SmartPlayer.class));
String url= "rtmp://123.56.205.116:6000/live/h5dev_1999957388_980_983041_1491813919";;
//// XdyPlayer xdyPlayer=new XdyPlayer(url,surface,Threeivity.this);
//// xdyPlayer.playVideo(url,surface);
// XdySdk.setAsyncApi("playAudio",url,null,Threeivity.this);
// XdySdk.setAsyncApi("playVideo",url,surface,Threeivity.this,new EventHande());
xdySdk.api("publishVideo",url,surface,Threeivity.this);
// xdyPlayer.playVideo("",surface);
// XdyPublisher xdyPublisherCore=new XdyPublisher(Threeivity.this);
// xdyPublisherCore.publish("",surface);
}
});
bt_stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// xdySdk.onPlayStop();
// XdySdk.onPublisherStop();;
xdySdk.api("leaveClass","");
}
});
init();
}
public void init(){
webView=new WebView(this);
WebSettings settings=webView.getSettings();
settings.setJavaScriptEnabled(true);
webView.addJavascriptInterface(new MyJsH(),"xdyAndroid");
webView.loadUrl(URL);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.bt_paudio:
//开始推送音频
String url= "rtmp://player.daniulive.com:1935/hls/stream";;
xdySdk.api("publishAudio",url,surface,Threeivity.this);
break;
case R.id.bt_stopaudiopub:
//停止
// XdySdk.setAsyncApi("unPublishAudio","");
String id="initRecordPlayback";
// String id="startRecordPlayback";
String param="{\n" +
" \"classId\": 479270427 ,\n" +
" \"portal\": \"112.126.80.182:90\",\n" +
" \"userRole\": \"normal\",\n" +
" \"userName\": \"\",\n" +
" \"userId\": 0\n" +
"}";
String ss=StringUtils.stringToJson(param,true);
xdySdk.api(id,ss);
break;
case R.id.bt_back:
// String id="initRecordPlayback";
String ids="startRecordPlayback";
// String param="{\n" +
// " \"classId\": 1184939098,\n" +
// " \"portal\": \"112.126.80.182:90\",\n" +
// " \"userRole\": \"normal\",\n" +
// " \"userName\": \"\",\n" +
// " \"userId\": 0\n" +
// "}";
// String ss=StringUtils.stringToJson(param,true);
xdySdk.api(ids,"");
break;
case R.id.bt_stopReco:
// String isd="stopRecordPlayback";
// XdySdk.setAsyncApi(isd,"");
// String ids_new="seekRecordPlayback";
// String tem="{\n" +
// " \"time\": 50\n" +
// "}";
// String s= StringUtils.stringToJson(tem,true);
// XdySdk.setAsyncApi(ids_new,s);
String ids_new="getVideoPublishPath";
String tem="{ \"type\": \"live\"}";
String s= StringUtils.stringToJson(tem,true);
xdySdk.api(ids_new,s);
break;
}
}
class MyJsH{
@JavascriptInterface
public String _js2native(String id,String parmp){
/* _native2js("接口名称","参数为JOSN字符串")*/
Log.e("s3sjs2native","id:"+id+" parmp:"+parmp);
return parmp;
}
}
public void getSdySdk(String id,String parameter){
// XdyCore core=XdyCore.getInstance(MyApplicaiton.getInstance());
// core.native2js(id,parameter);
// core.setXdyAsyncMessageListener(new XdyCore.XdyAsyncMessageListener() {
// @Override
// public void getSdyAsyncMessageListener(String s, String s1) {
// LogUtil.e("java_native",s+":"+s1);
// }
// });
xdySdk.api(id,parameter);
// XdySdk.getXdyInstance().setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
// @Override
// public void onXdyAsyncMessageReceiver(String type, String response) {
// XdyLogUtil.e("学点云",type+":"+response);
// }
// });
// XdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
// @Override
// public void onXdyAsyncMessageReceiver(String type, String response) {
// XdyLogUtil.e("学点云static", type + ":" + response);
//// if ("video_play".equals(type)) {
//// MessageBean messageBean = new Gson().fromJson(response, MessageBean.class);
//// if (messageBean != null) {
////// Intent intent = new Intent(Threeivity.this, SmartPlayer.class);
////// intent.putExtra("url", messageBean.getRtmpUrl() + "");
////// startActivity(intent);
//// Toast.makeText(Threeivity.this, messageBean.getRtmpUrl(), Toast.LENGTH_SHORT).show();
////// SmartPlayerNoLayout smartPlayerNoLayout=new SmartPlayerNoLayout(surface,Threeivity.this);
//// }
//// }
// if("live".equals(type)){
//// String urls= "rtmp://player.daniulive.com:1935/hls/stream";;
// String url = XdyStringUtils.stringToJson(response);
// XdyLogUtil.e("调用任务了播视频了url:",""+url);
// String us=response.substring(1,response.length()-1);
// XdyLogUtil.e("调用任务了播视频了ursfdfl:",""+us);
// try {
//
// LiveBean liveBean = new Gson().fromJson(url, LiveBean.class);
//
// if (liveBean != null) {
// XdySdk.setAsyncApi("publishVideo", liveBean.getPublishUrl(), surface, Threeivity.this);
// XdyLogUtil.e("调用任务了播视频了","哈哈哈哈");
// }
// }catch (Exception e){
// XdyLogUtil.e("调用任务了播视频了e",""+e.getMessage());
// XdyLogUtil.e("调用任务了播视频了url:",""+url);
// }
// }
// }
// });
}
public void playMedia(){
Intent intent = new Intent(Intent.ACTION_VIEW);
String bpath = "http://123.56.73.119:6001/live/h5dev_1184939098_980_983041_1491533378/total.m3u8";
intent.setDataAndType(Uri.parse(bpath), "video/*");
startActivity(intent);
}
}
class EventHande implements SmartEventCallback {
private static String TAG="THREURL";
@Override
public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) {
switch (code) {
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:
Log.i(TAG, "开始。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:
Log.i(TAG, "连接中。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:
Log.i(TAG, "连接失败。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:
Log.i(TAG, "连接成功。。");
//TODO
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
Log.i(TAG, "连接断开。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
Log.i(TAG, "关闭。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
Log.i(TAG, "收不到媒体数据,可能是url错误。。");
}
}
}