huangxinbao

add replay

正在显示 23 个修改的文件 包含 1444 行增加1238 行删除
... ... @@ -35,7 +35,6 @@ dependencies {
compile project(':xdy')
compile files('libs/pldroid-player-1.5.1.jar')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.jakewharton:butterknife:8.5.1'
... ... @@ -53,4 +52,6 @@ dependencies {
compile 'com.android.support:support-v4:25.3.1'
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
compile 'com.qiniu:happy-dns:0.2.+'
compile 'org.greenrobot:eventbus:3.0.0'
}
... ...
This file is too large to display.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mang.xdy.demo">
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
... ... @@ -25,6 +25,15 @@
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:name=".application.XdyApplicaiton"
... ...
... ... @@ -9,13 +9,15 @@ import android.widget.Button;
import android.widget.EditText;
import com.google.gson.Gson;
import com.mang.xdy.demo.activity.AudioPublisherActivity;
import com.mang.xdy.demo.activity.VideoPlayActivity;
import com.mang.xdy.demo.activity.VideoPublisherActivity;
import com.mang.xdy.demo.bean.JoinClass;
import com.mang.xdy.demo.bean.JoinClassBean;
import com.mang.xdy.demo.utils.ToastUtil;
import com.mang.xdy.utils.XdyLogUtil;
import java.util.ArrayList;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
... ... @@ -49,22 +51,29 @@ public class MainActivity extends AppCompatActivity {
if(TextUtils.isEmpty(joinClass())){
return;
}
ArrayList<String> arrayList=new ArrayList<>();
switch (view.getId()){
case R.id.btn_home_enter_class:
Intent intent=new Intent(MainActivity.this, VideoPlayActivity.class);
intent.putExtra("init",joinClass());
arrayList.clear();
arrayList.add(joinClass());
arrayList.add("normal");
intent.putStringArrayListExtra("init",arrayList);
startActivity(intent);
break;
case R.id.btn_home_enter_publisher:
Intent intents=new Intent(MainActivity.this, VideoPublisherActivity.class);
intents.putExtra("init",joinClass());
Intent intents=new Intent(MainActivity.this, VideoPlayActivity.class);
arrayList.clear();
arrayList.add(joinClass());
arrayList.add("");
intents.putStringArrayListExtra("init",arrayList);
startActivity(intents);
break;
case R.id.btn_home_enter_publisherAudio:
Intent intent_audio=new Intent(MainActivity.this, AudioPublisherActivity.class);
intent_audio.putExtra("init",joinClass());
startActivity(intent_audio);
// Intent intent_audio=new Intent(MainActivity.this, AudioPublisherActivity.class);
// intent_audio.putExtra("init",joinClass());
// startActivity(intent_audio);
break;
}
}
... ...
package com.mang.xdy.demo.activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.eventhandle.SmartEventCallback;
import com.google.gson.Gson;
import com.mang.xdy.common.Constants;
import com.mang.xdy.core.XdySdk;
import com.mang.xdy.demo.R;
import com.mang.xdy.demo.adapter.SimpleFragmentPagerAdapter;
import com.mang.xdy.demo.bean.AudioPlayBean;
import com.mang.xdy.demo.bean.ChatBean;
import com.mang.xdy.demo.bean.DocEntity;
import com.mang.xdy.demo.bean.InitClassSuccessEntity;
import com.mang.xdy.demo.bean.JoinClass;
import com.mang.xdy.demo.bean.LiveBean;
import com.mang.xdy.demo.bean.PublisherEntity;
import com.mang.xdy.demo.bean.VideoPlayBean;
import com.mang.xdy.demo.utils.JsonUtil;
import com.mang.xdy.demo.utils.ToastUtil;
import com.mang.xdy.utils.XdyLogUtil;
import com.mang.xdy.utils.XdyStringUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class AudioPublisherActivity extends AppCompatActivity {
private final static String TAG = "VideoPlayActivity";
@BindView(R.id.btn_videoPlay_pubsherVideo)
Button btnVideoPlayPubsherVideo;
@BindView(R.id.btn_videoPlay_chat)
Button btnVideoPlayChat;
@BindView(R.id.tv_videoPlay_url)
TextView tv_videoPlay_url;
@BindView(R.id.surfaceview_pubisherVideo)
SurfaceView surfaceview_pubisherVideo;
@BindView(R.id.btn_videoPlay_publisherAudio)
Button btn_videoPlay_publisherAudio;
@BindView(R.id.btn_videoPlay_stop)
Button btn_videoPlay_stop;
// @BindView(R.id.img_playVideo_novideo)
// ImageView img_playVideo_novideo;
private String username="";
private String userpwd="";
private PersonDialog personDialog;
private SimpleFragmentPagerAdapter pagerAdapter;
private ViewPager viewPager;
//默认推送视频
private boolean isPusherAudio=false;
private TabLayout tabLayout;
@BindView(R.id.surfaceview_playVideo)
SurfaceView surfaceviewPlayVideo;
private String initClass = "";
private String publisherSuccess="";
private XdySdk xdySdk;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case -2:
//加入课堂输入用户名,密码
joinClass("", (Boolean) msg.obj);
break;
case -1:
//退出
xdySdk.api("leaveClass", "");
break;
case 0:
parseJoinClass((String) msg.obj,true);
break;
case 1:
//播放视频
playVideo((String) msg.obj);
XdyLogUtil.e(TAG,"当前线程 handdler:"+android.os.Process.myPid()+""+"线程:"+Thread.currentThread().getId()+"");
break;
case 2:
//播放音频
playAudio((String) msg.obj);
break;
case 3:
getDoc((String) msg.obj);
break;
case 4:
//发送消息
sendMeg();
break;
case 5:
//接受消息
getMsg((String) msg.obj);
break;
case 6:
//推流video
publisherVideo((String) msg.obj);
break;
case 7:
//停止播放
// xdySdk.onPlayStop();
// img_playVideo_novideo.setVisibility(View.GONE);
// surfaceviewPlayVideo.refreshDrawableState();;
// ToastUtil.showToastshort("播放音视/视频停止",VideoPlayActivity.this);
break;
case 8:
btnVideoPlayPubsherVideo.setEnabled(true);
btn_videoPlay_publisherAudio.setEnabled(true);
break;
}
}
};
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //屏幕常亮
setContentView(R.layout.activity_video_publisher);
ButterKnife.bind(this);
xdySdk=XdySdk.getXdyInstance();
btnVideoPlayPubsherVideo.setVisibility(View.GONE);
// setTablayout();
init();
XdyLogUtil.e(TAG,"当前线程 main:"+android.os.Process.myPid()+"线程:"+Thread.currentThread().getId()+"");
xdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
@Override
public void onXdyAsyncMessageReceiver(String type, String response) {
switch (type) {
case "class_init_success":
ToastUtil.showToastshort("初始化课堂成功", AudioPublisherActivity.this);
Message message = Message.obtain();
message.obj = response;
message.what = 0;
handler.sendMessage(message);
break;
case "class_join_success":
//加入课堂成功
ToastUtil.showToastshort("加入课堂成功", AudioPublisherActivity.this);
//只有加入课堂成功才可以点击推流的按钮
handler.sendEmptyMessage(8);
break;
case "live":
// String urls= "rtmp://player.daniulive.com:1935/hls/stream";;
//推流直播
Message message1=Message.obtain();
message1.obj = response;
message1.what = 6;
handler.sendMessage(message1);
break;
case "video_stop":
// handler.sendEmptyMessage(7);
break;
case "audio_stop":
break;
}
}
});
}
public void init() {
initClass = getIntent().getStringExtra("init");
xdySdk.api("init", initClass);
}
//判断解析是否有密码
public void parseJoinClass(String rsponse,boolean isShowPwd){
InitClassSuccessEntity initClassSuccessEntity=JsonUtil.parseJsonToBean(rsponse,InitClassSuccessEntity.class);
if(initClassSuccessEntity!=null)
if(initClassSuccessEntity.isPasswordRequired()){
personDialog=new PersonDialog(this,true);
}else{
personDialog=new PersonDialog(this,false);
userpwd="123321";
}
personDialog.show();
}
//加入课堂
public void joinClass(String rsponse,boolean isShowPwd) {
// String temp = "{\n" +
// " \"userName\":\"base\",\n" +
// " \"password\":\"123321\",\n" +
// " \"hasCamera\":false,\n" +
// " \"hasMicrophone\":false}";
JoinClass joinClass=new JoinClass();
joinClass.setHasCamera(false);
joinClass.setHasMicrophone(false);
joinClass.setUserName(username);
if(!isShowPwd){
joinClass.setPassword("123321");
}else{
joinClass.setPassword(userpwd);
}
String temp=new Gson().toJson(joinClass);
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e("加入课堂", jsonParmp);
xdySdk.api("joinClass", jsonParmp);
}
public void playVideo(String response) {
// VideoPlayBean videoPlayBean = JsonUtil.parseJsonToBean(response, VideoPlayBean.class);
// if (videoPlayBean != null && videoPlayBean.getRtmpUrl() != null)
// XdyLogUtil.e(TAG, "执行了ss" + videoPlayBean.getRtmpUrl());
// xdySdk.api("playVideo", videoPlayBean.getRtmpUrl(), surfaceviewPlayVideo, AudioPublisherActivity.this, new EventHande_Video());
//// img_playVideo_novideo.setVisibility(View.GONE);
// ToastUtil.showToastshort("视频播放初始化",AudioPublisherActivity.this);
}
public void playAudio(String response) {
// AudioPlayBean audioPlayBean = JsonUtil.parseJsonToBean(response, AudioPlayBean.class);
// if (audioPlayBean != null && audioPlayBean.getRtmpUrl() != null) {
// XdyLogUtil.e(TAG, "执行了" + audioPlayBean.getRtmpUrl());
// xdySdk.api("playAudio", audioPlayBean.getRtmpUrl(), null, AudioPublisherActivity.this, new EventHande_Video());
//// img_playVideo_novideo.setVisibility(View.GONE);
// ToastUtil.showToastshort("音频播放初始化",AudioPublisherActivity.this);
// }
}
public void getDoc(String response) {
DocEntity docEntity = JsonUtil.parseJsonToBean(response, DocEntity.class);
if (docEntity != null && docEntity.getRelativeUrl() != null) {
String url = docEntity.getRelativeUrl();
String temp = "{\n" +
" \"type\": \"jpg\",\n" +
" \"pageNum\": 1,\n" +
" \"relativeUrl\": \" '" + url + "'\"\n" +
"}";
// String temp = "{\n" +
// " \"type\": \"jpg\",\n" +
// " \"pageNum\": 1,\n" +
// " \"relativeUrl\": \"/DocSharing/data/1087553281/20170409-204600041/d32594763768243bddc64934be5088a0.jpg\"\n" +
// "}";
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e(TAG, "文档" + jsonParmp);
xdySdk.api("getDocImageFullPath", jsonParmp);
}
}
public void sendMeg() {
String temp = "{\n" +
" \"message\": \"固定发送测试 hello\",\n" +
" \"to\": 0\n" +
"}";
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e(TAG, "聊天" + jsonParmp);
xdySdk.api("sendChatMsg", jsonParmp);
}
//获取聊天信息
public void getMsg(String msg) {
ChatBean chatBean = JsonUtil.parseJsonToBean(msg, ChatBean.class);
if (chatBean != null) {
btnVideoPlayChat.setText(chatBean.getMessage());
}
}
//获取推流地址
public void getPublish() {
String ids_new = "getVideoPublishPath";
String tem = "{ \"type\": \"live\"}";
String s = XdyStringUtils.stringToJson(tem, true);
xdySdk.api(ids_new, s);
}
public void publisherVideo(String response) {
// String url = XdyStringUtils.stringToJson(response);
// XdyLogUtil.e("调用任务了播url:", "" + url);
// String us = response.substring(1, response.length() - 1);
// try {
// LiveBean liveBean = new Gson().fromJson(url, LiveBean.class);
// if (liveBean != null&&liveBean.getCode()==0&&liveBean.getPublishUrl()!=null) {
//// String url_text="rtmp://player.daniulive.com:1935/hls/stream";
//// String url_text="rtmp://123.56.205.116:6000/live/h5dev_1999957388_980_983041_1491813919";
// publisherSuccess=liveBean.getPublishUrl();
// if(isPusherAudio){
// xdySdk.api("publishAudio", liveBean.getPublishUrl(), surfaceview_pubisherVideo, AudioPublisherActivity.this,new EventHande());
// ToastUtil.showToastshort("推送纯音频初始化中",AudioPublisherActivity.this);
// }else{
// xdySdk.api("publishVideo", liveBean.getPublishUrl(), surfaceview_pubisherVideo, AudioPublisherActivity.this,new EventHande());
// ToastUtil.showToastshort("推送视频初始化中",AudioPublisherActivity.this);
// }
//
// XdyLogUtil.e(TAG,liveBean.getPublishUrl());
// PublisherEntity publisherEntity=new PublisherEntity();
// if(!TextUtils.isEmpty(publisherSuccess)) {
// publisherEntity.setPublishUrl(publisherSuccess);
// String pamp= new Gson().toJson(publisherEntity);
// XdyLogUtil.e("推流成功",""+pamp);
// xdySdk.api("publishVideo",pamp);
// }
//
// }
// } catch (Exception e) {
// XdyLogUtil.e("调用任务了播视频了e", "" + e.getMessage());
//
// }
}
/**
* 测试Audio
*/
public void publisherAudioText(){
xdySdk.api(Constants.PUBLISH_AUDIO, "", surfaceview_pubisherVideo, AudioPublisherActivity.this);
}
@Override
public void onBackPressed() {
xdySdk.api("unPublishVideo","");
super.onBackPressed();
}
@Override
protected void onDestroy() {
xdySdk.onPublisherStop();
super.onDestroy();
}
@OnClick({R.id.btn_videoPlay_chat, R.id.btn_videoPlay_pubsherVideo,R.id.btn_videoPlay_publisherAudio,R.id.btn_videoPlay_stop})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.btn_videoPlay_chat:
handler.sendEmptyMessage(4);
break;
case R.id.btn_videoPlay_pubsherVideo:
// getPublish();
// ToastUtil.showToastshort("推送视频",AudioPublisherActivity.this);
// btnVideoPlayPubsherVideo.setClickable(false);
break;
case R.id.btn_videoPlay_publisherAudio:
//获取推流地址推送音频
// getPublish();
// isPusherAudio=true;
// XdySdk.onPublisherStop();
// ToastUtil.showToastshort("推送音频",AudioPublisherActivity.this);
// btn_videoPlay_publisherAudio.setClickable(false);
publisherAudioText();
break;
case R.id.btn_videoPlay_stop:
ToastUtil.showToastshort("正在退出,请稍等",this);
xdySdk.api("unPublishVideo","");
finish();
break;
}
}
class EventHande implements SmartEventCallback {
@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, "连接成功。。");
// PublisherEntity publisherEntity=new PublisherEntity();
// if(TextUtils.isEmpty(publisherSuccess)) {
// publisherEntity.setPublishUrl(publisherSuccess);
// XdySdk.setAsyncApi("publishVideo", new Gson().toJson(publisherEntity));
// }
//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错误。。");
}
}
}
class EventHande_Video implements SmartEventCallback {
@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错误。。");
}
}
}
class PersonDialog extends Dialog {
public PersonDialog(Context context) {
this(context, false);
}
public PersonDialog(Context context, boolean showPwd) {
this(context, R.style.bottom_dialog, showPwd);
}
public PersonDialog(Context context, int themeResId, boolean showPwd) {
super(context, themeResId);
init(context, showPwd);
}
public void init(Context context, boolean showPwd) {
View view = View.inflate(context, R.layout.dialog_item, null);
setContentView(view);
initView(view,showPwd);
setCanceledOnTouchOutside(false);
Window window = getWindow();
WindowManager.LayoutParams params = window.getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = dp2px(context, 220);
window.setAttributes(params);
window.setGravity(Gravity.CENTER);
}
public int dp2px(Context context, float dp) {
return (int) Math.ceil(context.getResources().getDisplayMetrics().density * dp);
}
public void initView(View view, final boolean showPwd){
final EditText edt_uername= (EditText) view.findViewById(R.id.dialog_edt_username);
final EditText edt_userpwd= (EditText) view.findViewById(R.id.dialog_edt_userpwd);
if(showPwd){
edt_userpwd.setVisibility(View.VISIBLE);
}else{
edt_userpwd.setVisibility(View.GONE);
}
Button btn_enter= (Button) view.findViewById(R.id.dialog_btn_enter);
btn_enter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
username=edt_uername.getText().toString();
userpwd=edt_userpwd.getText().toString();
if(TextUtils.isEmpty(username)){
ToastUtil.showToastshort("用户名不能为空",AudioPublisherActivity.this);
return;
}
if(showPwd&&TextUtils.isEmpty(userpwd)){
ToastUtil.showToastshort("密码不能为空",AudioPublisherActivity.this);
return;
}
dismiss();
Message message=Message.obtain();
message.what=-2;
message.obj=showPwd;
handler.sendMessage(message);
}
});
}
}
}
... ... @@ -2,17 +2,27 @@ package com.mang.xdy.demo.activity;
;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.PixelFormat;
import android.hardware.display.VirtualDisplay;
import android.media.projection.MediaProjection;
import android.media.projection.MediaProjectionManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
... ... @@ -23,6 +33,8 @@ import android.widget.SeekBar;
import android.widget.TextView;
import com.google.gson.Gson;
import com.mang.xdy.bean.VideoPlayBean;
import com.mang.xdy.cache.ACache;
import com.mang.xdy.common.Constants;
import com.mang.xdy.core.SPUtil;
import com.mang.xdy.core.XdySdk;
... ... @@ -32,6 +44,7 @@ import com.mang.xdy.demo.bean.ErrorEntity;
import com.mang.xdy.demo.bean.InitClassSuccessEntity;
import com.mang.xdy.demo.bean.JoinClass;
import com.mang.xdy.demo.bean.ResponseEntity;
import com.mang.xdy.demo.bean.TimeEntity;
import com.mang.xdy.demo.bean.VideoOrAudioStopEntity;
import com.mang.xdy.demo.utils.JsonUtil;
import com.mang.xdy.demo.utils.ToastUtil;
... ... @@ -45,11 +58,14 @@ import com.pili.pldroid.player.AVOptions;
import com.pili.pldroid.player.PLMediaPlayer;
import com.pili.pldroid.player.widget.PLVideoTextureView;
import com.pili.pldroid.player.widget.PLVideoView;
import com.videoengine.NTRenderer;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Locale;
import butterknife.BindView;
... ... @@ -57,7 +73,7 @@ import butterknife.ButterKnife;
import static com.pili.pldroid.player.AVOptions.KEY_DELAY_OPTIMIZATION;
public class VideoPlayActivity extends AppCompatActivity implements ObserverListener, PLMediaPlayer.OnErrorListener, PLMediaPlayer.OnInfoListener {
public class VideoPlayActivity extends AppCompatActivity implements ObserverListener, PLMediaPlayer.OnErrorListener, PLMediaPlayer.OnInfoListener,NoScrollViewPager.OnRplayTouchListener {
private final static String TAG = "VideoPlayActivity";
@BindView(R.id.img_playVideo_novideo)
ImageView img_playVideo_novideo;
... ... @@ -71,6 +87,15 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
private TabLayout tabLayout;
@BindView(R.id.surfaceview_playVideo)
SurfaceView surfaceviewPlayVideo;
@BindView(R.id.fra_videoPlay_publish)
FrameLayout frameLayout_publish;
@BindView(R.id.btn_videoPlay_stopPublish)
Button btn_videoPlay_stopPublish;
/*推流*/
// @BindView(R.id.surfaceview_playVideo_text)
SurfaceView mSurfaceView ;
private String initClass = "";
private XdySdk xdySdk;
private LoginDialog mLoginDialog;
... ... @@ -83,8 +108,10 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
/*mcu断开或者网络原因为false*/
private boolean isDefaultExit=true;
private AlertDialog mErrorDialog;
private ACache aCache;
//TODO 默认回放
private boolean replay = true;
private boolean replay = false;
private Handler mmHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
... ... @@ -93,10 +120,9 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
switch (responseEntity.getType()) {
case Constants.CLASS_EXIT:
xdySdk.removeAll();
ToastUtil.showToast("退出课堂",VideoPlayActivity.this);
progressDialogDismiss();
exit();
exit();
break;
case Constants.ERROR_CODE:
handError(responseEntity.getType(), responseEntity.getParam());
... ... @@ -104,15 +130,25 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
case Constants.CLASS_INIT_SUCCESS:
String login = responseEntity.getParam();
parseJoinClass(login, true);
// ToastUtil.showToastshort("初始化课堂成功", VideoPlayActivity.this);
ToastUtil.showToastshort("初始化课堂成功", VideoPlayActivity.this);
break;
case Constants.CLASS_JOIN_SUCCESS:
//加入课堂成功
progressDialogDismiss();
UIUtils.closeDialog(mLoginDialog);
// ToastUtil.showToastshort("加入课堂成功", VideoPlayActivity.this);
ToastUtil.showToastshort("加入课堂成功", VideoPlayActivity.this);
String userJson = responseEntity.getParam();
SPUtil.putString(VideoPlayActivity.this, Constants.CLASS_JOIN_SUCCESS, userJson);
// JSONObject jsonObject = null;
// try {
// jsonObject = new JSONObject(userJson);
// replay = jsonObject.optBoolean("isRecordPlayBack");
// } catch (JSONException e) {
// e.printStackTrace();
// }
if(replay) {
initRecordSeek(userJson);
}
break;
case Constants.VIDEO_PLAY:
//播放视频
... ... @@ -136,6 +172,13 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
//自定义消息 播放视频音频都通过这个来判断
img_playVideo_novideo.setVisibility(View.GONE);
break;
case Constants.CLASS_UPDATE_TIMER:
if(replay)
handleTime(responseEntity.getParam());
break;
case Constants.RECORD_PLAYBACK_UPDATE:
handleRecord(responseEntity.getParam());
break;
}
... ... @@ -148,21 +191,76 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //屏幕常亮
setContentView(R.layout.activity_video_play);
ButterKnife.bind(this);
aCache=ACache.get(this);
// XdySdk.init(this);
xdySdk = XdySdk.getXdyInstance();
xdySdk.add(this);
init();
progressDialogShow();
setTablayout();
}
public void init() {
initClass = getIntent().getStringExtra("init");
xdySdk.api("init", initClass);
ArrayList<String> arrayList=getIntent().getStringArrayListExtra("init");
if(arrayList!=null&&arrayList.size()>1){
initClass= arrayList.get(0);
if(TextUtils.isEmpty(arrayList.get(1))){
replay=true;
}else {
replay=false;
}
}
if(!replay){
mVideoView.setVisibility(View.GONE);
mMediaContainer.setVisibility(View.GONE);
// btn_videoPlay_exit.setVisibility(View.VISIBLE);
}else{
surfaceviewPlayVideo.setVisibility(View.GONE);
initReplay();
}
// initClass = getIntent().getStringExtra("init");
if(!replay){
xdySdk.api("init", initClass);
}else{
xdySdk.api("initRecordPlayback", initClass);
// xdySdk.api("startRecordPlayback", "");
}
currentTime=0;
btn_videoPlay_stopPublish.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
xdySdk.api("stopPublishVideo", "");
}
});
btn_videoPlay_exit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
xdySdk.api("leaveClass", "");
if (mSurfaceView == null) {
mSurfaceView = NTRenderer.CreateRenderer(VideoPlayActivity.this, false);
}
btn_videoPlay_stopPublish.setVisibility(View.VISIBLE);
btn_videoPlay_exit.setVisibility(View.GONE);
btn_videoPlay_exit.setEnabled(false);
// mSurfaceView=new SurfaceView(VideoPlayActivity.this);
SurfaceHolder sh = mSurfaceView.getHolder();;
sh.setFormat(PixelFormat.TRANSPARENT);
mSurfaceView.setZOrderOnTop(true);
frameLayout_publish.addView(mSurfaceView);
xdySdk.api("publishVideo", "", mSurfaceView, VideoPlayActivity.this);
isVideoMode=true;
// mmHandler.post(new Runnable() {
// @Override
// public void run() {
// initSmall();
// }
// });
// xdySdk.api("leaveClass", "");
//
// xdySdk.remove(VideoPlayActivity.this);
... ... @@ -172,7 +270,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
// exit();
// String id="initRecordPlayback";
// String param="{\n" +
// " \"classId\": 479270427 ,\n" +
// " \"classId\": 391813551,\n" +
// " \"portal\": \"112.126.80.182:90\",\n" +
// " \"userRole\": \"normal\",\n" +
// " \"userName\": \"\",\n" +
... ... @@ -192,8 +290,9 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
}
public void setTablayout() {
pagerAdapter = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), this);
pagerAdapter = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), this,replay);
viewPager.setAdapter(pagerAdapter);
viewPager.setOnRplayTouchListener(this);
tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
// tabLayout.setupWithViewPager(viewPager);
tabLayout.setupWithViewPager(viewPager,false);
... ... @@ -270,22 +369,34 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
* @param response
*/
public void playVideo(String response) {
xdySdk.api("playVideo", response + "", surfaceviewPlayVideo, VideoPlayActivity.this);
progressDialogDismiss();
if(replay){
playRecord(response);
}else {
xdySdk.api("playVideo", response + "", surfaceviewPlayVideo, VideoPlayActivity.this);
// img_playVideo_novideo.setVisibility(View.GONE);
img_playVideo_novideo.setImageResource(R.mipmap.no_video);
ToastUtil.showToastshort("视频播放初始化", VideoPlayActivity.this);
img_playVideo_novideo.setImageResource(R.mipmap.no_video);
ToastUtil.showToastshort("视频播放初始化", VideoPlayActivity.this);
}
}
/**
* 播放音频
*
* @param response
*/
public void playAudio(String response) {
xdySdk.api("playAudio", response, null, VideoPlayActivity.this);
img_playVideo_novideo.setImageResource(R.mipmap.audio_mode);
img_playVideo_novideo.setVisibility(View.VISIBLE);
ToastUtil.showToastshort("音频播放初始化", VideoPlayActivity.this);
if(replay){
playRecord(response);
img_playVideo_novideo.setImageResource(R.mipmap.audio_mode);
img_playVideo_novideo.setVisibility(View.VISIBLE);
}else {
xdySdk.api("playAudio", response, null, VideoPlayActivity.this);
img_playVideo_novideo.setImageResource(R.mipmap.audio_mode);
img_playVideo_novideo.setVisibility(View.VISIBLE);
ToastUtil.showToastshort("音频播放初始化", VideoPlayActivity.this);
}
}
@Override
... ... @@ -303,7 +414,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
@Override
public void onClick(DialogInterface dialogInterface, int i) {
xdySdk.api("leaveClass", "");
//如果收到class_exit 就执行,退出界面
UIUtils.closeDialog(mLoginDialog);
exit();
... ... @@ -361,7 +472,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
case "20000":
isDefaultExit=false;
showErrorDialog();
// ToastUtil.showToastshort(errorEntity.getReson(), this);
ToastUtil.showToastshort(errorEntity.getReson(), this);
break;
}
... ... @@ -372,25 +483,41 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
protected void onPause() {
super.onPause();
xdySdk.onPlayStop(playVideoOrAudioId);
if(isVideoMode){
stopVideo();
}else{
stopAudio();
}
xdySdk.api("pauseRecordPlayback","");
}
@Override
protected void onResume() {
super.onResume();
if(isVideoMode) {
playVideo(playVideoOrAudioId);
}else{
playAudio(playVideoOrAudioId);
}
if (isVideoMode) {
playVideo(playVideoOrAudioId);
} else {
playAudio(playVideoOrAudioId);
}
xdySdk.api("startRecordPlayback","");
}
/**
* 错误情况退出
*/
public void exit() {
xdySdk.api("stopPublishVideo","");
xdySdk.api("leaveClass", "");
xdySdk.remove(this);
xdySdk.onPublisherStop();
if (mVideoView != null ){
mVideoView.stopPlayback();
}
UIUtils.closeDialog(mLoginDialog);
xdySdk.onPlayPauseAll();
if(!replay) {
xdySdk.removeAll();
}
mmHandler.removeCallbacksAndMessages(null);
this.finish();
}
... ... @@ -415,13 +542,23 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
* @param response
*/
public void stopPlay(String response) {
VideoOrAudioStopEntity entity = JsonUtil.parseJsonToBean(response, VideoOrAudioStopEntity.class);
if (entity != null) {
if (xdySdk.onPlayStop(entity.getMediaId() + "")) {
img_playVideo_novideo.setImageResource(R.mipmap.novideo);
img_playVideo_novideo.setVisibility(View.VISIBLE);
if(replay){
if(isVideoMode){
stopVideo();
}else{
stopAudio();
}
}else{
VideoOrAudioStopEntity entity = JsonUtil.parseJsonToBean(response, VideoOrAudioStopEntity.class);
if (entity != null) {
if (xdySdk.onPlayStop(entity.getMediaId() + "")) {
img_playVideo_novideo.setImageResource(R.mipmap.novideo);
img_playVideo_novideo.setVisibility(View.VISIBLE);
}
}
}
}
public void showErrorDialog() {
if(isDefaultExit){
... ... @@ -438,6 +575,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
exit();
}
})
.create();
... ... @@ -455,22 +593,111 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
mmHandler.sendMessage(message);
}
/******************************悬浮********************************/
/**
* 窗口管理者
*/
private WindowManager mWindowManager;
// desk capture
private int mScreenDensity;
private int sreenWindowWidth;
private int screenWindowHeight;
private VirtualDisplay mVirtualDisplay;
private MediaProjectionManager mMediaProjectionManager;
private MediaProjection mMediaProjection;
private SurfaceView bgSurfaceView;
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
private void createScreenEnvironment() {
sreenWindowWidth = mWindowManager.getDefaultDisplay().getWidth();
screenWindowHeight = mWindowManager.getDefaultDisplay().getHeight();
// if (sreenWindowWidth > 800) {
// if (screenResolution == SCREEN_RESOLUTION_STANDARD) {
// sreenWindowWidth = align(sreenWindowWidth / 2, 16);
// screenWindowHeight = align(screenWindowHeight / 2, 16);
// } else {
// sreenWindowWidth = align(sreenWindowWidth * 2 / 5, 16);
// screenWindowHeight = align(screenWindowHeight * 2 / 5, 16);
// }
// }
Log.i(TAG, "mWindowWidth : " + sreenWindowWidth + ",mWindowHeight : "
+ screenWindowHeight);
DisplayMetrics displayMetrics = new DisplayMetrics();
mWindowManager.getDefaultDisplay().getMetrics(displayMetrics);
mScreenDensity = displayMetrics.densityDpi;
// densityDpi mImageReader = ImageReader.newInstance(sreenWindowWidth,
// screenWindowHeight, 0x1, 2);
mMediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
}
public void initSmall(){
mWindowManager = (WindowManager) getSystemService(Service.WINDOW_SERVICE);
// if (pushType == PUSH_TYPE_CAMERA) {
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
// | Intent.FLAG_ACTIVITY_SINGLE_TOP);
// PendingIntent contentIntent = PendingIntent.getActivity(this,
// 0, intent, 0);
//
// Intent bIntent = new Intent(this, BackgroudService.class);
// PendingIntent deleteIntent = PendingIntentnt.getService(this, 0,
// bIntent, 0);
//
//// notification = new Notification.Builder(this)
//// .setContentTitle("后台采集中。。").setAutoCancel(true)
//// .setDeleteIntent(deleteIntent)
//// .setContentIntent(contentIntent).build();
//
//// startForeground(android.os.Process.myPid(), notification);
bgSurfaceView = new SurfaceView(this);
bgSurfaceView.setZOrderMediaOverlay(true);
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
1, 1, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
layoutParams.gravity = Gravity.LEFT | Gravity.BOTTOM;
ImageView initPic = new ImageView(VideoPlayActivity.this);
initPic.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
initPic.setScaleType(ImageView.ScaleType.CENTER_CROP);
initPic.setImageResource(R.mipmap.no_video);
mWindowManager.addView(bgSurfaceView, layoutParams);
// xdySdk.api("publishVideo", "", bgSurfaceView, VideoPlayActivity.this);
// bgSurfaceView.getHolder().addCallback(this);
}
/*************************************** 回放***************************************************/
private static final int FADE_OUT = 1;
private static final int SHOW_PROGRESS = 2;
private TextView mEndTime, mCurrentTime;
private boolean mShowing;
private boolean mDragging;
private RelativeLayout mMediaControllerRight;
// @BindView(R.id.iv_operation_video)
// ImageView operationIcon;
// private PLMediaPlayer mMediaPlayer;
private FrameLayout mMediaContainer;
private ImageButton mPauseButton;
private SeekBar mSeekBar;
private RelativeLayout mPauseContainer;
@BindView(R.id.fl_media)
FrameLayout mMediaContainer;
@BindView(R.id.iv_operation_play)
ImageButton mPauseButton;
@BindView(R.id.sb_live)
SeekBar mSeekBar;
@BindView(R.id.rl_operation_play)
RelativeLayout mPauseContainer;
private TextView mClassName;
private SurfaceView mSurfaceView = null;
@BindView(R.id.tv_end_time)
TextView mEndTime;
@BindView(R.id.tv_current_time)
TextView mCurrentTime;
@SuppressLint("HandlerLeak")
private Handler mHandler = new Handler() {
@Override
... ... @@ -496,6 +723,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
mVideoView.setOnSeekCompleteListener(mOnSeekCompleteListener);
mVideoView.setDisplayAspectRatio(PLVideoView.ASPECT_RATIO_PAVED_PARENT);
AVOptions options = new AVOptions();
mSeekBar.setOnSeekBarChangeListener(mSeekListener);
// 解码方式:
// codec=AVOptions.MEDIA_CODEC_HW_DECODE,硬解
... ... @@ -541,6 +769,16 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
// 请在开始播放之前配置
mVideoView.setAVOptions(options);
mPauseContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//开启或暂停回放
boolean pause = getRecordStatus();
pauseAndStart(!pause);
}
});
}
@Override
... ... @@ -565,18 +803,91 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
}
};
public void resetSeekBar() {
if (mSeekBar != null) {
setProgress();
}
}
public void setCurrentTime(int currentTime) {
this.currentTime = currentTime;
}
public void seekRecordPlay(long b) {
//TODO 清除以前的数据
// chatView.clearChatHistory();
// docView.clear();
EventBus.getDefault().post("doc");
EventBus.getDefault().post("chat");
seekRecordPlayback(b);
}
private SeekBar.OnSeekBarChangeListener mSeekListener = new SeekBar.OnSeekBarChangeListener() {
public void onStartTrackingTouch(SeekBar bar) {
mDragging = true;
showMediaContainer(TIME_OUT);
mHandler.removeMessages(SHOW_PROGRESS);
//停掉音视频
if (isVideoMode)
stopVideo();
else
stopAudio();
}
public void onProgressChanged(SeekBar bar, int progress, boolean fromuser) {
if (!fromuser)
return;
setCurrentTime(progress);
String time = generateTime(progress);
if (mCurrentTime != null)
mCurrentTime.setText(time);
}
public void onStopTrackingTouch(SeekBar bar) {
seekRecordPlay(bar.getProgress() == 0 ? 1 : bar.getProgress());
showMediaContainer(TIME_OUT);
mHandler.removeMessages(SHOW_PROGRESS);
mDragging = false;
mHandler.sendEmptyMessageDelayed(SHOW_PROGRESS, 1000);
}
};
int TIME_OUT = 3600;
/**
* @param timeout 单位秒
*/
public void showMediaContainer(int timeout) {
if (!mShowing) {
if (mPauseContainer != null) {
mPauseContainer.requestLayout();
mPauseContainer.requestFocus();
}
mShowing = true;
}
updatePausePlay();
mHandler.sendEmptyMessage(SHOW_PROGRESS);
mMediaContainer.setVisibility(View.VISIBLE);
if (timeout != 0) {
mHandler.removeMessages(FADE_OUT);
mHandler.sendMessageDelayed(mHandler.obtainMessage(FADE_OUT),
timeout);
}
}
private void setProgress() {
// if (!mDragging) {
// if (mEndTime != null)
// mEndTime.setText(generateTime(mPresenter.getRecordPlaybackMaxTime()));
// if (mCurrentTime != null)
// mCurrentTime.setText(generateTime(mPresenter.getCurrentTime()));
// if (mSeekBar != null)
// mSeekBar.setProgress(mPresenter.getCurrentTime());
// }
if (!mDragging) {
if (mEndTime != null)
mEndTime.setText(generateTime(seek));
if (mCurrentTime != null) {
mCurrentTime.setText(generateTime(currentTime));
}
if (mSeekBar != null) {
mSeekBar.setProgress(currentTime);
}
}
}
private String generateTime(long currentTime) {
... ... @@ -606,63 +917,229 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
mShowing = false;
}
}
private boolean pause=true;
/**
* 退出标记
*/
private boolean quit;
private boolean isOver;
public void updatePausePlay() {
// if (mPresenter.getRecordStatus())
// mPauseButton.setImageResource(play);
// else
// mPauseButton.setImageResource(R.mipmap.stop);
// }
if (pause)
mPauseButton.setImageResource(R.mipmap.play);
else
mPauseButton.setImageResource(R.mipmap.stop);
}
private void handleRecord(String pa) {
try {
JSONObject jsonObject = new JSONObject(pa);
int status = jsonObject.optInt("status");
switch (status) {
case Constants.RECORD_READY:
// pause = true;
// isOver = false;
pause = true;
isOver = false;
break;
case Constants.RECORD_PLAYING:
// pause = false;
// isOver = false;
// mRootView.pauseOrStartEverything();
pause = false;
isOver = false;
pauseOrStartEverything();
break;
case Constants.RECORD_SEEK:
// isOver = false;
// pause = false;
isOver = false;
pause = false;
// int keyFrameSeek = jsonObject.optInt("keyFrameSeekTime");
// mRootView.seek(keyFrameSeek);
break;
case Constants.RECORD_STOP:
// pause = true;
pause = true;
// //停止后 录制回放要进行初始化
// if (!quit) {//回放结束了
if (!quit) {//回放结束了
// isOver = true;
// if (currentTime < recordPlaybackMaxTime)
// currentTime++;
// xdySdk.api("initRecordPlayback", initClass);
// int classId = AccountUtils.getUser().getClassId();
// mModel.initRecordPlayback(classId, portal, userRole, userId);
// //停止视频
// mRootView.stopVideo();
// currentTime = 0;
// mRootView.resetSeekBar();
stopVideo();
currentTime = 0;
resetSeekBar();
// docView.clear();
// chatView.clearChatHistory();
// currentPlayAudio = null;
// currentPlayVideo = null;
// }
EventBus.getDefault().post("doc");
EventBus.getDefault().post("chat");
}
break;
case Constants.RECORD_PAUSE:
// isOver = false;
// pause = true;
// mRootView.pauseOrStartEverything();
isOver = false;
pause = true;
pauseOrStartEverything();
break;
}
// mRootView.updatePausePlay();
updatePausePlay();
} catch (JSONException e) {
e.printStackTrace();
}
}
long seek=0;
int currentTime;
/**
* 录制回放初始化 seek长度等信息
*/
public void initRecordSeek(String response){
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(response);
seek = jsonObject.optLong("recordPlaybackMaxTime");
} catch (JSONException e) {
e.printStackTrace();
}
// if (mVideoView.isPlaying()) {
// mVideoView.stopPlayback();
// }
// if (replay && seek > 0) {
// mVideoView.seekTo(seek * 1000);
setProgress();
//
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
xdySdk.api("startRecordPlayback", "");
}
}, 200);
mVideoView.start();
}
private void handleTime(String pa) {
try {
JSONObject jsonObject = new JSONObject(pa);
//防止时间超了
currentTime = jsonObject.optInt("classTimestamp");
boolean isRe = jsonObject.optBoolean("recordStatus");
} catch (JSONException e) {
e.printStackTrace();
}
setProgress();
}
// public void setProcess(){
// if (mEndTime != null)
// mEndTime.setText(generateTime(seek));
// if (mCurrentTime != null) {
// mCurrentTime.setText(generateTime(currentTime));
// }
// if (mSeekBar != null){
//// mSeekBar.setProgress(generateTime(currentTime));
// }
// }
public boolean getRecordStatus() {
return pause;
}
public void pauseOrStartEverything() {
boolean isPause = getRecordStatus();
if (isPause && mVideoView != null && mVideoView.isPlaying()) {
mVideoView.pause();
XdyLogUtil.i(TAG, "视频停止");
} else if (mVideoView != null) {
mVideoView.start();
XdyLogUtil.i(TAG, "视频开始");
}
}
/**
* 回放 播放 音视频
* @param response
*/
public void playRecord(String response){
String json_video= aCache.getAsString(response);
if(TextUtils.isEmpty(json_video)){
///给出相应的提示表示没有 这个id
XdyLogUtil.e(TAG,"Play Video Can not find this VideoId");
return;
}
VideoPlayBean videoPlayBean= JsonUtil.parseJsonToBean(json_video,VideoPlayBean.class);
if(videoPlayBean!=null){
//回放不会出现Constants.PLAY_SUCCESS:
if(img_playVideo_novideo!=null)
img_playVideo_novideo.setVisibility(View.GONE);
if (mVideoView.isPlaying()) {
mVideoView.stopPlayback();
// mVideoView.pause();
}
mVideoView.setVideoPath(videoPlayBean.getReplay());
//TODO 这个地方需要调整进度的话
XdyLogUtil.e("播放精度哈哈哈哈哈",""+videoPlayBean.getSeek());
if (replay && videoPlayBean.getSeek() > 0) {
mVideoView.seekTo(videoPlayBean.getSeek() * 1000);
}
mVideoView.start();
XdyLogUtil.e("录制回放播放视频的了",""+videoPlayBean.getReplay());
}
}
public void stopVideo() {
mHandler.post(new Runnable() {
@Override
public void run() {
img_playVideo_novideo.setImageResource(R.mipmap.no_video);
img_playVideo_novideo.setVisibility(View.VISIBLE);
}
});
if (isVideoMode && mVideoView != null && mVideoView.isPlaying())
mVideoView.stopPlayback();
}
public void stopAudio() {
img_playVideo_novideo.setImageResource(R.mipmap.no_video);
img_playVideo_novideo.setVisibility(View.VISIBLE);
if (isVideoMode && mVideoView != null && mVideoView.isPlaying())
mVideoView.stopPlayback();
}
@Override
public void onClick() {
if (replay) {
if (mMediaContainer.getVisibility() == View.VISIBLE) {
hideMediaContainer();
} else {
showMediaContainer(TIME_OUT);
}
}
}
public void pauseAndStart(boolean b) {
if (b) {
pauseRecordPlayback();
} else {
startRecordPlayback();
}
}
public void pauseRecordPlayback() {
xdySdk.api("pauseRecordPlayback","");
}
public void startRecordPlayback() {
xdySdk.api("startRecordPlayback","");
}
public void seekRecordPlayback(long time) {
TimeEntity timeEntity=new TimeEntity(time);
xdySdk.api("seekRecordPlayback", new Gson().toJson(timeEntity));
}
}
... ...
package com.mang.xdy.demo.activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.media.Image;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.eventhandle.SmartEventCallback;
import com.google.gson.Gson;
import com.mang.xdy.common.Constants;
import com.mang.xdy.core.XdySdk;
import com.mang.xdy.demo.R;
import com.mang.xdy.demo.adapter.SimpleFragmentPagerAdapter;
import com.mang.xdy.demo.bean.AudioPlayBean;
import com.mang.xdy.demo.bean.ChatBean;
import com.mang.xdy.demo.bean.DocEntity;
import com.mang.xdy.demo.bean.ErrorEntity;
import com.mang.xdy.demo.bean.InitClassSuccessEntity;
import com.mang.xdy.demo.bean.JoinClass;
import com.mang.xdy.demo.bean.LiveBean;
import com.mang.xdy.demo.bean.PublisherEntity;
import com.mang.xdy.demo.bean.PublisherVideoExitBean;
import com.mang.xdy.demo.bean.PublisherVideoReturnBean;
import com.mang.xdy.demo.bean.VideoPlayBean;
import com.mang.xdy.demo.utils.JsonUtil;
import com.mang.xdy.demo.utils.ToastUtil;
import com.mang.xdy.demo.widget.dialog.LoginDialog;
import com.mang.xdy.listener.ObserverListener;
import com.mang.xdy.utils.UIUtils;
import com.mang.xdy.utils.XdyLogUtil;
import com.mang.xdy.utils.XdyStringUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class VideoPublisherActivity extends AppCompatActivity implements ObserverListener{
private final static String TAG = "VideoPlayActivity";
@BindView(R.id.btn_videoPlay_pubsherVideo)
Button btnVideoPlayPubsherVideo;
@BindView(R.id.btn_videoPlay_chat)
Button btnVideoPlayChat;
@BindView(R.id.tv_videoPlay_url)
TextView tv_videoPlay_url;
@BindView(R.id.surfaceview_pubisherVideo)
SurfaceView surfaceview_pubisherVideo;
@BindView(R.id.btn_videoPlay_publisherAudio)
Button btn_videoPlay_publisherAudio;
// @BindView(R.id.img_playVideo_novideo)
// ImageView img_playVideo_novideo;
private String username="";
private String userpwd="";
private PersonDialog personDialog;
private SimpleFragmentPagerAdapter pagerAdapter;
private XdySdk xdySdk;
private ViewPager viewPager;
//默认推送视频
private boolean isPusherAudio=false;
/*默认是可以退出的,如果进行推流则需要主动退出*/
private boolean isAbleback=false;
private TabLayout tabLayout;
@BindView(R.id.surfaceview_playVideo)
SurfaceView surfaceviewPlayVideo;
@BindView(R.id.btn_videoPlay_stop)
Button btn_videoPlay_stop;
private String initClass = "";
private String publisherSuccess="";
/*视频成功返回值*/
private PublisherVideoReturnBean publisherVideoReturnBean;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case -2:
//加入课堂输入用户名,密码
joinClass("", (Boolean) msg.obj);
break;
case -1:
//退出
// xdySdk.api("leaveClass", "");
break;
case 0:
parseJoinClass((String) msg.obj,true);
break;
case 7:
break;
case 8:
btnVideoPlayPubsherVideo.setEnabled(true);
btn_videoPlay_publisherAudio.setEnabled(true);
break;
}
}
};
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //屏幕常亮
setContentView(R.layout.activity_video_publisher);
ButterKnife.bind(this);
btn_videoPlay_publisherAudio.setVisibility(View.GONE);
// setTablayout();
xdySdk=XdySdk.getXdyInstance();
xdySdk.add(this);
init();
XdyLogUtil.e(TAG,"当前线程 main:"+android.os.Process.myPid()+"线程:"+Thread.currentThread().getId()+"");
xdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
@Override
public void onXdyAsyncMessageReceiver(String type, String response) {
switch (type) {
case "class_init_success":
ToastUtil.showToastshort("初始化课堂成功", VideoPublisherActivity.this);
Message message = Message.obtain();
message.obj = response;
message.what = 0;
handler.sendMessage(message);
break;
case "class_join_success":
//加入课堂成功
UIUtils.closeDialog(mLoginDialog);
ToastUtil.showToastshort("加入课堂成功", VideoPublisherActivity.this);
//只有加入课堂成功才可以点击推流的按钮
handler.sendEmptyMessage(8);
break;
case "video_stop":
// handler.sendEmptyMessage(7);
break;
case "audio_stop":
break;
}
XdyLogUtil.e(TAG,"type:"+type+" response:"+response);
}
});
}
public void init() {
initClass = getIntent().getStringExtra("init");
xdySdk.api("init", initClass);
}
private LoginDialog mLoginDialog;
//判断解析是否有密码
public void parseJoinClass(String rsponse,boolean isShowPwd){
InitClassSuccessEntity initClassSuccessEntity=JsonUtil.parseJsonToBean(rsponse,InitClassSuccessEntity.class);
if(initClassSuccessEntity!=null) {
if (initClassSuccessEntity.isPasswordRequired()) {
isShowPwd=true;
} else {
isShowPwd=false;
userpwd = "123321";
}
}
if (mLoginDialog == null) {
mLoginDialog = new LoginDialog(this, isShowPwd, null);
mLoginDialog.show();
mLoginDialog.setCanceledOnTouchOutside(false);
final boolean finalIsShowPwd = isShowPwd;
mLoginDialog.setBtnClick(new View.OnClickListener() {
@Override
public void onClick(View view) {
String[] nameAndPwd = mLoginDialog.getNameAndPwd();
joinClass(nameAndPwd[0], nameAndPwd[1], finalIsShowPwd);
}
});
}else if (mLoginDialog != null) {
UIUtils.closeDialog(mLoginDialog);
}
}
//加入课堂
public void joinClass(String username,String userpwd,boolean isShowPwd) {
JoinClass joinClass=new JoinClass();
joinClass.setHasCamera(false);
joinClass.setHasMicrophone(false);
joinClass.setUserName(username);
if(!isShowPwd){
joinClass.setPassword("123321");
}else{
joinClass.setPassword(userpwd);
}
String temp=new Gson().toJson(joinClass);
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e("加入课堂", jsonParmp);
xdySdk.api("joinClass", jsonParmp);
}
//加入课堂
public void joinClass(String rsponse,boolean isShowPwd) {
//package com.mang.xdy.demo.activity;
//
// import android.app.AlertDialog;
// import android.app.Dialog;
// import android.content.Context;
// import android.content.DialogInterface;
// import android.media.Image;
// import android.os.Bundle;
// import android.os.Handler;
// import android.os.Message;
// import android.support.design.widget.TabLayout;
// import android.support.v4.view.ViewPager;
// import android.support.v7.app.AppCompatActivity;
// import android.text.TextUtils;
// import android.util.Log;
// import android.view.Gravity;
// import android.view.SurfaceView;
// import android.view.View;
// import android.view.Window;
// import android.view.WindowManager;
// import android.widget.Button;
// import android.widget.EditText;
// import android.widget.ImageView;
// import android.widget.TextView;
// import android.widget.Toast;
//
// import com.eventhandle.SmartEventCallback;
// import com.google.gson.Gson;
// import com.mang.xdy.common.Constants;
// import com.mang.xdy.core.XdySdk;
// import com.mang.xdy.demo.R;
// import com.mang.xdy.demo.adapter.SimpleFragmentPagerAdapter;
// import com.mang.xdy.demo.bean.AudioPlayBean;
// import com.mang.xdy.demo.bean.ChatBean;
// import com.mang.xdy.demo.bean.DocEntity;
// import com.mang.xdy.demo.bean.ErrorEntity;
// import com.mang.xdy.demo.bean.InitClassSuccessEntity;
// import com.mang.xdy.demo.bean.JoinClass;
// import com.mang.xdy.demo.bean.LiveBean;
// import com.mang.xdy.demo.bean.PublisherEntity;
// import com.mang.xdy.demo.bean.PublisherVideoExitBean;
// import com.mang.xdy.demo.bean.PublisherVideoReturnBean;
// import com.mang.xdy.demo.bean.VideoPlayBean;
// import com.mang.xdy.demo.utils.JsonUtil;
// import com.mang.xdy.demo.utils.ToastUtil;
// import com.mang.xdy.demo.widget.dialog.LoginDialog;
// import com.mang.xdy.listener.ObserverListener;
// import com.mang.xdy.utils.UIUtils;
// import com.mang.xdy.utils.XdyLogUtil;
// import com.mang.xdy.utils.XdyStringUtils;
//
// import butterknife.BindView;
// import butterknife.ButterKnife;
// import butterknife.OnClick;
//
//public class VideoPublisherActivity extends AppCompatActivity implements ObserverListener{
// private final static String TAG = "VideoPlayActivity";
// @BindView(R.id.btn_videoPlay_pubsherVideo)
// Button btnVideoPlayPubsherVideo;
// @BindView(R.id.btn_videoPlay_chat)
// Button btnVideoPlayChat;
// @BindView(R.id.tv_videoPlay_url)
// TextView tv_videoPlay_url;
// @BindView(R.id.surfaceview_pubisherVideo)
// SurfaceView surfaceview_pubisherVideo;
// @BindView(R.id.btn_videoPlay_publisherAudio)
// Button btn_videoPlay_publisherAudio;
//// @BindView(R.id.img_playVideo_novideo)
//// ImageView img_playVideo_novideo;
// private String username="";
// private String userpwd="";
// private PersonDialog personDialog;
// private SimpleFragmentPagerAdapter pagerAdapter;
// private XdySdk xdySdk;
// private ViewPager viewPager;
// //默认推送视频
// private boolean isPusherAudio=false;
// /*默认是可以退出的,如果进行推流则需要主动退出*/
// private boolean isAbleback=false;
// private TabLayout tabLayout;
// @BindView(R.id.surfaceview_playVideo)
// SurfaceView surfaceviewPlayVideo;
// @BindView(R.id.btn_videoPlay_stop)
// Button btn_videoPlay_stop;
// private String initClass = "";
// private String publisherSuccess="";
// /*视频成功返回值*/
// private PublisherVideoReturnBean publisherVideoReturnBean;
// private Handler handler = new Handler() {
// @Override
// public void handleMessage(Message msg) {
// super.handleMessage(msg);
// switch (msg.what) {
// case -2:
// //加入课堂输入用户名,密码
// joinClass("", (Boolean) msg.obj);
// break;
// case -1:
// //退出
// // xdySdk.api("leaveClass", "");
// break;
// case 0:
// parseJoinClass((String) msg.obj,true);
// break;
// case 7:
// break;
// case 8:
// btnVideoPlayPubsherVideo.setEnabled(true);
// btn_videoPlay_publisherAudio.setEnabled(true);
// break;
//
// }
// }
// };
//
// @Override
// protected void onCreate(final Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //屏幕常亮
// setContentView(R.layout.activity_video_publisher);
// ButterKnife.bind(this);
// btn_videoPlay_publisherAudio.setVisibility(View.GONE);
//// setTablayout();
// xdySdk=XdySdk.getXdyInstance();
// xdySdk.add(this);
// init();
// XdyLogUtil.e(TAG,"当前线程 main:"+android.os.Process.myPid()+"线程:"+Thread.currentThread().getId()+"");
// xdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
// @Override
// public void onXdyAsyncMessageReceiver(String type, String response) {
//
// switch (type) {
// case "class_init_success":
// ToastUtil.showToastshort("初始化课堂成功", VideoPublisherActivity.this);
// Message message = Message.obtain();
// message.obj = response;
// message.what = 0;
// handler.sendMessage(message);
// break;
// case "class_join_success":
// //加入课堂成功
// UIUtils.closeDialog(mLoginDialog);
// ToastUtil.showToastshort("加入课堂成功", VideoPublisherActivity.this);
// //只有加入课堂成功才可以点击推流的按钮
// handler.sendEmptyMessage(8);
// break;
// case "video_stop":
//// handler.sendEmptyMessage(7);
// break;
// case "audio_stop":
//
// break;
// }
// XdyLogUtil.e(TAG,"type:"+type+" response:"+response);
// }
// });
// }
//
// public void init() {
// initClass = getIntent().getStringExtra("init");
// xdySdk.api("init", initClass);
//
// }
//private LoginDialog mLoginDialog;
// //判断解析是否有密码
// public void parseJoinClass(String rsponse,boolean isShowPwd){
// InitClassSuccessEntity initClassSuccessEntity=JsonUtil.parseJsonToBean(rsponse,InitClassSuccessEntity.class);
// if(initClassSuccessEntity!=null) {
// if (initClassSuccessEntity.isPasswordRequired()) {
// isShowPwd=true;
// } else {
// isShowPwd=false;
// userpwd = "123321";
// }
// }
//
// if (mLoginDialog == null) {
// mLoginDialog = new LoginDialog(this, isShowPwd, null);
// mLoginDialog.show();
// mLoginDialog.setCanceledOnTouchOutside(false);
// final boolean finalIsShowPwd = isShowPwd;
// mLoginDialog.setBtnClick(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// String[] nameAndPwd = mLoginDialog.getNameAndPwd();
// joinClass(nameAndPwd[0], nameAndPwd[1], finalIsShowPwd);
// }
// });
// }else if (mLoginDialog != null) {
// UIUtils.closeDialog(mLoginDialog);
// }
// }
// //加入课堂
// public void joinClass(String username,String userpwd,boolean isShowPwd) {
// JoinClass joinClass=new JoinClass();
// joinClass.setHasCamera(false);
// joinClass.setHasMicrophone(false);
// joinClass.setUserName(username);
// if(!isShowPwd){
// joinClass.setPassword("123321");
// }else{
// joinClass.setPassword(userpwd);
// }
// String temp=new Gson().toJson(joinClass);
// String jsonParmp = XdyStringUtils.stringToJson(temp, true);
// XdyLogUtil.e("加入课堂", jsonParmp);
// xdySdk.api("joinClass", jsonParmp);
// }
//
// //加入课堂
// public void joinClass(String rsponse,boolean isShowPwd) {
//
//// String temp = "{\n" +
//// " \"userName\":\"base\",\n" +
//// " \"password\":\"123321\",\n" +
//// " \"hasCamera\":false,\n" +
//// " \"hasMicrophone\":false}";
// JoinClass joinClass=new JoinClass();
// joinClass.setHasCamera(false);
// joinClass.setHasMicrophone(false);
// joinClass.setUserName(username);
// if(!isShowPwd){
// joinClass.setPassword("123321");
// }else{
// joinClass.setPassword(userpwd);
// }
// String temp=new Gson().toJson(joinClass);
// String jsonParmp = XdyStringUtils.stringToJson(temp, true);
// XdyLogUtil.e("加入课堂", jsonParmp);
// xdySdk.api("joinClass", jsonParmp);
// }
//
//
//
// public void sendMeg() {
// String temp = "{\n" +
// " \"userName\":\"base\",\n" +
// " \"password\":\"123321\",\n" +
// " \"hasCamera\":false,\n" +
// " \"hasMicrophone\":false}";
JoinClass joinClass=new JoinClass();
joinClass.setHasCamera(false);
joinClass.setHasMicrophone(false);
joinClass.setUserName(username);
if(!isShowPwd){
joinClass.setPassword("123321");
}else{
joinClass.setPassword(userpwd);
}
String temp=new Gson().toJson(joinClass);
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e("加入课堂", jsonParmp);
xdySdk.api("joinClass", jsonParmp);
}
public void sendMeg() {
String temp = "{\n" +
" \"message\": \"固定发送测试 hello\",\n" +
" \"to\": 0\n" +
"}";
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e(TAG, "聊天" + jsonParmp);
xdySdk.api("sendChatMsg", jsonParmp);
}
/**
* 获取封装的推流地址
*/
public void publisherVideoText(){
xdySdk.api("publishVideo", "", surfaceview_pubisherVideo, VideoPublisherActivity.this);
}
@Override
protected void onPause() {
super.onPause();
xdySdk.onPublisherPause();
}
@Override
protected void onResume() {
super.onResume();
xdySdk.onPublisherResume();
}
@Override
protected void onDestroy() {
xdySdk.onPublisherStop();
super.onDestroy();
}
@OnClick({R.id.btn_videoPlay_chat, R.id.btn_videoPlay_pubsherVideo,R.id.btn_videoPlay_publisherAudio,R.id.btn_videoPlay_stop})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.btn_videoPlay_chat:
handler.sendEmptyMessage(4);
break;
case R.id.btn_videoPlay_pubsherVideo:
// getPublish();
publisherVideoText();
// publisherAudioText();
ToastUtil.showToastshort("推送视频",VideoPublisherActivity.this);
btnVideoPlayPubsherVideo.setClickable(false);
break;
case R.id.btn_videoPlay_stop:
ToastUtil.showToastshort("正在退出,请稍等",this);
xdySdk.api("unPublishVideo","");
// finish();
break;
}
}
@Override
public void observerUpData(final String type, final String parameter) {
handler.post(new Runnable() {
@Override
public void run() {
handError(type,parameter);
}
});
}
public void handError(String errorId, String errorMsg) {
ErrorEntity errorEntity = JsonUtil.parseJsonToBean(errorMsg, ErrorEntity.class);
if (errorEntity == null) {
return;
}
switch (errorEntity.getCode() + "") {
case "100":
case "101":
case "102":
case "103":
case "104":
case "105":
case "106":
case "107":
case "200":
case "201":
case "202":
case "203":
case "204":
case "205":
case "206":
case "207":
case "208":
ToastUtil.showToastshort(errorEntity.getReson(), this);
exit();
break;
case "300":
case "301":
break;
case "10000":
ToastUtil.showToastshort(errorEntity.getReson(), this);
break;
case "10001":
ToastUtil.showToastshort(errorEntity.getReson(), this);
break;
case "20000":
isDefaultExit=false;
showErrorDialog();
ToastUtil.showToastshort(errorEntity.getReson(), this);
break;
}
}
class EventHande implements SmartEventCallback {
@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, "连接成功。。");
// PublisherEntity publisherEntity=new PublisherEntity();
// if(TextUtils.isEmpty(publisherSuccess)) {
// publisherEntity.setPublishUrl(publisherSuccess);
// XdySdk.setAsyncApi("publishVideo", new Gson().toJson(publisherEntity));
// }
//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错误。。");
}
}
}
/*mcu断开或者网络原因为false*/
private boolean isDefaultExit=true;
private android.support.v7.app.AlertDialog mErrorDialog;
public void showErrorDialog() {
// if(isDefaultExit){
// " \"message\": \"固定发送测试 hello\",\n" +
// " \"to\": 0\n" +
// "}";
// String jsonParmp = XdyStringUtils.stringToJson(temp, true);
// XdyLogUtil.e(TAG, "聊天" + jsonParmp);
// xdySdk.api("sendChatMsg", jsonParmp);
//
// }
//
// /**
// * 获取封装的推流地址
// */
// public void publisherVideoText(){
// xdySdk.api("publishVideo", "", surfaceview_pubisherVideo, VideoPublisherActivity.this);
//// xdySdk.api(Constants.PUBLISH_AUDIO, "", surfaceview_pubisherVideo, VideoPublisherActivity.this);
//
// }
//
// @Override
// protected void onPause() {
// super.onPause();
//// xdySdk.onPublisherPause();
// }
//
// @Override
// protected void onResume() {
// super.onResume();
//// xdySdk.onPublisherResume();
// }
//
// @Override
// protected void onDestroy() {
// xdySdk.onPublisherStop();
// super.onDestroy();
// }
//
// @OnClick({R.id.btn_videoPlay_chat, R.id.btn_videoPlay_pubsherVideo,R.id.btn_videoPlay_publisherAudio,R.id.btn_videoPlay_stop})
// public void onViewClicked(View view) {
// switch (view.getId()) {
// case R.id.btn_videoPlay_chat:
// handler.sendEmptyMessage(4);
// break;
// case R.id.btn_videoPlay_pubsherVideo:
//// getPublish();
// publisherVideoText();
//// publisherAudioText();
// ToastUtil.showToastshort("推送视频",VideoPublisherActivity.this);
// btnVideoPlayPubsherVideo.setClickable(false);
//
// break;
// case R.id.btn_videoPlay_stop:
// ToastUtil.showToastshort("正在退出,请稍等",this);
// xdySdk.api("unPublishVideo","");
//// finish();
// break;
// }
// }
//
// @Override
// public void observerUpData(final String type, final String parameter) {
// handler.post(new Runnable() {
// @Override
// public void run() {
// handError(type,parameter);
// }
// });
// }
// public void handError(String errorId, String errorMsg) {
// ErrorEntity errorEntity = JsonUtil.parseJsonToBean(errorMsg, ErrorEntity.class);
// if (errorEntity == null) {
// return;
// }
if (mErrorDialog != null)
return;
mErrorDialog = new android.support.v7.app.AlertDialog.Builder(this)
.setTitle("退出")
.setMessage("您设备的网络属于断开状态,请重新进入")
.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
exit();
}
})
.create();
mErrorDialog.setCanceledOnTouchOutside(false);
mErrorDialog.show();
}
/**
* 错误情况退出
*/
public void exit() {
UIUtils.closeDialog(mLoginDialog);
// xdySdk.onPublisherStop();
xdySdk.remove(this);
handler.removeCallbacksAndMessages(null);
this.finish();
}
class PersonDialog extends Dialog {
public PersonDialog(Context context) {
this(context, false);
}
public PersonDialog(Context context, boolean showPwd) {
this(context, R.style.bottom_dialog, showPwd);
}
public PersonDialog(Context context, int themeResId, boolean showPwd) {
super(context, themeResId);
init(context, showPwd);
}
public void init(Context context, boolean showPwd) {
View view = View.inflate(context, R.layout.dialog_item, null);
setContentView(view);
initView(view,showPwd);
setCanceledOnTouchOutside(false);
Window window = getWindow();
WindowManager.LayoutParams params = window.getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = dp2px(context, 220);
window.setAttributes(params);
window.setGravity(Gravity.CENTER);
}
public int dp2px(Context context, float dp) {
return (int) Math.ceil(context.getResources().getDisplayMetrics().density * dp);
}
public void initView(View view, final boolean showPwd){
final EditText edt_uername= (EditText) view.findViewById(R.id.dialog_edt_username);
final EditText edt_userpwd= (EditText) view.findViewById(R.id.dialog_edt_userpwd);
if(showPwd){
edt_userpwd.setVisibility(View.VISIBLE);
}else{
edt_userpwd.setVisibility(View.GONE);
}
Button btn_enter= (Button) view.findViewById(R.id.dialog_btn_enter);
btn_enter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
username=edt_uername.getText().toString();
userpwd=edt_userpwd.getText().toString();
if(TextUtils.isEmpty(username)){
ToastUtil.showToastshort("用户名不能为空",VideoPublisherActivity.this);
return;
}
if(showPwd&&TextUtils.isEmpty(userpwd)){
ToastUtil.showToastshort("密码不能为空",VideoPublisherActivity.this);
return;
}
dismiss();
Message message=Message.obtain();
message.what=-2;
message.obj=showPwd;
handler.sendMessage(message);
}
});
}
}
}
// switch (errorEntity.getCode() + "") {
// case "100":
// case "101":
// case "102":
// case "103":
// case "104":
// case "105":
// case "106":
// case "107":
// case "200":
// case "201":
// case "202":
// case "203":
// case "204":
// case "205":
// case "206":
// case "207":
// case "208":
// ToastUtil.showToastshort(errorEntity.getReson(), this);
// exit();
// break;
// case "300":
// case "301":
// break;
// case "10000":
// ToastUtil.showToastshort(errorEntity.getReson(), this);
// break;
// case "10001":
// ToastUtil.showToastshort(errorEntity.getReson(), this);
// break;
// case "20000":
// isDefaultExit=false;
// showErrorDialog();
// ToastUtil.showToastshort(errorEntity.getReson(), this);
// break;
// }
//
//
// }
//
// class EventHande implements SmartEventCallback {
// @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, "连接成功。。");
//// PublisherEntity publisherEntity=new PublisherEntity();
//// if(TextUtils.isEmpty(publisherSuccess)) {
//// publisherEntity.setPublishUrl(publisherSuccess);
//// XdySdk.setAsyncApi("publishVideo", new Gson().toJson(publisherEntity));
//// }
// //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错误。。");
// }
//
// }
// }
// /*mcu断开或者网络原因为false*/
// private boolean isDefaultExit=true;
// private android.support.v7.app.AlertDialog mErrorDialog;
// public void showErrorDialog() {
//// if(isDefaultExit){
//// return;
//// }
// if (mErrorDialog != null)
// return;
//
// mErrorDialog = new android.support.v7.app.AlertDialog.Builder(this)
// .setTitle("退出")
// .setMessage("您设备的网络属于断开状态,请重新进入")
// .setPositiveButton("确认", new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialogInterface, int i) {
// dialogInterface.dismiss();
// exit();
// }
// })
// .create();
// mErrorDialog.setCanceledOnTouchOutside(false);
//
// mErrorDialog.show();
//
// }
//
// /**
// * 错误情况退出
// */
// public void exit() {
//
// UIUtils.closeDialog(mLoginDialog);
//// xdySdk.onPublisherStop();
// xdySdk.remove(this);
// handler.removeCallbacksAndMessages(null);
// this.finish();
// }
// class PersonDialog extends Dialog {
// public PersonDialog(Context context) {
// this(context, false);
//
// }
//
// public PersonDialog(Context context, boolean showPwd) {
// this(context, R.style.bottom_dialog, showPwd);
// }
//
// public PersonDialog(Context context, int themeResId, boolean showPwd) {
// super(context, themeResId);
// init(context, showPwd);
// }
//
// public void init(Context context, boolean showPwd) {
// View view = View.inflate(context, R.layout.dialog_item, null);
// setContentView(view);
// initView(view,showPwd);
// setCanceledOnTouchOutside(false);
// Window window = getWindow();
// WindowManager.LayoutParams params = window.getAttributes();
// params.width = WindowManager.LayoutParams.MATCH_PARENT;
// params.height = dp2px(context, 220);
// window.setAttributes(params);
// window.setGravity(Gravity.CENTER);
// }
//
// public int dp2px(Context context, float dp) {
// return (int) Math.ceil(context.getResources().getDisplayMetrics().density * dp);
// }
// public void initView(View view, final boolean showPwd){
// final EditText edt_uername= (EditText) view.findViewById(R.id.dialog_edt_username);
// final EditText edt_userpwd= (EditText) view.findViewById(R.id.dialog_edt_userpwd);
// if(showPwd){
// edt_userpwd.setVisibility(View.VISIBLE);
// }else{
// edt_userpwd.setVisibility(View.GONE);
// }
// Button btn_enter= (Button) view.findViewById(R.id.dialog_btn_enter);
// btn_enter.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// username=edt_uername.getText().toString();
// userpwd=edt_userpwd.getText().toString();
// if(TextUtils.isEmpty(username)){
// ToastUtil.showToastshort("用户名不能为空",VideoPublisherActivity.this);
// return;
// }
// if(showPwd&&TextUtils.isEmpty(userpwd)){
// ToastUtil.showToastshort("密码不能为空",VideoPublisherActivity.this);
// return;
// }
// dismiss();
// Message message=Message.obtain();
// message.what=-2;
// message.obj=showPwd;
// handler.sendMessage(message);
// }
// });
// }
// }
//
//}
... ...
... ... @@ -20,14 +20,14 @@ public class SimpleFragmentPagerAdapter extends FragmentPagerAdapter {
private String tabTitles[] = new String[]{"文档","聊天"};
private Context context;
private DocFragment docFragment=new DocFragment();
private ChatFragment chatFragment=new ChatFragment();
private List<Fragment> fragmentList=new ArrayList<>();
public SimpleFragmentPagerAdapter(FragmentManager fm,Context context) {
private boolean replay=false;
public SimpleFragmentPagerAdapter(FragmentManager fm,Context context,boolean replay) {
super(fm);
this.context = context;
fragmentList.add(docFragment);
fragmentList.add(chatFragment);
this.replay=replay;
fragmentList.add(DocFragment.newInstance(replay));
fragmentList.add(ChatFragment.newInstance(replay));
}
@Override
... ...
package com.mang.xdy.demo.bean;
/**
* Created by abao on 2017/4/28.
*/
public class EventBusPost {
private String msg;
public EventBusPost(String msg) {//事件传递参数
this.msg = msg;
}
public String getMsg() {//取出事件参数
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
... ...
package com.mang.xdy.demo.bean;
/**
* Created by abao on 2017/4/28.
*/
public class TimeEntity {
/**
* time : 20
*/
private long time;
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
public TimeEntity(long time) {
this.time = time;
}
}
... ...
... ... @@ -35,6 +35,9 @@ import com.mang.xdy.listener.ObserverListener;
import com.mang.xdy.utils.XdyLogUtil;
import com.mang.xdy.utils.XdyStringUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.KJLoger;
import org.kymjs.kjframe.utils.StringUtils;
... ... @@ -76,11 +79,24 @@ public class ChatFragment extends Fragment implements ObserverListener{
mContext=this.getContext();
xdySdk=XdySdk.getXdyInstance();
xdySdk.add(this);
EventBus.getDefault().register(this);
init();
initData();
}
public static ChatFragment newInstance(boolean replay) {
ChatFragment chatFragment = new ChatFragment();
Bundle bundle = new Bundle();
bundle.putBoolean("replay", replay);
chatFragment.setArguments(bundle);
//add params
return chatFragment;
}
public void init(){
Bundle arguments = getArguments();
if(arguments!=null)
replay = arguments.getBoolean("replay");
box.setToolBoxIsClick(false);
box.setOnOperationListener(new OnOperationListener() {
@Override
... ... @@ -254,7 +270,20 @@ public class ChatFragment extends Fragment implements ObserverListener{
}
};
}
//回放时候清除数据
public void clearChatHistory() {
if (adapter != null) {
datas.clear();
adapter.refresh(datas);
}
}
@Subscribe(threadMode = ThreadMode.POSTING)
public void clearChatHistory(String res){
if("chat".equals(res)) {
clearChatHistory();
}
}
private Handler mHandler=new Handler(){
@Override
public void handleMessage(android.os.Message msg) {
... ... @@ -286,4 +315,10 @@ private Handler mHandler=new Handler(){
void onFaceClick(int position);
}
@Override
public void onDestroy() {
EventBus.getDefault().unregister(this);
super.onDestroy();
}
}
... ...
... ... @@ -28,6 +28,9 @@ import com.mang.xdy.demo.widget.CanvasView;
import com.mang.xdy.listener.ObserverListener;
import com.mang.xdy.utils.XdyLogUtil;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONObject;
import java.util.concurrent.ExecutionException;
... ... @@ -56,6 +59,7 @@ public class DocFragment extends Fragment implements ObserverListener{
private long intervalTime;
/*判断文档和白板是否匹配*/
private String mItemidx ="";
private boolean replay;
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
... ... @@ -63,9 +67,19 @@ public class DocFragment extends Fragment implements ObserverListener{
xdySdk=XdySdk.getXdyInstance();
xdySdk.add(this);
mContext=this.getContext();
EventBus.getDefault().register(this);
init();
}
public static DocFragment newInstance(boolean replay) {
DocFragment docFragment = new DocFragment();
Bundle bundle = new Bundle();
bundle.putBoolean("replay", replay);
docFragment.setArguments(bundle);
return docFragment;
}
private Handler mHandler=new Handler(){
@Override
public void handleMessage(Message msg) {
... ... @@ -84,6 +98,10 @@ public class DocFragment extends Fragment implements ObserverListener{
public void init(){
Bundle arguments = getArguments();
if(arguments!=null)
replay = arguments.getBoolean("replay");
DisplayMetrics metric = new DisplayMetrics();
getWindowWith(metric);
docUrlTransformBitmap(null);
... ... @@ -119,29 +137,6 @@ public class DocFragment extends Fragment implements ObserverListener{
}
public void getBitmap(final String url){
// new Thread(){
// @Override
// public void run() {
// super.run();
// try {
// bitmap= Glide.with(mContext).load(url).asBitmap().into(480,480).get();
// if(bitmap!=null) {
//// mHandler.post(new Runnable() {
//// @Override
//// public void run() {
// mCanvasView.setZOrderMediaOverlay(true);
// mCanvasView.setBitmap(bitmap,false);
//// }
//// });
//
// }
// } catch (InterruptedException e) {
// e.printStackTrace();
// } catch (ExecutionException e) {
// e.printStackTrace();
// }
// }
// }.start();
}
/**
* 展示文档
... ... @@ -152,7 +147,6 @@ public class DocFragment extends Fragment implements ObserverListener{
WhiteboardUpdateEntity whiteboardUpdateEntity= JsonUtil.parseJsonToBean(response,WhiteboardUpdateEntity.class);
if(whiteboardUpdateEntity!=null){
if(whiteboardUpdateEntity.annotaionItems!=null){
if (whiteboardUpdateEntity.annotaionItems.size()>0&& mItemidx.equals(whiteboardUpdateEntity.annotaionItems.get(0).parentId)){
if (intervalTime != 0) {
intervalTime = System.currentTimeMillis() - intervalTime;
... ... @@ -166,7 +160,6 @@ public class DocFragment extends Fragment implements ObserverListener{
intervalTime = System.currentTimeMillis();
}
}
}
}
private void delayDraw(final WhiteboardUpdateEntity entity) {
... ... @@ -250,7 +243,7 @@ public class DocFragment extends Fragment implements ObserverListener{
}
@Override
public void observerUpData(final String type, final String parameter) {
XdyLogUtil.e(TAG,"type:"+type+" response:"+parameter);
// XdyLogUtil.e(TAG,"type:"+type+" response:"+parameter);
switch (type){
case Constants.DOCUMENT_UPDATE:
getDoc(parameter);
... ... @@ -270,11 +263,29 @@ public class DocFragment extends Fragment implements ObserverListener{
}
break;
}
}
/**
* 回放的时候清除数据
*/
public void clear() {
if(mCanvasView!=null) {
mCanvasView.clear();
}
docUrlTransformBitmap(null);
}
@Subscribe(threadMode = ThreadMode.POSTING)
public void clearDocHistory(String res){
if("doc".equals(res)) {
clear();
}
}
@Override
public void onDestroyView() {
EventBus.getDefault().unregister(this);
super.onDestroyView();
// xdySdk.remove(this);
// if(mCanvasView!=null){
... ...
... ... @@ -15,7 +15,8 @@
android:id="@+id/edt_home_classId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1573557360"/>
android:hint="请输入课堂号"
android:text="391813551"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
... ... @@ -60,9 +61,7 @@
android:id="@+id/btn_home_enter_publisher"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="推视频"
android:visibility="gone"
android:text="录制回放"
/>
<Button
... ... @@ -71,6 +70,5 @@
android:layout_height="wrap_content"
android:text="推音频"
android:visibility="gone"
/>
</LinearLayout>
... ...
... ... @@ -13,22 +13,24 @@
android:layout_height="1dp"
android:visibility="gone">
</FrameLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/ui_DIMEN_500.0PX">
<com.pili.pldroid.player.widget.PLVideoTextureView
android:id="@+id/img_playVideo_replay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"/>
</FrameLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/ui_DIMEN_500.0PX">
<SurfaceView
android:id="@+id/surfaceview_playVideo"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
/>
<!--<FrameLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent">-->
<ImageView
android:id="@+id/img_playVideo_novideo"
... ... @@ -36,23 +38,52 @@
android:layout_height="match_parent"
android:background="@mipmap/novideo"
/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/fra_videoPlay_publish"
android:layout_width="150dp"
android:layout_gravity="right|bottom"
android:layout_height="100dp">
<Button
android:id="@+id/btn_videoPlay_exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:text="退出课堂,界面还在"
android:text="开始推流"
android:visibility="gone"
/>
</FrameLayout>
</RelativeLayout>
</FrameLayout>
</RelativeLayout>
<SurfaceView
android:id="@+id/surfaceview_playVideo_text"
android:layout_width="150dp"
android:layout_height="200dp"
android:visibility="gone"/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/btn_videoPlay_stopPublish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="结束按钮"
android:visibility="gone"
/>
</FrameLayout>
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<!--</FrameLayout>-->
<com.mang.xdy.demo.widget.view.NoScrollViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
... ... @@ -64,8 +95,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone">
>
<include
layout="@layout/home_media_controller"
... ...
... ... @@ -170,7 +170,14 @@ public interface Constants {
* 获取Audio推流地址
*/
String GET_AUDIO_PUBLISH_PATH="getAudioPublishPath";
/**
* 推流地址返回成功
*/
String VIDEO_PUBLISH_RESULT= "video_publish_result";
/**
* 开始录制回放
*/
String START_RECORD_PLAY_BACK="startRecordPlayback";
String UN_PUBLISH_VIDEO="unPublishVideo";
/*Context为空的时候给出的提示*/
String ERROR_CONTENT_NULL="Xdy,init context is null";
... ... @@ -186,6 +193,10 @@ public interface Constants {
* activity is null
*/
String ERROR_TYPE_ACTIVITY="xdysdk activity is null";
/**
* 断线重连时间间隔
*/
long TIME_NET_ERROR_RECONNECTION=6000;
/**********************************以下实现为自定义code 先定义后实现*********************************************************************/
/**
... ...
... ... @@ -66,7 +66,7 @@ public class XdyJsCore {
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
super.onConsoleMessage(message, lineNumber, sourceID);
//TODO 发布时去掉
XdyLogUtil.e("message:"+message+" lineNumber:"+" sourceId:"+sourceID);
// XdyLogUtil.e("message:"+message+" lineNumber:"+" sourceId:"+sourceID);
}
});
mWebView.post(new Runnable() {
... ... @@ -104,7 +104,7 @@ public class XdyJsCore {
@JavascriptInterface
public void _js2native(String id,String parmp){
/* _native2js("接口名称","参数为JOSN字符串")*/
XdyLogUtil.e("s3sjs2native","id:"+id+" parmp:"+parmp);
// XdyLogUtil.e("s3sjs2native","id:"+id+" parmp:"+parmp);
if(mOnXdyAsyncMessageListener !=null){
mOnXdyAsyncMessageListener.getSdyAsyncMessageListener(id,parmp);
}
... ... @@ -118,13 +118,11 @@ public class XdyJsCore {
* @param parameter
*/
protected void native2js( String id, String parameter) {
XdyLogUtil.e("推流线程native2js:",Thread.currentThread().getId()+"id:"+id);
// XdyLogUtil.e("推流线程native2js:",Thread.currentThread().getId()+"id:"+id);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mWebView.evaluateJavascript("javascript:_native2js('" + id + "','"+parameter+"')", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
XdyLogUtil.e(TAG+"同步获取的数据", value);
}
});
}else{
... ...
... ... @@ -75,10 +75,11 @@ public class XdyPublisherCore implements SurfaceHolder.Callback, Camera.PreviewC
xdyPublisher = new SmartPublisherJni();
}
isStart=true;
pubSurfaceViewHolder = mSurfaceView.getHolder();
pubSurfaceViewHolder.addCallback(this);
pubSurfaceViewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
if(pubSurfaceViewHolder==null) {
pubSurfaceViewHolder = mSurfaceView.getHolder();
pubSurfaceViewHolder.addCallback(this);
pubSurfaceViewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
Log.i(TAG, "surfaceCreated..");
try {
currentCameraType = FRONT;
... ... @@ -87,15 +88,13 @@ public class XdyPublisherCore implements SurfaceHolder.Callback, Camera.PreviewC
mCamera = openCamera(currentCameraType);
mCamera.stopPreview();
initCamera(pubSurfaceViewHolder);
Log.e("推流","0000000000");
}
Log.e("推流","11111111");
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "surfaceCreated: 异常了"+e.getMessage());
}
int i = xdyPublisher.SmartPublisherInit(mActivity, audio_opt,video_opt, videoWidth, videoHight);
XdyLogUtil.e(TAG, "SmartPublisherInit:初始化返回值是0成功: " + i);
XdyLogUtil.e(TAG, ": " + i);
xdyPublisher.SetSmartPublisherEventCallback(new EventHande());
XdyLogUtil.e(TAG,"url:"+rtmpUrls);
if (xdyPublisher.SmartPublisherSetURL(rtmpUrls) != 0) {
... ... @@ -445,6 +444,10 @@ public class XdyPublisherCore implements SurfaceHolder.Callback, Camera.PreviewC
if (xdyPublisher != null) {
xdyPublisher.SmartPublisherStop();
}
if(mCamera!=null) {
mCamera.stopPreview();
}
}
public void onResumePublisher(){
isStart=true;
... ...
... ... @@ -22,10 +22,14 @@ import com.mang.xdy.listener.ObserverListener;
import com.mang.xdy.listener.SubjectListener;
import com.mang.xdy.message.MsgManage;
import com.mang.xdy.utils.JsonUtil;
import com.mang.xdy.utils.NetWorkUtils;
import com.mang.xdy.utils.PlayerUtils;
import com.mang.xdy.utils.XdyLogUtil;
import com.mang.xdy.utils.XdyStringUtils;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
... ... @@ -55,14 +59,20 @@ public class XdySdk implements SubjectListener{
/*缓存管理*/
private static ACache aCache;
//TODO 拿不到同步的数据先保留信息(必须释放,否者内存泄漏)
private SurfaceView mSurfaceView;
private SurfaceView mSurfaceView_Publish;
private Activity mActivity;
/*是否正在推流,mcu自动断开的时候使用,推流成功后才表示正在使用*/
private boolean isPublisher=false;
private boolean isPublisher =false;
// /*Audio 推送中,resume需要使用*/
private boolean isPublisherAudio=false;
/*推流重连状态,如果是重连状态会有一系列加入课堂的情况*/
private boolean isReconnection=false;
/*是否进行录制回放*/
private boolean isRecordPlayBack=false;
/*观察者集合*/
private List<ObserverListener> observerListenerList=new ArrayList<ObserverListener>();
/*推流地址*/
private String publish_url="";
@Override
public void add(ObserverListener observerListener) {
... ... @@ -78,20 +88,14 @@ public class XdySdk implements SubjectListener{
@Override
public void remove(ObserverListener observerListener) {
if(observerListenerList.contains(observerListener)){
if(observerListenerList!=null){
if(observerListenerList.contains(observerListener)) {
observerListenerList.remove(observerListener);
}
}
}
/**
* 退出时清除信息(重置js监听)
*/
public void removeAll(){
// if(observerListenerList!=null){
// observerListenerList.clear();
// }
// mXdyJsCore.init(mContext);
}
/**
* 对外提供的异步消息接收接口)
... ... @@ -119,6 +123,14 @@ public class XdySdk implements SubjectListener{
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if(msg.what==Constants.LEAVE_CLASS_CODE){
if(!NetWorkUtils.isNetworkConnected(mContext)) {
if (mXdySdk != null) {
mXdySdk.onPublisherStop();
handler.removeCallbacksAndMessages(null);
}
}
}
}
};
/**
... ... @@ -133,33 +145,6 @@ public class XdySdk implements SubjectListener{
mContext=context;
mXdyJsCore = XdyJsCore.getInstance(context);
mMsgManage=MsgManage.getErrorMsgInstance();
// mMsgManage.setXdyMsgManageListener(new MsgManage.OnXdyMsgManageListener() {
// @Override
// public void onXdyMsgResponse(final String type, final String response) {
// //处理数据异常,传递给最外层
// handler.post(new Runnable() {
// @Override
// public void run() {
// handleListener(type,response);
// }
// });
//
// }
// });
// mXdyJsCore.setXdyAsyncMessageListener(new XdyJsCore.OnXdyAsyncMessageListener() {
// @Override
// public void getSdyAsyncMessageListener(final String id, final String parameter) {
// handler.post(new Runnable() {
// @Override
// public void run() {
// handleData(id,parameter);
//
// }
// });
//
// }
// });
// aCache=ACache.get(mContext);
}
/**
... ... @@ -171,17 +156,17 @@ public class XdySdk implements SubjectListener{
judgeCore();
//再次停止播放器
switch (type){
// case "unPublishAudio":
// //停止推送音频
// case "unPublishVideo":
// //停止推流video(关闭视频:根据api)
// onPublisherStop();
// break;
case "stopPublishAudio":
//停止推送音频
case "stopPublishVideo":
//停止推流video(关闭视频:根据api)
onPublisherStop();
break;
case "stopAudio":
//停止播放audio()
case"stopVideo":
//停止播放video( 停止播放:根据api)
// onPlayStop();
onPlayDestroy();
break;
}
handler.post(new Runnable() {
... ... @@ -194,13 +179,13 @@ public class XdySdk implements SubjectListener{
}
/**
* 测试封装 用过时标识区分
*
* @param type
* @param
* @param surfaceView
* @param activity
* @param
* @deprecated
*
*/
public void api(String type,String mediaId, SurfaceView surfaceView, Activity activity) {
judgeString(type);
... ... @@ -220,10 +205,19 @@ public class XdySdk implements SubjectListener{
currentPlayId=mediaId;
AudioPlayBean audioPlayBean=JsonUtil.parseJsonToBean(json_audio,AudioPlayBean.class);
if(audioPlayBean!=null) {
if(mXdyPlayerCore==null) {
mXdyPlayerCore = XdyPlayerCore.getXdyPlayerCore(audioPlayBean.getRtmpUrl(), activity);
String play_url_audio="";
if(isRecordPlayBack){
play_url_audio=audioPlayBean.getReplay();
}else{
play_url_audio=audioPlayBean.getRtmpUrl() ;
if(mXdyPlayerCore==null) {
mXdyPlayerCore = XdyPlayerCore.getXdyPlayerCore(play_url_audio, activity);
}else{
mXdyPlayerCore.onStopPlay();
}
mXdyPlayerCore.playAudio(play_url_audio, new EventHande_Play());
}
mXdyPlayerCore.playAudio(audioPlayBean.getRtmpUrl(), new EventHande());
}else{
XdyLogUtil.e(TAG,"Can not get play Audio response");
}
... ... @@ -243,10 +237,20 @@ public class XdySdk implements SubjectListener{
currentPlayId=mediaId;
VideoPlayBean videoPlayBean=JsonUtil.parseJsonToBean(json_video,VideoPlayBean.class);
if(videoPlayBean!=null){
if(mXdyPlayerCore==null) {
mXdyPlayerCore = XdyPlayerCore.getXdyPlayerCore(videoPlayBean.getRtmpUrl(), activity);
String play_url_video="";
if(isRecordPlayBack){
play_url_video=videoPlayBean.getReplay();
}else{
play_url_video=videoPlayBean.getRtmpUrl();
if(mXdyPlayerCore==null) {
mXdyPlayerCore = XdyPlayerCore.getXdyPlayerCore(play_url_video, activity);
}else{
//重复播放时候
mXdyPlayerCore.onStopPlay();
}
mXdyPlayerCore.playVideo(play_url_video, surfaceView,new EventHande_Play());
}
mXdyPlayerCore.playVideo(videoPlayBean.getRtmpUrl(), surfaceView,new EventHande());
}else{
//统一提示推流错误
XdyLogUtil.e(TAG,"Can not get play Video response");
... ... @@ -262,7 +266,7 @@ public class XdySdk implements SubjectListener{
*
*/
getPublishPathVideo();
mSurfaceView=surfaceView;
mSurfaceView_Publish=surfaceView;
mActivity=activity;
break;
case Constants.PUBLISH_AUDIO:
... ... @@ -325,6 +329,17 @@ public class XdySdk implements SubjectListener{
*/
switch (type) {
case Constants.CLASS_JOIN_SUCCESS:
//判断是否是录制回放,调整播流地址
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(response);
isRecordPlayBack = jsonObject.optBoolean("isRecordPlayBack");
} catch (JSONException e) {
e.printStackTrace();
}
handleListener(type,response);
break;
case Constants.VIDEO_GET_PUBLISH_PATH:
//推流地址的返回值拿到正确的推流地址直接开始推流
//打开推流视频
... ... @@ -339,7 +354,7 @@ public class XdySdk implements SubjectListener{
String video_url = getPublishPathReceiveBean.getPublishUrl();
aCache.put(Constants.VIDEO_GET_PUBLISH_PATH, video_url);
//判断
if (mSurfaceView == null) {
if (mSurfaceView_Publish == null) {
//todo 输出提示
throw new IllegalArgumentException(Constants.ERROR_TYPE_SURFACEVIEW);
}
... ... @@ -351,8 +366,9 @@ public class XdySdk implements SubjectListener{
mXdyPublisherCore = new XdyPublisherCore(1, 1, mActivity);
}
publish_url=video_url;
isPublisher=true;
mXdyPublisherCore.publisher(video_url,mSurfaceView, new EventHande());
isPublisher =true;
isPublisherAudio=false;
mXdyPublisherCore.publisher(video_url,mSurfaceView_Publish, new EventHande_Publish());
// PlayerUtils.setPublishSendSuccessVideo(aCache.getAsString(Constants.GET_VIDEO_PUBLISH_PATH));
//// TODO: 2017/4/13 大牛连接成功回调没有监听到 暂时在这告知后台,(后续加上网路判断,摄像头判断)
setPublishSendSuccessVideo(video_url);
... ... @@ -387,8 +403,10 @@ public class XdySdk implements SubjectListener{
}
if(mXdyPublisherCore==null)
mXdyPublisherCore=new XdyPublisherCore(1,0,mActivity);
mXdyPublisherCore.publisherAudio(audio_url,new EventHande());
isPublisher=true;
mXdyPublisherCore.publisherAudio(audio_url,new EventHande_Publish());
publish_url=audio_url;
isPublisher =true;
isPublisherAudio=true;
//// TODO: 2017/4/13 大牛连接成功回调没有监听到 暂时在这告知后台,(后续加上网路判断,摄像头判断)
PlayerUtils.setPublishSendSuccessAudio(audio_url);
}else{
... ... @@ -412,7 +430,7 @@ public class XdySdk implements SubjectListener{
handleListener(Constants.PUBLISH_RERUEN_SUCCESS,"");
}
break;
case "video_publish_result":
case Constants.VIDEO_PUBLISH_RESULT:
//接收发送推流地址给后台返回的信息
String publishReplay=response;
XdyLogUtil.e(TAG,"后台成功接收到,返回值"+XdyStringUtils.stringToJson(publishReplay));
... ... @@ -424,7 +442,10 @@ public class XdySdk implements SubjectListener{
handleListener(Constants.PUBLISH_RERUEN_SUCCESS,"");
}else{
//TODO
handleListener(Constants.PUBLISH_RERUEN_SUCCESS,"");
handleListener(Constants.ERROR_CODE,"{\n" +
" \"code\": 804,\n" +
" \"reson\": \"推流失败\"\n" +
"}");
}
break;
case Constants.VIDEO_PLAY:
... ... @@ -433,16 +454,20 @@ public class XdySdk implements SubjectListener{
String video=response;
VideoPlayBean videoPlayBean= JsonUtil.parseJsonToBean(video,VideoPlayBean.class);
if(videoPlayBean!=null) {
aCache.put(videoPlayBean.getMediaId()+"", video);
handleListener(type,videoPlayBean.getMediaId()+"");
if(videoPlayBean.getMediaId()!=videoPlayBean.getFromNodeId()) {
aCache.put(videoPlayBean.getMediaId() + "", video);
handleListener(type, videoPlayBean.getMediaId() + "");
}
}
break;
case Constants.AUDIO_PLAY:
String audio=response;
AudioPlayBean audioPlayBean=JsonUtil.parseJsonToBean(audio,AudioPlayBean.class);
if(audioPlayBean!=null){
aCache.put(audioPlayBean.getMediaId()+"",audio);
handleListener(type,audioPlayBean.getMediaId()+"");
if(audioPlayBean.getMediaId()!=audioPlayBean.getFromNodeId()) {
aCache.put(audioPlayBean.getMediaId() + "", audio);
handleListener(type, audioPlayBean.getMediaId() + "");
}
}
break;
case Constants.ERROR_CODE:
... ... @@ -456,15 +481,14 @@ public class XdySdk implements SubjectListener{
*/
// 方案 二 mcu 断开,页面也断开,用户需要手动重新调用
if(isPublisher) {
// onPublisherStop();
// api("publishVideo", "", mSurfaceView, mActivity);
if(!NetWorkUtils.isNetworkConnected(mContext)){
//todo判断是否有网络,没有网络的话就让其退出
// TOdo 延迟10秒,
// onPublisherStop();
handler.sendEmptyMessageDelayed(Constants.LEAVE_CLASS_CODE,Constants.TIME_NET_ERROR_RECONNECTION);
}
isReconnection=true;
// XdyLogUtil.e("mcu 断线了重连","断线重连,使用的都是同一个保存的url");
// api(Constants.UN_PUBLISH_VIDEO,"");
// setPublishSendSuccessVideo(publish_url);
// getPublishPathVideo();
}
// onPublisherStop();
}
}
handleListener(type,response);
... ... @@ -475,21 +499,7 @@ public class XdySdk implements SubjectListener{
* 此时,停止推流,清除surfaceview Activtity 数据,url数据
*/
if(isPublisher){
onPublisherStop();
}
handleListener(type,response);
break;
case Constants.CLASS_JOIN_SUCCESS:
if(isReconnection){
// api("stopPublishVideo","");
// if(mXdyPublisherCore!=null){
// mXdyPublisherCore.onStopPublisher();
// mXdyPublisherCore=null;
// }
// getPublishPathVideo();;
// setPublishSendSuccessVideo(publish_url);
}
handleListener(type,response);
break;
... ... @@ -532,13 +542,13 @@ public class XdySdk implements SubjectListener{
return false;
}
/**
* onPause 暂停所有的,退出都在这里
* 退出时清除信息(重置js监听)
*/
public void onPlayPauseAll(){
public void removeAll(){
if(mXdyPlayerCore!=null) {
mXdyPlayerCore.onPause();
}
if(mXdyJsCore!=null) {
if(mXdyJsCore!=null&&!isRecordPlayBack) {
mXdyJsCore.init(mContext);
}
}
... ... @@ -556,7 +566,8 @@ public class XdySdk implements SubjectListener{
}
/**
* 推送视频音频停止方法
* 推送视频音频停止方法(最后调用的方法)
* @deprecated daniu sdk handle best
*/
public void onPublisherStop(){
if(mXdyPublisherCore!=null){
... ... @@ -565,15 +576,16 @@ public class XdySdk implements SubjectListener{
}
//如果正在推流,msurfaceView ,mActivity不清空
if(!isPublisher) {
if (mSurfaceView != null) {
mSurfaceView = null;
if (mSurfaceView_Publish != null) {
mSurfaceView_Publish = null;
}
if (mActivity != null) {
mActivity = null;
}
}
isPublisher=false;
isPublisher =false;
isReconnection=false;
isPublisherAudio=false;
}
/**
... ... @@ -584,21 +596,31 @@ public class XdySdk implements SubjectListener{
mXdyPublisherCore.onPausePublisher();
}
}
private String publish_url="";
/**
* onResume 调用,目前是空方法
* TODO 只有一个boolean
* 开始isPublish 为false
* 开始推流初始化后onresume 就是开始
* @deprecated 大牛 sdk处理的更好
*/
public void onPublisherResume(){
if(!isPublisher){
return;
}
if(mXdyPublisherCore!=null) {
mXdyPublisherCore.onResumePublisher();
if (!TextUtils.isEmpty(publish_url)) {
mXdyPublisherCore.publisher(publish_url, mSurfaceView, new EventHande());
if(!isPublisherAudio){
mXdyPublisherCore.publisher(publish_url, mSurfaceView_Publish, new EventHande_Publish());
}else{
mXdyPublisherCore.publisherAudio(publish_url,new EventHande_Publish());
}
}
}
}
class EventHande implements SmartEventCallback {
class EventHande_Play implements SmartEventCallback {
@Override
public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) {
switch (code) {
... ... @@ -635,16 +657,54 @@ private String publish_url="";
}
}
class EventHande_Publish implements SmartEventCallback {
@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.e(TAG, "开始。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:
Log.e(TAG, "连接中。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:
Log.e(TAG, "连接失败。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:
Log.e(TAG, "连接成功。。");
//TODO //如果连接成功发送连接成功信息,判断的方式有待考虑
// PlayerUtils.setPublishSendSuccessVideo(aCache.getAsString(Constants.GET_VIDEO_PUBLISH_PATH));
// XdySdk.getXdyInstance().notifyObserver("video_success","");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
Log.e(TAG, "连接断开。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
Log.i(TAG, "关闭。。");
notifyObserver("play_stop",currentPlayId+"");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
Log.e(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
//在这里最接近得到播放的成功的准确回调
notifyObserver(Constants.PLAY_SUCCESS,currentPlayId+"");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
Log.e(TAG, "收不到媒体数据,可能是url错误。。");
}
}
}
/**
* 向后台发送推流数据(Auido)成功信息
* @param url
*/
public static void setPublishSendSuccessAudio(String url) {
protected static void setPublishSendSuccessAudio(String url) {
PublisherSuccessEntity publisherEntity = new PublisherSuccessEntity();
if (!TextUtils.isEmpty(url)) {
publisherEntity.setPublishUrl(url);
final String pamp = new Gson().toJson(publisherEntity);
XdyLogUtil.e("推流成功", "" + pamp);
XdySdk.getXdyInstance().api(Constants.PUBLISH_AUDIO, pamp);
}
... ... @@ -654,12 +714,12 @@ private String publish_url="";
* 向后台发送推流(Video)成功的信息
* @param url
*/
public static void setPublishSendSuccessVideo(String url) {
protected static void setPublishSendSuccessVideo(String url) {
PublisherSuccessEntity publisherEntity = new PublisherSuccessEntity();
if (!TextUtils.isEmpty(url)) {
publisherEntity.setPublishUrl(url);
final String pamp = new Gson().toJson(publisherEntity);
XdyLogUtil.e("推流线程setPublishSendSuccessVideo:",Thread.currentThread().getId()+"");
XdyLogUtil.e("setPublishSendSuccessVideo:",Thread.currentThread().getId()+"");
XdySdk.getXdyInstance().api(Constants.PUBLISH_VIDEO, pamp);
}
... ...
... ... @@ -3,6 +3,8 @@ package com.mang.xdy.utils;
import android.text.TextUtils;
import android.util.Log;
import java.util.Locale;
/**
* Created by abao on 2017/3/30.
*/
... ... @@ -60,4 +62,25 @@ public class XdyStringUtils {
return;
}
}
/**
* 时间
* @param currentTime
* @return
*/
private String generateTime(long currentTime) {
int totalSeconds = (int) (currentTime);
int seconds = totalSeconds % 60;
int minutes = (totalSeconds / 60) % 60;
int hours = totalSeconds / 3600;
if (hours > 0) {
return String.format(Locale.US, "%02d:%02d:%02d", hours, minutes,
seconds).toString();
} else {
return String.format(Locale.US, "%02d:%02d", minutes, seconds)
.toString();
}
}
}
... ...