huangxinbao

fix whitebroad

正在显示 24 个修改的文件 包含 2158 行增加563 行删除
... ... @@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
... ...
... ... @@ -71,6 +71,7 @@ public class AudioPublisherActivity extends AppCompatActivity {
SurfaceView surfaceviewPlayVideo;
private String initClass = "";
private String publisherSuccess="";
private XdySdk xdySdk;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
... ... @@ -82,7 +83,7 @@ public class AudioPublisherActivity extends AppCompatActivity {
break;
case -1:
//退出
XdySdk.api("leaveClass", "");
xdySdk.api("leaveClass", "");
break;
case 0:
parseJoinClass((String) msg.obj,true);
... ... @@ -113,7 +114,7 @@ public class AudioPublisherActivity extends AppCompatActivity {
break;
case 7:
//停止播放
XdySdk.onPlayStop();
xdySdk.onPlayStop();
// img_playVideo_novideo.setVisibility(View.GONE);
// surfaceviewPlayVideo.refreshDrawableState();;
// ToastUtil.showToastshort("播放音视/视频停止",VideoPlayActivity.this);
... ... @@ -133,11 +134,12 @@ public class AudioPublisherActivity extends AppCompatActivity {
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() {
xdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
@Override
public void onXdyAsyncMessageReceiver(String type, String response) {
... ... @@ -176,7 +178,7 @@ public class AudioPublisherActivity extends AppCompatActivity {
public void init() {
initClass = getIntent().getStringExtra("init");
XdySdk.api("init", initClass);
xdySdk.api("init", initClass);
}
//判断解析是否有密码
... ... @@ -211,26 +213,26 @@ public class AudioPublisherActivity extends AppCompatActivity {
String temp=new Gson().toJson(joinClass);
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e("加入课堂", jsonParmp);
XdySdk.api("joinClass", 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);
// 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);
}
// 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) {
... ... @@ -252,7 +254,7 @@ public class AudioPublisherActivity extends AppCompatActivity {
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e(TAG, "文档" + jsonParmp);
XdySdk.api("getDocImageFullPath", jsonParmp);
xdySdk.api("getDocImageFullPath", jsonParmp);
}
}
... ... @@ -263,7 +265,7 @@ public class AudioPublisherActivity extends AppCompatActivity {
"}";
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e(TAG, "聊天" + jsonParmp);
XdySdk.api("sendChatMsg", jsonParmp);
xdySdk.api("sendChatMsg", jsonParmp);
}
... ... @@ -281,55 +283,55 @@ public class AudioPublisherActivity extends AppCompatActivity {
String ids_new = "getVideoPublishPath";
String tem = "{ \"type\": \"live\"}";
String s = XdyStringUtils.stringToJson(tem, true);
XdySdk.api(ids_new, s);
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());
}
// 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,"");
xdySdk.api(Constants.PUBLISH_AUDIO, "", surfaceview_pubisherVideo, AudioPublisherActivity.this);
}
@Override
public void onBackPressed() {
XdySdk.api("unPublishVideo","");
xdySdk.api("unPublishVideo","");
super.onBackPressed();
}
... ... @@ -337,7 +339,7 @@ public class AudioPublisherActivity extends AppCompatActivity {
@Override
protected void onDestroy() {
XdySdk.onPublisherStop();
xdySdk.onPublisherStop();
super.onDestroy();
}
... ... @@ -364,7 +366,7 @@ public class AudioPublisherActivity extends AppCompatActivity {
break;
case R.id.btn_videoPlay_stop:
ToastUtil.showToastshort("正在退出,请稍等",this);
XdySdk.api("unPublishVideo","");
xdySdk.api("unPublishVideo","");
finish();
break;
}
... ...
package com.mang.xdy.demo.activity;
import android.app.AlertDialog;
;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.Image;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
... ... @@ -14,7 +9,6 @@ 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;
... ... @@ -23,74 +17,41 @@ 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.bumptech.glide.Glide;
import com.eventhandle.SmartEventCallback;
import com.google.gson.Gson;
import com.mang.xdy.common.Constants;
import com.mang.xdy.core.SPUtil;
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.GetDocImageEntity;
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.VideoPlayBean;
import com.mang.xdy.demo.bean.WhiteboardUpdateEntity;
import com.mang.xdy.demo.utils.JsonUtil;
import com.mang.xdy.demo.utils.ToastUtil;
import com.mang.xdy.demo.widget.CanvasView;
import com.mang.xdy.utils.XdyLogUtil;
import com.mang.xdy.utils.XdyStringUtils;
import com.squareup.picasso.Picasso;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class VideoPlayActivity 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.img_playVideo_novideo)
ImageView img_playVideo_novideo;
@BindView(R.id.bt_stop)
Button bt_stop;
@BindView(R.id.img_playVideo_docShow)
ImageView mDocImage;
private String username="";
private String userpwd="";
private PersonDialog personDialog;
private SimpleFragmentPagerAdapter pagerAdapter;
private ViewPager viewPager;
private TabLayout tabLayout;
@BindView(R.id.surfaceview_playVideo)
SurfaceView surfaceviewPlayVideo;
@BindView(R.id.canvas_playVideo_showWhiteBroad)
CanvasView mCanvasView;
private String initClass = "";
public OnAcceptFromCoreToFragmentListener mOnAcceptFromCoreToFragmentListener;
public interface OnAcceptFromCoreToFragmentListener{
void onAcceptInfo(String type,String response);
}
public void setmOnAcceptFromCoreToFragmentListener(OnAcceptFromCoreToFragmentListener mOnAcceptFromCoreToFragmentListener){
this.mOnAcceptFromCoreToFragmentListener=mOnAcceptFromCoreToFragmentListener;
}
private XdySdk xdySdk;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
... ... @@ -102,7 +63,7 @@ public class VideoPlayActivity extends AppCompatActivity {
break;
case -1:
//退出
XdySdk.api("leaveClass", "");
xdySdk.api("leaveClass", "");
break;
case 0:
parseJoinClass((String) msg.obj,true);
... ... @@ -123,20 +84,15 @@ public class VideoPlayActivity extends AppCompatActivity {
getDoc((String) msg.obj);
break;
case 4:
//发送消息
sendMeg();
break;
case 5:
//接受消息
getMsg((String) msg.obj);
break;
case 6:
//图片
setDocImage((String) msg.obj);
break;
case 7:
//停止播放
XdySdk.onPlayStop();
xdySdk.onPlayStop();
img_playVideo_novideo.setVisibility(View.VISIBLE);
// surfaceviewPlayVideo.refreshDrawableState();;
// ToastUtil.showToastshort("播放音视/视频停止",VideoPlayActivity.this);
... ... @@ -151,11 +107,11 @@ public class VideoPlayActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_play);
ButterKnife.bind(this);
xdySdk=XdySdk.getXdyInstance();
init();
setTablayout();
setTablayout();
XdyLogUtil.e(TAG,"当前线程 main:"+android.os.Process.myPid()+"线程:"+Thread.currentThread().getId()+"");
XdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
xdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
@Override
public void onXdyAsyncMessageReceiver(String type, String response) {
Message message = Message.obtain();
... ... @@ -188,6 +144,8 @@ public class VideoPlayActivity extends AppCompatActivity {
case "class_join_success":
//加入课堂成功
ToastUtil.showToastshort("加入课堂成功", VideoPlayActivity.this);
String userJson=response;
SPUtil.putString(VideoPlayActivity.this, Constants.CLASS_JOIN_SUCCESS,userJson);
break;
case "class_delete_roster":
// ToastUtil.showToastshort("离开课堂", VideoPlayActivity.this);
... ... @@ -209,7 +167,6 @@ public class VideoPlayActivity extends AppCompatActivity {
break;
case "whiteboard_annotation_update":
ToastUtil.showToastshort("白板信息更新" + response, VideoPlayActivity.this);
showDoc(type,response);
break;
case "getDocImageFullPath":
// String urls= "rtmp://player.daniulive.com:1935/hls/stream";;
... ... @@ -230,16 +187,13 @@ public class VideoPlayActivity extends AppCompatActivity {
XdyLogUtil.e("xuedianyunlog",response);
}
}
if(mOnAcceptFromCoreToFragmentListener!=null){
mOnAcceptFromCoreToFragmentListener.onAcceptInfo(type,response);
}
}
});
}
public void init() {
initClass = getIntent().getStringExtra("init");
XdySdk.api("init", initClass);
xdySdk.api("init", initClass);
}
... ... @@ -265,12 +219,6 @@ public class VideoPlayActivity extends AppCompatActivity {
}
//加入课堂
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);
... ... @@ -283,112 +231,60 @@ public class VideoPlayActivity extends AppCompatActivity {
String temp=new Gson().toJson(joinClass);
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e("加入课堂", jsonParmp);
XdySdk.api("joinClass", jsonParmp);
xdySdk.api("joinClass", jsonParmp);
}
VideoPlayBean videoPlayBean;
/**
* 播放视频
* @param response
*/
public void playVideo(String response) {
// videoPlayBean = JsonUtil.parseJsonToBean(response, VideoPlayBean.class);
// if (videoPlayBean != null && videoPlayBean.getRtmpUrl() != null) {
// XdyLogUtil.e(TAG, "执行了ss" + videoPlayBean.getRtmpUrl());
bt_stop.setEnabled(true);
// XdySdk.setAsyncApi("playVideo", videoPlayBean.getRtmpUrl(), surfaceviewPlayVideo, VideoPlayActivity.this, new EventHande_Video());
XdySdk.api("playVideo", response+"", surfaceviewPlayVideo, VideoPlayActivity.this,"");
img_playVideo_novideo.setVisibility(View.GONE);
// }else{
// bt_stop.setEnabled(false);
// }
xdySdk.api("playVideo", response+"", surfaceviewPlayVideo, VideoPlayActivity.this);
img_playVideo_novideo.setVisibility(View.GONE);
ToastUtil.showToastshort("视频播放初始化",VideoPlayActivity.this);
}
/**
* 播放音频
* @param response
*/
public void playAudio(String response) {
// AudioPlayBean audioPlayBean = JsonUtil.parseJsonToBean(response, AudioPlayBean.class);
// if (audioPlayBean != null && audioPlayBean.getRtmpUrl() != null) {
// XdyLogUtil.e(TAG, "执行了" + audioPlayBean.getRtmpUrl());
// XdySdk.setAsyncApi("playAudio", audioPlayBean.getRtmpUrl(), null, VideoPlayActivity.this, new EventHande_Video());
XdySdk.api("playAudio", response, null, VideoPlayActivity.this, "");
img_playVideo_novideo.setVisibility(View.GONE);
ToastUtil.showToastshort("音频播放初始化",VideoPlayActivity.this);
// }
xdySdk.api("playAudio", response, null, VideoPlayActivity.this);
img_playVideo_novideo.setVisibility(View.GONE);
ToastUtil.showToastshort("音频播放初始化",VideoPlayActivity.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" +
// "}";
GetDocImageEntity getDocImageEntity=new GetDocImageEntity();
getDocImageEntity.setPageNum(1);
// getDocImageEntity.setRelativeUrl("/DocSharing/data/1087553281/20170409-204600041/d32594763768243bddc64934be5088a0.swf");
getDocImageEntity.setRelativeUrl(url);
getDocImageEntity.setType("jpg");
String jsonParmp = new Gson().toJson(getDocImageEntity);
XdyLogUtil.e(TAG, "文档" + jsonParmp);
XdySdk.api("getDocImageFullPath", 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() {
}
public void publisherVideo(String response) {
}
@Override
public void onBackPressed() {
super.onBackPressed();
XdySdk.onPlayStop();
xdySdk.onPlayStop();
}
@OnClick({R.id.btn_videoPlay_chat, R.id.btn_videoPlay_pubsherVideo,R.id.bt_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();
break;
case R.id.bt_stop:
//停止视频
if(videoPlayBean!=null) {
XdySdk.api("stopVideo", videoPlayBean.getMediaId() + "");
}
break;
// case R.id.bt_stop:
// //停止视频
// if(videoPlayBean!=null) {
// xdySdk.api("stopVideo", videoPlayBean.getMediaId() + "");
// }
// break;
}
}
class PersonDialog extends Dialog {
... ... @@ -453,58 +349,6 @@ public class VideoPlayActivity extends AppCompatActivity {
});
}
}
public void setDocImage(String resonse){
if(resonse.length()>10){
String temp=XdyStringUtils.stringToJson(resonse);
String url=temp.substring(2,temp.length()-2);
urlsss=url;
XdyLogUtil.e(TAG,"截取后的"+url);
Picasso.with(this).load(url).placeholder(R.mipmap.novideo).into(mDocImage);
getBitmap(url);
}
}
String urlsss="";
Bitmap bitmap;
public void showDoc(String type,String response){
mCanvasView.setZOrderMediaOverlay(true);
mCanvasView.setBitmap(bitmap,false);
WhiteboardUpdateEntity whiteboardUpdateEntity= JsonUtil.parseJsonToBean(response,WhiteboardUpdateEntity.class);
if(whiteboardUpdateEntity!=null){
drawline(whiteboardUpdateEntity);
}
}
private void drawline(WhiteboardUpdateEntity o) {
if (o != null) {
if (o.isFresh) {
if (mCanvasView != null) {
mCanvasView.clear();
}
}
if (o.annotaionItems != null) {
if (mCanvasView != null) {
mCanvasView.drawLine(o.annotaionItems);
}
}
}
}
public void getBitmap(final String url){
new Thread(){
@Override
public void run() {
super.run();
try {
bitmap= Glide.with(VideoPlayActivity.this).load(url).asBitmap().into(480,480).get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
}.start();
}
}
... ...
... ... @@ -67,7 +67,7 @@ public class VideoPublisherActivity extends AppCompatActivity {
private String userpwd="";
private PersonDialog personDialog;
private SimpleFragmentPagerAdapter pagerAdapter;
private XdySdk xdySdk;
private ViewPager viewPager;
//默认推送视频
private boolean isPusherAudio=false;
... ... @@ -93,7 +93,7 @@ public class VideoPublisherActivity extends AppCompatActivity {
break;
case -1:
//退出
XdySdk.api("leaveClass", "");
xdySdk.api("leaveClass", "");
break;
case 0:
parseJoinClass((String) msg.obj,true);
... ... @@ -126,7 +126,7 @@ public class VideoPublisherActivity extends AppCompatActivity {
break;
case 7:
//停止播放
XdySdk.onPlayStop();
xdySdk.onPlayStop();
// img_playVideo_novideo.setVisibility(View.GONE);
// surfaceviewPlayVideo.refreshDrawableState();;
// ToastUtil.showToastshort("播放音视/视频停止",VideoPlayActivity.this);
... ... @@ -148,9 +148,10 @@ public class VideoPublisherActivity extends AppCompatActivity {
ButterKnife.bind(this);
btn_videoPlay_publisherAudio.setVisibility(View.GONE);
// setTablayout();
xdySdk=XdySdk.getXdyInstance();
init();
XdyLogUtil.e(TAG,"当前线程 main:"+android.os.Process.myPid()+"线程:"+Thread.currentThread().getId()+"");
XdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
xdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
@Override
public void onXdyAsyncMessageReceiver(String type, String response) {
... ... @@ -191,7 +192,7 @@ public class VideoPublisherActivity extends AppCompatActivity {
public void init() {
initClass = getIntent().getStringExtra("init");
XdySdk.api("init", initClass);
xdySdk.api("init", initClass);
}
//判断解析是否有密码
... ... @@ -226,26 +227,26 @@ public class VideoPublisherActivity extends AppCompatActivity {
String temp=new Gson().toJson(joinClass);
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e("加入课堂", jsonParmp);
XdySdk.api("joinClass", 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, VideoPublisherActivity.this, new EventHande_Video());
// img_playVideo_novideo.setVisibility(View.GONE);
ToastUtil.showToastshort("视频播放初始化",VideoPublisherActivity.this);
// 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, VideoPublisherActivity.this, new EventHande_Video());
//// img_playVideo_novideo.setVisibility(View.GONE);
// ToastUtil.showToastshort("视频播放初始化",VideoPublisherActivity.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, VideoPublisherActivity.this, new EventHande_Video());
// img_playVideo_novideo.setVisibility(View.GONE);
ToastUtil.showToastshort("音频播放初始化",VideoPublisherActivity.this);
}
// AudioPlayBean audioPlayBean = JsonUtil.parseJsonToBean(response, AudioPlayBean.class);
// if (audioPlayBean != null && audioPlayBean.getRtmpUrl() != null) {
// XdyLogUtil.e(TAG, "执行了" + audioPlayBean.getRtmpUrl());
// xdySdk.api("playAudio", audioPlayBean.getRtmpUrl(), null, VideoPublisherActivity.this, new EventHande_Video());
//// img_playVideo_novideo.setVisibility(View.GONE);
// ToastUtil.showToastshort("音频播放初始化",VideoPublisherActivity.this);
// }
}
public void getDoc(String response) {
... ... @@ -267,7 +268,7 @@ public class VideoPublisherActivity extends AppCompatActivity {
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e(TAG, "文档" + jsonParmp);
XdySdk.api("getDocImageFullPath", jsonParmp);
xdySdk.api("getDocImageFullPath", jsonParmp);
}
}
... ... @@ -278,7 +279,7 @@ public class VideoPublisherActivity extends AppCompatActivity {
"}";
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e(TAG, "聊天" + jsonParmp);
XdySdk.api("sendChatMsg", jsonParmp);
xdySdk.api("sendChatMsg", jsonParmp);
}
... ... @@ -296,14 +297,14 @@ public class VideoPublisherActivity extends AppCompatActivity {
String ids_new = "getVideoPublishPath";
String tem = "{ \"type\": \"live\"}";
String s = XdyStringUtils.stringToJson(tem, true);
XdySdk.api(ids_new, s);
xdySdk.api(ids_new, s);
}
/**
* 获取封装的推流地址
*/
public void publisherVideoText(){
XdySdk.api("publishVideo", "", surfaceview_pubisherVideo, VideoPublisherActivity.this,"");
xdySdk.api("publishVideo", "", surfaceview_pubisherVideo, VideoPublisherActivity.this);
}
... ... @@ -315,44 +316,44 @@ public class VideoPublisherActivity extends AppCompatActivity {
}
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, VideoPublisherActivity.this,new EventHande());
ToastUtil.showToastshort("推送纯音频初始化中",VideoPublisherActivity.this);
}else{
XdySdk.api("publishVideo", liveBean.getPublishUrl(), surfaceview_pubisherVideo, VideoPublisherActivity.this,new EventHande());
ToastUtil.showToastshort("推送视频初始化中",VideoPublisherActivity.this);
}
isAbleback=true;
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());
// publisherVideoReturnBean=JsonUtil.parseJsonToBean(response,PublisherVideoReturnBean.class);
}
// 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, VideoPublisherActivity.this,new EventHande());
// ToastUtil.showToastshort("推送纯音频初始化中",VideoPublisherActivity.this);
// }else{
// xdySdk.api("publishVideo", liveBean.getPublishUrl(), surfaceview_pubisherVideo, VideoPublisherActivity.this,new EventHande());
// ToastUtil.showToastshort("推送视频初始化中",VideoPublisherActivity.this);
// }
// isAbleback=true;
// 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());
//// publisherVideoReturnBean=JsonUtil.parseJsonToBean(response,PublisherVideoReturnBean.class);
// }
}
@Override
public void onBackPressed() {
//退出课堂
XdySdk.api("unPublishVideo","");
xdySdk.api("unPublishVideo","");
super.onBackPressed();
... ... @@ -362,7 +363,7 @@ public class VideoPublisherActivity extends AppCompatActivity {
@Override
protected void onDestroy() {
XdySdk.onPublisherStop();
xdySdk.onPublisherStop();
super.onDestroy();
}
... ... @@ -382,7 +383,7 @@ public class VideoPublisherActivity extends AppCompatActivity {
break;
case R.id.btn_videoPlay_stop:
ToastUtil.showToastshort("正在退出,请稍等",this);
XdySdk.api("unPublishVideo","");
xdySdk.api("unPublishVideo","");
finish();
break;
}
... ...
/*
* Copyright (c) 2015, 张涛.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mang.xdy.demo.adapter;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.mang.xdy.demo.R;
import com.mang.xdy.demo.bean.Message;
import com.mang.xdy.demo.fragment.ChatFragment;
import com.mang.xdy.demo.widget.chat.UrlUtils;
import com.mang.xdy.utils.XdyLogUtil;
import org.kymjs.kjframe.KJBitmap;
import java.util.ArrayList;
import java.util.List;
/**
* @author kymjs (http://www.kymjs.com/) on 6/8/15.
*/
public class ChatAdapter extends BaseAdapter {
private final Context cxt;
private List<Message> datas = null;
private KJBitmap kjb;
private ChatFragment.OnChatItemClickListener listener;
String oldTime;
public ChatAdapter(Context cxt, List<Message> datas, ChatFragment.OnChatItemClickListener listener) {
this.cxt = cxt;
if (datas == null) {
datas = new ArrayList<Message>(0);
}
this.datas = datas;
kjb = new KJBitmap();
this.listener = listener;
}
public void refresh(List<Message> datas) {
if (datas == null) {
datas = new ArrayList<>(0);
}
this.datas = datas;
notifyDataSetChanged();
}
@Override
public int getCount() {
return datas.size();
}
@Override
public Object getItem(int position) {
return datas.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemViewType(int position) {
return datas.get(position).getIsSend() ? 1 : 0;
}
@Override
public int getViewTypeCount() {
return 2;
}
@Override
public View getView(final int position, View v, ViewGroup parent) {
final ViewHolder holder;
final Message data = datas.get(position);
if (v == null) {
holder = new ViewHolder();
if (data.getIsSend()) {
v = View.inflate(cxt, R.layout.home_chat_item_list_right, null);
} else {
v = View.inflate(cxt, R.layout.home_chat_item_list_left, null);
}
holder.layout_content = (RelativeLayout) v.findViewById(R.id.chat_item_layout_content);
holder.img_avatar = (ImageView) v.findViewById(R.id.chat_item_avatar);
holder.img_chatimage = (ImageView) v.findViewById(R.id.chat_item_content_image);
holder.img_sendfail = (ImageView) v.findViewById(R.id.chat_item_fail);
holder.progress = (ProgressBar) v.findViewById(R.id.chat_item_progress);
holder.tv_chatcontent = (TextView) v.findViewById(R.id.chat_item_content_text);
holder.tv_date = (TextView) v.findViewById(R.id.chat_item_date);
holder.tv_name = (TextView) v.findViewById(R.id.chat_item_name);
holder.tv_teacher_bg = (TextView) v.findViewById(R.id.chat_item_taacher_bg);
v.setTag(holder);
} else {
holder = (ViewHolder) v.getTag();
}
if (data.getTime() != null) {
String dataTime = data.getTime();
holder.tv_date.setText(dataTime);
holder.tv_date.setVisibility(View.VISIBLE);
}else {
holder.tv_date.setVisibility(View.GONE);
}
//如果是文本类型,则隐藏图片,如果是图片则隐藏文本
if (data.getType() == Message.MSG_TYPE_TEXT) {
holder.img_chatimage.setVisibility(View.GONE);
holder.tv_chatcontent.setVisibility(View.VISIBLE);
if (data.getContent().contains("href")) {
holder.tv_chatcontent = UrlUtils.handleHtmlText(holder.tv_chatcontent, data
.getContent());
} else {
holder.tv_chatcontent = UrlUtils.handleText(holder.tv_chatcontent, data
.getContent());
}
} else {
holder.tv_chatcontent.setVisibility(View.GONE);
holder.img_chatimage.setVisibility(View.VISIBLE);
}
//如果是表情或图片,则不显示气泡,如果是图片则显示气泡
if (data.getType() != Message.MSG_TYPE_TEXT) {
holder.layout_content.setBackgroundResource(android.R.color.transparent);
} else {
if (data.getIsSend()) {
holder.layout_content.setBackgroundResource(R.drawable.chat_pop_send);
} else {
holder.layout_content.setBackgroundResource(R.drawable.chat_pop_receive);
}
}
//显示头像
/*if (data.getIsSend()) {
kjb.display(holder.img_avatar, data.getFromUserAvatar());
} else {
kjb.display(holder.img_avatar, data.getToUserAvatar());
}*/
if (data.getIsSend()) {
XdyLogUtil.e("chatadapter getIsSend","hahhaahahhaahhhahaahahha");
// switch (AccountUtils.getUser().getUserRole()) {
// case "normal"://普通角色/学生
// if (!TextUtils.isEmpty(data.getFromUserName())) {
// holder.tv_name.setText(data.getFromUserName());
// } else {
// holder.tv_name.setText("学生");
// }
// holder.tv_teacher_bg.setVisibility(View.GONE);
// holder.img_avatar.setImageResource(R.mipmap.student);
// break;
// case "host"://主持人/老师
// if (TextUtils.isEmpty(data.getFromUserName())) {
// data.setFromUserName("老师");
// }
// holder.img_avatar.setImageResource(R.mipmap.teacher);
// holder.tv_name.setText(data.getFromUserName());
// holder.tv_teacher_bg.setVisibility(View.VISIBLE);
// break;
// case "presenter"://主讲人
// if (!TextUtils.isEmpty(data.getFromUserName())) {
// holder.tv_name.setText(data.getFromUserName());
// } else {
// holder.tv_name.setText("主讲人");
// }
// holder.tv_teacher_bg.setVisibility(View.GONE);
// holder.img_avatar.setImageResource(R.mipmap.student);
// break;
// case "assistant"://助教
// if (!TextUtils.isEmpty(data.getFromUserName())) {
// holder.tv_name.setText(data.getFromUserName());
// } else {
// holder.tv_name.setText("助教");
// }
// holder.tv_teacher_bg.setVisibility(View.GONE);
// holder.img_avatar.setImageResource(R.mipmap.student);
// break;
// case "record":// 暂时没用
// if (!TextUtils.isEmpty(data.getFromUserName())) {
// holder.tv_name.setText(data.getFromUserName());
// } else {
// holder.tv_name.setText("学生");
// }
// holder.tv_teacher_bg.setVisibility(View.GONE);
// holder.img_avatar.setImageResource(R.mipmap.student);
// break;
// }
}
else {
switch (data.getUserRole()) {
case "normal"://普通角色/学生
if (!TextUtils.isEmpty(data.getToUserName())) {
holder.tv_name.setText(data.getToUserName());
} else {
holder.tv_name.setText("学生");
}
holder.tv_teacher_bg.setVisibility(View.GONE);
holder.img_avatar.setImageResource(R.mipmap.student);
break;
case "host"://主持人/老师
if (TextUtils.isEmpty(data.getToUserName())) {
data.setToUserName("老师");
}
holder.tv_teacher_bg.setVisibility(View.VISIBLE);
holder.img_avatar.setImageResource(R.mipmap.teacher);
holder.tv_name.setText(data.getToUserName());
break;
case "presenter"://主讲人
if (!TextUtils.isEmpty(data.getToUserName())) {
holder.tv_name.setText(data.getToUserName());
} else {
holder.tv_name.setText("主讲人");
}
holder.tv_teacher_bg.setVisibility(View.GONE);
holder.img_avatar.setImageResource(R.mipmap.student);
break;
case "assistant"://助教
if (!TextUtils.isEmpty(data.getToUserName())) {
holder.tv_name.setText(data.getToUserName());
} else {
holder.tv_name.setText("助教");
}
holder.tv_teacher_bg.setVisibility(View.GONE);
holder.img_avatar.setImageResource(R.mipmap.student);
break;
case "record":// 暂时没用
if (!TextUtils.isEmpty(data.getToUserName())) {
holder.tv_name.setText(data.getToUserName());
} else {
holder.tv_name.setText("学生");
}
holder.tv_teacher_bg.setVisibility(View.GONE);
holder.img_avatar.setImageResource(R.mipmap.student);
break;
}
}
if (listener != null) {
holder.tv_chatcontent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onTextClick(position);
}
});
holder.img_chatimage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (data.getType()) {
case Message.MSG_TYPE_PHOTO:
listener.onPhotoClick(position);
break;
case Message.MSG_TYPE_FACE:
listener.onFaceClick(position);
break;
}
}
});
}
//消息发送的状态
switch (data.getState()) {
case Message.MSG_STATE_FAIL:
holder.progress.setVisibility(View.GONE);
holder.img_sendfail.setVisibility(View.VISIBLE);
break;
case Message.MSG_STATE_SUCCESS:
holder.progress.setVisibility(View.GONE);
holder.img_sendfail.setVisibility(View.GONE);
break;
case Message.MSG_STATE_SENDING:
holder.progress.setVisibility(View.VISIBLE);
holder.img_sendfail.setVisibility(View.GONE);
break;
}
return v;
}
static class ViewHolder {
TextView tv_date;
TextView tv_name;
TextView tv_teacher_bg;
ImageView img_avatar;
TextView tv_chatcontent;
ImageView img_chatimage;
ImageView img_sendfail;
ProgressBar progress;
RelativeLayout layout_content;
}
private float sp2px(float spValue) {
final float scale = cxt.getResources().getDisplayMetrics().scaledDensity;
return spValue * scale;
}
}
... ...
... ... @@ -18,8 +18,7 @@ import java.util.List;
public class SimpleFragmentPagerAdapter extends FragmentPagerAdapter {
final int PAGE_COUNT = 1;
private String tabTitles[] = new String[]{"tab1","tab2"};
private String tabTitles[] = new String[]{"文档","聊天"};
private Context context;
private DocFragment docFragment=new DocFragment();
private ChatFragment chatFragment=new ChatFragment();
... ... @@ -33,7 +32,6 @@ public class SimpleFragmentPagerAdapter extends FragmentPagerAdapter {
@Override
public Fragment getItem(int position) {
// return PageFragment.newInstance(position + 1);
return fragmentList.get(position);
}
... ...
package com.mang.xdy.demo.base;
import java.lang.ref.WeakReference;
public abstract class BaseRunnable<T> implements Runnable {
WeakReference<T> weakReference;
public BaseRunnable() {
}
public BaseRunnable(T t) {
weakReference = new WeakReference<>(t);
}
@Override
public void run() {
T t = null;
if (weakReference != null && (t = weakReference.get()) != null) {
handle(t);
} else {
handle(null);
}
}
protected abstract void handle(T t);
}
... ...
package com.mang.xdy.demo.bean;
/**
* Created by Admin on 2017/3/25.
*/
public class ChatMsgEntity {
public String fromNodeId;
public String toNodeId;
public String message;
public String fromName;
public String fromRole;
}
... ...
package com.mang.xdy.demo.bean;
import java.util.List;
/**
* Created by huang on 2017/4/9.
*/
public class DocEntity {
/**
* itemIdx : 749428394
* owner : 747132023
* from : 747132023
* visible : true
* itemIdx : 48941765
* owner : 51346831
* from : 51346831
* curPageNo : 1
* pageNum : 1
* fileType : jpg
* creatUserId : 0
* relativeUrl : /DocSharing/data/1087553281/20170409-204600041/d32594763768243bddc64934be5088a0.jpg
* url :
* pageNum : 3
* fileType : pdf
* creatUserId : 968228008
* relativeUrl : /DocSharing/data/1299232248/example.swf
* url : http://127.0.0.1/DocSharing/data/1299232248/example.swf
* curV : 0
* curH : 0
* scale : 100
* visible : true
* action : 1
* docId : 8ab3b0ed5b4fb08d015b52bf009e0b7e
* fileName : 19462408_171130083000_2.jpg
* action : 0
* docId : 8ab3b0ed5b5f23bc015b603b965d0552
* fileName : example.jpg
* dynamicTS : 0
* md5 :
* showType : 0
* images : ["http://127.0.0.1/DocSharing/data/1299232248/1.jpg","http://127.0.0.1/DocSharing/data/1299232248/2.jpg","http://127.0.0.1/DocSharing/data/1299232248/3.jpg"]
* pdf : http://127.0.0.1/DocSharing/data/1299232248/example.pdf
* html :
*/
private boolean visible;
private int itemIdx;
private int owner;
private int from;
... ... @@ -40,13 +47,23 @@ public class DocEntity {
private int curV;
private int curH;
private int scale;
private boolean visible;
private int action;
private String docId;
private String fileName;
private String dynamicTS;
private String md5;
private int showType;
private String pdf;
private String html;
private List<String> images;
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
public int getItemIdx() {
return itemIdx;
... ... @@ -144,14 +161,6 @@ public class DocEntity {
this.scale = scale;
}
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
public int getAction() {
return action;
}
... ... @@ -199,4 +208,28 @@ public class DocEntity {
public void setShowType(int showType) {
this.showType = showType;
}
public String getPdf() {
return pdf;
}
public void setPdf(String pdf) {
this.pdf = pdf;
}
public String getHtml() {
return html;
}
public void setHtml(String html) {
this.html = html;
}
public List<String> getImages() {
return images;
}
public void setImages(List<String> images) {
this.images = images;
}
}
... ...
... ... @@ -3,7 +3,7 @@ package com.mang.xdy.demo.bean;
/**
* Created by abao on 2017/4/11.
*/
@Deprecated
public class GetDocImageEntity {
/**
... ...
/*
* Copyright (c) 2015, 张涛.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mang.xdy.demo.bean;
/**
* 聊天消息javabean
*
* @author kymjs (http://www.kymjs.com/)
*/
public class Message {
public final static int MSG_TYPE_TEXT = 3;
public final static int MSG_TYPE_PHOTO = 1;
public final static int MSG_TYPE_FACE = 2;
public final static int MSG_STATE_SENDING = 3;
public final static int MSG_STATE_SUCCESS = 1;
public final static int MSG_STATE_FAIL = 2;
private Long id;
private String userRole;
private int type; // 0-text | 1-photo | 2-face | more type ...
private int state; // 0-sending | 1-success | 2-fail
private String fromUserName;
private String fromUserAvatar;
private String toUserName;
private String toUserAvatar;
private String content;
private Boolean isSend;
private Boolean sendSucces;
private String time;
public Message(int type, int state, String userRole, String fromUserName,
String fromUserAvatar, String toUserName, String toUserAvatar,
String content, Boolean isSend, Boolean sendSucces, String time) {
super();
this.type = type;
this.state = state;
this.userRole=userRole;
this.fromUserName = fromUserName;
this.fromUserAvatar = fromUserAvatar;
this.toUserName = toUserName;
this.toUserAvatar = toUserAvatar;
this.content = content;
this.isSend = isSend;
this.sendSucces = sendSucces;
this.time = time;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
public String getFromUserName() {
return fromUserName;
}
public void setFromUserName(String fromUserName) {
this.fromUserName = fromUserName;
}
public String getFromUserAvatar() {
return fromUserAvatar;
}
public void setFromUserAvatar(String fromUserAvatar) {
this.fromUserAvatar = fromUserAvatar;
}
public String getToUserName() {
return toUserName;
}
public void setToUserName(String toUserName) {
this.toUserName = toUserName;
}
public String getToUserAvatar() {
return toUserAvatar;
}
public void setToUserAvatar(String toUserAvatar) {
this.toUserAvatar = toUserAvatar;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Boolean getIsSend() {
return isSend;
}
public void setIsSend(Boolean isSend) {
this.isSend = isSend;
}
public Boolean getSendSucces() {
return sendSucces;
}
public void setSendSucces(Boolean sendSucces) {
this.sendSucces = sendSucces;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getUserRole() {
return userRole;
}
public void setUserRole(String userRole) {
this.userRole = userRole;
}
}
... ...
package com.mang.xdy.demo.bean;
/**
* Created by abao on 2017/4/18.
*/
public class SendChatMsgEntity {
/**
* message : Hello world!
* to : 0
*/
private String message;
private int to;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public int getTo() {
return to;
}
public void setTo(int to) {
this.to = to;
}
}
... ...
... ... @@ -11,11 +11,32 @@ import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import com.google.gson.Gson;
import com.mang.xdy.common.Constants;
import com.mang.xdy.core.SPUtil;
import com.mang.xdy.core.XdySdk;
import com.mang.xdy.demo.R;
import com.mang.xdy.demo.activity.VideoPlayActivity;
import com.mang.xdy.demo.adapter.ChatAdapter;
import com.mang.xdy.demo.bean.ChatMsgEntity;
import com.mang.xdy.demo.bean.Faceicon;
import com.mang.xdy.demo.bean.JoinClassBean;
import com.mang.xdy.demo.bean.JoinClassSuccessEntity;
import com.mang.xdy.demo.bean.Message;
import com.mang.xdy.demo.bean.SendChatMsgEntity;
import com.mang.xdy.demo.utils.JsonUtil;
import com.mang.xdy.demo.widget.chat.KJChatKeyboard;
import com.mang.xdy.demo.widget.chat.OnOperationListener;
import com.mang.xdy.demo.widget.emoji.DisplayRules;
import com.mang.xdy.listener.ObserverListener;
import com.mang.xdy.utils.XdyLogUtil;
import com.mang.xdy.utils.XdyStringUtils;
import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.KJLoger;
import org.kymjs.kjframe.utils.StringUtils;
import java.io.File;
import java.math.MathContext;
... ... @@ -29,10 +50,17 @@ import butterknife.ButterKnife;
* Created by abao on 2017/4/17.
*/
public class ChatFragment extends Fragment {
public class ChatFragment extends Fragment implements ObserverListener{
@BindView(R.id.chat_msg_input_box)
KJChatKeyboard box;
@BindView(R.id.chat_listview)
ListView mListView;
private Context mContext;
private String TAG=this.getClass().getSimpleName();
private boolean replay=false;
private ChatAdapter adapter;
List<Message> datas = new ArrayList<Message>();
private XdySdk xdySdk;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
... ... @@ -45,7 +73,10 @@ public class ChatFragment extends Fragment {
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mContext=this.getContext();
xdySdk=XdySdk.getXdyInstance();
xdySdk.add(this);
init();
initData();
}
public void init(){
... ... @@ -56,6 +87,7 @@ public class ChatFragment extends Fragment {
if (!TextUtils.isEmpty(content)) {
// LogUtil.i("聊天内容===" + content);
// mPresenter.sendChatMsg(content, 0);
sendMeg(content);
}
}
... ... @@ -88,7 +120,7 @@ public class ChatFragment extends Fragment {
@Override
public void selectedBackSpace(String back) {
// DisplayRules.backspace(box.getEditTextBox());
DisplayRules.backspace(box.getEditTextBox());
}
@Override
... ... @@ -116,11 +148,96 @@ public class ChatFragment extends Fragment {
}
box.setFaceData(faceCagegory);
// mRealListView.setOnTouchListener(getOnTouchListener());
mListView.setOnTouchListener(getOnTouchListener());
}
protected void initData() {
adapter = new ChatAdapter(mContext, datas, getOnChatItemClickListener());
mListView.setAdapter(adapter);
}
/**
* @return 聊天列表内存点击事件监听器
*/
private OnChatItemClickListener getOnChatItemClickListener() {
return new OnChatItemClickListener() {
@Override
public void onPhotoClick(int position) {
KJLoger.debug(datas.get(position).getContent() + "点击图片的");
ViewInject.toast(mContext, datas.get(position).getContent() + "点击图片的");
}
@Override
public void onTextClick(int position) {
}
@Override
public void onFaceClick(int position) {
}
};
}
private String oldTime;
private String time;
public void renderChatMsg(String response) {
ChatMsgEntity entity= JsonUtil.parseJsonToBean(response,ChatMsgEntity.class);
JoinClassSuccessEntity joinClassSuccessEntity=JsonUtil.parseJsonToBean(SPUtil.getString(mContext,Constants.CLASS_JOIN_SUCCESS,""),JoinClassSuccessEntity.class);
String nodeId="";
if(joinClassSuccessEntity!=null) {
nodeId = joinClassSuccessEntity.getNodeId() + "";
}
if (entity != null && adapter != null) {
Message message;
String dataTime = StringUtils.getDataTime("HH:mm");
if (entity.fromNodeId.equals(nodeId)) {
if (TextUtils.isEmpty(oldTime)) {
time = oldTime = dataTime;
} else if (dataTime.equals(oldTime)) {
time = null;
} else {
time = oldTime = dataTime;
}
message = new Message(Message.MSG_TYPE_TEXT, Message.MSG_STATE_SUCCESS, entity.fromRole,
entity.fromName, "", "",
"", entity.message, true, true, replay ? null : time);
datas.add(message);
adapter.refresh(datas);
mListView.setSelection(adapter.getCount() - 1);
} else {
XdyLogUtil.e("返回的聊天内容===" + entity.message);
if (TextUtils.isEmpty(oldTime)) {
time = oldTime = dataTime;
} else if (dataTime.equals(oldTime)) {
time = null;
} else {
time = oldTime = dataTime;
}
message = new Message(Message.MSG_TYPE_TEXT, Message.MSG_STATE_SUCCESS, entity.fromRole, "",
"", entity.fromName, "", entity.message, false,
true, replay ? null : time);
datas.add(message);
adapter.refresh(datas);
mListView.setSelection(adapter.getCount() - 1);
}
}
}
/**
* 发送聊天消息
* @param chatmsg
*/
public void sendMeg(String chatmsg) {
SendChatMsgEntity sendChatMsgEntity=new SendChatMsgEntity();
sendChatMsgEntity.setMessage(chatmsg);
sendChatMsgEntity.setTo(0);
String jsonParmp=new Gson().toJson(sendChatMsgEntity);
XdyLogUtil.e(TAG, "聊天" + jsonParmp);
xdySdk.api("sendChatMsg", jsonParmp);
}
/**
* 若软键盘或表情键盘弹起,点击上端空白处应该隐藏输入法键盘
*
* @return 会隐藏输入法键盘的触摸事件监听器
... ... @@ -135,4 +252,25 @@ public class ChatFragment extends Fragment {
}
};
}
@Override
public void observerUpData(String type, String parameter) {
switch (type) {
case Constants.CHAT_RECEIVE_MESSAGE:
renderChatMsg(parameter);
break;
}
}
/**
* 聊天列表中对内容的点击事件监听
*/
public interface OnChatItemClickListener {
void onPhotoClick(int position);
void onTextClick(int position);
void onFaceClick(int position);
}
}
... ...
... ... @@ -8,6 +8,7 @@ import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
... ... @@ -18,11 +19,14 @@ import com.mang.xdy.common.Constants;
import com.mang.xdy.core.XdySdk;
import com.mang.xdy.demo.R;
import com.mang.xdy.demo.activity.VideoPlayActivity;
import com.mang.xdy.demo.base.BaseRunnable;
import com.mang.xdy.demo.bean.DocEntity;
import com.mang.xdy.demo.bean.GetDocImageEntity;
import com.mang.xdy.demo.bean.WhiteboardUpdateEntity;
import com.mang.xdy.demo.utils.JsonUtil;
import com.mang.xdy.demo.utils.ToastUtil;
import com.mang.xdy.demo.widget.CanvasView;
import com.mang.xdy.listener.ObserverListener;
import com.mang.xdy.utils.XdyLogUtil;
import com.mang.xdy.utils.XdyStringUtils;
import com.squareup.picasso.Picasso;
... ... @@ -36,26 +40,32 @@ import butterknife.ButterKnife;
* Created by abao on 2017/4/14.
*/
public class DocFragment extends Fragment implements VideoPlayActivity.OnAcceptFromCoreToFragmentListener{
public class DocFragment extends Fragment implements ObserverListener{
private static String TAG="DocFragment";
@BindView(R.id.canvas_doc_show)
CanvasView mCanvasView;
private Bitmap bitmap;
private Context mContext;
private String whritebroad="";
private XdySdk xdySdk;
int winWidth;
int winHeight;
private long intervalTime;
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
xdySdk=XdySdk.getXdyInstance();
xdySdk.add(this);
init();
mContext=this.getContext();
}
private static Handler mHandler=new Handler(){
private Handler mHandler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
ToastUtil.showToastshort("图片加载失败",mContext);
}
};
... ... @@ -67,36 +77,40 @@ public class DocFragment extends Fragment implements VideoPlayActivity.OnAcceptF
return view;
}
public void init(){
VideoPlayActivity videoPlayActivity= (VideoPlayActivity) this.getActivity();
DisplayMetrics metric = new DisplayMetrics();
getWindowWith(metric);
mCanvasView.setBitmap(getEmptyBitmap(),false);
videoPlayActivity.setmOnAcceptFromCoreToFragmentListener(this);
}
private void getWindowWith(DisplayMetrics metric) {
this.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metric);
winWidth = metric.widthPixels; // 屏幕宽度(像素)
winHeight = metric.heightPixels; // 屏幕高度(像素)
XdyLogUtil.e(TAG,"获取屏幕的宽:"+winWidth+":"+mCanvasView.getWidth()+" 获取屏幕的高:"+winHeight);
}
/**
* 获取文档
* @param response
*/
public void getDoc(String response) {
DocEntity docEntity = JsonUtil.parseJsonToBean(response, DocEntity.class);
if (docEntity != null && docEntity.getRelativeUrl() != null) {
String url = docEntity.getRelativeUrl();
GetDocImageEntity getDocImageEntity=new GetDocImageEntity();
getDocImageEntity.setPageNum(1);
// getDocImageEntity.setRelativeUrl("/DocSharing/data/1087553281/20170409-204600041/d32594763768243bddc64934be5088a0.swf");
getDocImageEntity.setRelativeUrl(url);
getDocImageEntity.setType("jpg");
String jsonParmp = new Gson().toJson(getDocImageEntity);
XdyLogUtil.e(TAG, "文档" + jsonParmp);
XdySdk.api("getDocImageFullPath", jsonParmp);
if (docEntity != null && docEntity.getImages()!= null&&docEntity.getImages().size()>=1) {
//默认显示第一张
setDocImage(docEntity.getImages().get(0));
}else{
mHandler.sendEmptyMessage(0);
}
}
public void setDocImage(String resonse){
if(resonse.length()>10){
String temp= XdyStringUtils.stringToJson(resonse);
String url=temp.substring(2,temp.length()-2);
XdyLogUtil.e(TAG,"截取后的"+url);
/**
* 设置图片
* @param url
*/
public void setDocImage(String url){
getBitmap(url);
}
}
public void getBitmap(final String url){
... ... @@ -105,12 +119,13 @@ public class DocFragment extends Fragment implements VideoPlayActivity.OnAcceptF
public void run() {
super.run();
try {
bitmap= Glide.with(mContext).load(url).asBitmap().into(480,480).get();
bitmap= Glide.with(mContext).load(url).asBitmap().centerCrop() .into(winWidth,winWidth).get();
if(bitmap!=null) {
mHandler.post(new Runnable() {
@Override
public void run() {
mCanvasView.setBitmap(bitmap,false);
mCanvasView.setZOrderMediaOverlay(true);
mCanvasView.setBitmap(bitmap,true);
}
});
... ... @@ -129,30 +144,41 @@ public class DocFragment extends Fragment implements VideoPlayActivity.OnAcceptF
* @param response
*/
public void showDoc(String type,String response){
mCanvasView.setZOrderMediaOverlay(true);
if(bitmap!=null) {
mCanvasView.setBitmap(bitmap,false);
}
// else{
// mCanvasView.setBitmap(getEmptyBitmap(),false);
// }
WhiteboardUpdateEntity whiteboardUpdateEntity= JsonUtil.parseJsonToBean(response,WhiteboardUpdateEntity.class);
if(whiteboardUpdateEntity!=null){
drawline(whiteboardUpdateEntity);
mCanvasView.setZOrderMediaOverlay(true);
// if(bitmap!=null) {
// mCanvasView.setBitmap(bitmap,!whiteboardUpdateEntity.isFresh);
// }
if (intervalTime != 0) {
intervalTime = System.currentTimeMillis() - intervalTime;
if (intervalTime < 150) {//小于100毫秒 不执行?
mHandler.removeCallbacksAndMessages(null);
}
delayDraw(whiteboardUpdateEntity);
} else {
delayDraw(whiteboardUpdateEntity);
}
intervalTime = System.currentTimeMillis();
}
}
private void delayDraw(final WhiteboardUpdateEntity entity) {
mHandler.postDelayed(new BaseRunnable<WhiteboardUpdateEntity>() {
@Override
protected void handle(WhiteboardUpdateEntity o) {
drawline(entity);
}
}, 200);
}
public Bitmap getEmptyBitmap(){
Bitmap bitmap_empty= BitmapFactory.decodeResource(getResources(),R.mipmap.no_doc);
return bitmap_empty;
}
private void drawline(WhiteboardUpdateEntity o) {
if (o != null) {
if (o.isFresh) {
... ... @@ -169,19 +195,18 @@ public class DocFragment extends Fragment implements VideoPlayActivity.OnAcceptF
}
}
@Override
public void onAcceptInfo(String type, String response) {
XdyLogUtil.e(TAG,"type:"+type+" response:"+response);
public void observerUpData(String type, String parameter) {
XdyLogUtil.e(TAG,"type:"+type+" response:"+parameter);
switch (type){
case Constants.DOCUMENT_UPDATE:
getDoc(response);
break;
case "getDocImageFullPath":
setDocImage(response);
getDoc(parameter);
break;
// case "getDocImageFullPath":
// setDocImage(parameter);
// break;
case Constants.WHITEBOARD_ANNOTATION_UPDATE:
showDoc(type,response);
showDoc(type,parameter);
break;
case Constants.DOCUMENT_DELETE:
bitmap=null;
... ... @@ -190,4 +215,9 @@ public class DocFragment extends Fragment implements VideoPlayActivity.OnAcceptF
}
}
@Override
public void onDestroyView() {
super.onDestroyView();
mHandler.removeCallbacksAndMessages(null);
}
}
... ...
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mang.xdy.demo.utils.cache;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
public class ACache implements ICache {
public static final int TIME_HOUR = 60 * 60;
public static final int TIME_DAY = TIME_HOUR * 24;
private static final int MAX_SIZE = 1000 * 1000 * 50; // 50 mb
private static final int MAX_COUNT = Integer.MAX_VALUE; // 不限制存放数据的数量
private static Map<String, ICache> mInstanceMap = new HashMap<String, ICache>();
private ACacheManager mCache;
public static ICache get(Context ctx) {
return get(ctx, "ACache");
}
public static ICache get(Context ctx, String cacheName) {
File f = new File(ctx.getCacheDir(), cacheName);
return get(f, MAX_SIZE, MAX_COUNT);
}
public static ICache get(File cacheDir) {
return get(cacheDir, MAX_SIZE, MAX_COUNT);
}
public static ICache get(Context ctx, long max_zise, int max_count) {
File f = new File(ctx.getCacheDir(), "ACache");
return get(f, max_zise, max_count);
}
public static ICache get(File cacheDir, long max_zise, int max_count) {
ICache manager = mInstanceMap.get(cacheDir.getAbsoluteFile() + myPid());
if (manager == null) {
manager = new ACache(cacheDir, max_zise, max_count);
mInstanceMap.put(cacheDir.getAbsolutePath() + myPid(), manager);
}
return manager;
}
private static String myPid() {
return "_" + android.os.Process.myPid();
}
private ACache(File cacheDir, long max_size, int max_count) {
if (!cacheDir.exists() && !cacheDir.mkdirs()) {
throw new RuntimeException("can't make dirs in "
+ cacheDir.getAbsolutePath());
}
mCache = new ACacheManager(cacheDir, max_size, max_count);
}
/**
* Provides a means to save a cached file before the data are available.
* Since writing about the file is complete, and its close method is called,
* its contents will be registered in the cache. Example of use:
* <p/>
* ACache cache = new ACache(this) try { OutputStream stream =
* cache.put("myFileName") stream.write("some bytes".getBytes()); // now
* update cache! stream.close(); } catch(FileNotFoundException e){
* e.printStackTrace() }
*/
class xFileOutputStream extends FileOutputStream {
File file;
public xFileOutputStream(File file) throws FileNotFoundException {
super(file);
this.file = file;
}
public void close() throws IOException {
super.close();
mCache.put(file);
}
}
// =======================================
// ============ String数据 读写 ==============
// =======================================
/**
* 保存 String数据 到 缓存中
*
* @param key 保存的key
* @param value 保存的String数据
*/
@Override
public void put(String key, String value) {
if (TextUtils.isEmpty(value))//不允许有空值出现
return;
File file = mCache.newFile(key);
BufferedWriter out = null;
try {
if(!file.exists()){
file.createNewFile();
}
out = new BufferedWriter(new FileWriter(file), 1024);
out.write(value);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
mCache.put(file);
}
}
/**
* 保存 String数据 到 缓存中
*
* @param key 保存的key
* @param value 保存的String数据
* @param saveTime 保存的时间,单位:秒
*/
@Override
public void put(String key, String value, int saveTime) {
put(key, Utils.newStringWithDateInfo(saveTime, value));
}
/**
* 读取 String数据
*
* @param key
* @return String 数据
*/
@Override
public String getAsString(String key) {
File file = mCache.get(key);
if (!file.exists())
return null;
boolean removeFile = false;
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(file));
String readString = "";
String currentLine;
while ((currentLine = in.readLine()) != null) {
readString += currentLine;
}
if (!Utils.isDue(readString)) {
return Utils.clearDateInfo(readString);
} else {
removeFile = true;
return null;
}
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (removeFile)
remove(key);
}
}
// =======================================
// ============= JSONObject 数据 读写 ==============
// =======================================
/**
* 保存 JSONObject数据 到 缓存中
*
* @param key 保存的key
* @param value 保存的JSON数据
*/
@Override
public void put(String key, JSONObject value) {
put(key, value.toString());
}
/**
* 保存 JSONObject数据 到 缓存中
*
* @param key 保存的key
* @param value 保存的JSONObject数据
* @param saveTime 保存的时间,单位:秒
*/
@Override
public void put(String key, JSONObject value, int saveTime) {
put(key, value.toString(), saveTime);
}
/**
* 读取JSONObject数据
*
* @param key
* @return JSONObject数据
*/
@Override
public JSONObject getAsJSONObject(String key) {
String JSONString = getAsString(key);
try {
JSONObject obj = new JSONObject(JSONString);
return obj;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
// =======================================
// ============ JSONArray 数据 读写 =============
// =======================================
/**
* 保存 JSONArray数据 到 缓存中
*
* @param key 保存的key
* @param value 保存的JSONArray数据
*/
@Override
public void put(String key, JSONArray value) {
put(key, value.toString());
}
/**
* 保存 JSONArray数据 到 缓存中
*
* @param key 保存的key
* @param value 保存的JSONArray数据
* @param saveTime 保存的时间,单位:秒
*/
@Override
public void put(String key, JSONArray value, int saveTime) {
put(key, value.toString(), saveTime);
}
/**
* 读取JSONArray数据
*
* @param key
* @return JSONArray数据
*/
@Override
public JSONArray getAsJSONArray(String key) {
String JSONString = getAsString(key);
try {
JSONArray obj = new JSONArray(JSONString);
return obj;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
// =======================================
// ============== byte 数据 读写 =============
// =======================================
/**
* 保存 byte数据 到 缓存中
*
* @param key 保存的key
* @param value 保存的数据
*/
@Override
public void put(String key, byte[] value) {
File file = mCache.newFile(key);
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
out.write(value);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
mCache.put(file);
}
}
/**
* Cache for a stream
*
* @param key the file name.
* @return OutputStream stream for writing data.
* @throws FileNotFoundException if the file can not be created.
*/
@Override
public OutputStream put(String key) throws FileNotFoundException {
return new xFileOutputStream(mCache.newFile(key));
}
/**
* @param key the file name.
* @return (InputStream or null) stream previously saved in cache.
* @throws FileNotFoundException if the file can not be opened
*/
@Override
public InputStream get(String key) throws FileNotFoundException {
File file = mCache.get(key);
if (!file.exists())
return null;
return new FileInputStream(file);
}
/**
* 保存 byte数据 到 缓存中
*
* @param key 保存的key
* @param value 保存的数据
* @param saveTime 保存的时间,单位:秒
*/
@Override
public void put(String key, byte[] value, int saveTime) {
put(key, Utils.newByteArrayWithDateInfo(saveTime, value));
}
/**
* 获取 byte 数据
*
* @param key
* @return byte 数据
*/
@Override
public byte[] getAsBinary(String key) {
RandomAccessFile RAFile = null;
boolean removeFile = false;
try {
File file = mCache.get(key);
if (!file.exists())
return null;
RAFile = new RandomAccessFile(file, "r");
byte[] byteArray = new byte[(int) RAFile.length()];
RAFile.read(byteArray);
if (!Utils.isDue(byteArray)) {
return Utils.clearDateInfo(byteArray);
} else {
removeFile = true;
return null;
}
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if (RAFile != null) {
try {
RAFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (removeFile)
remove(key);
}
}
// =======================================
// ============= 序列化 数据 读写 ===============
// =======================================
/**
* 保存 Serializable数据 到 缓存中
*
* @param key 保存的key
* @param value 保存的value
*/
@Override
public void put(String key, Serializable value) {
put(key, value, -1);
}
/**
* 保存 Serializable数据到 缓存中
*
* @param key 保存的key
* @param value 保存的value
* @param saveTime 保存的时间,单位:秒
*/
@Override
public void put(String key, Serializable value, int saveTime) {
ByteArrayOutputStream baos = null;
ObjectOutputStream oos = null;
try {
baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
oos.writeObject(value);
byte[] data = baos.toByteArray();
if (saveTime != -1) {
put(key, data, saveTime);
} else {
put(key, data);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
oos.close();
} catch (IOException e) {
}
}
}
/**
* 读取 Serializable数据
*
* @param key
* @return Serializable 数据
*/
@Override
public Object getAsObject(String key) {
byte[] data = getAsBinary(key);
if (data != null) {
ByteArrayInputStream bais = null;
ObjectInputStream ois = null;
try {
bais = new ByteArrayInputStream(data);
ois = new ObjectInputStream(bais);
Object reObject = ois.readObject();
return reObject;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
try {
if (bais != null)
bais.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
if (ois != null)
ois.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
// =======================================
// ============== bitmap 数据 读写 =============
// =======================================
/**
* 保存 bitmap 到 缓存中
*
* @param key 保存的key
* @param value 保存的bitmap数据
*/
@Override
public void put(String key, Bitmap value) {
put(key, Utils.Bitmap2Bytes(value));
}
/**
* 保存 bitmap 到 缓存中
*
* @param key 保存的key
* @param value 保存的 bitmap 数据
* @param saveTime 保存的时间,单位:秒
*/
@Override
public void put(String key, Bitmap value, int saveTime) {
put(key, Utils.Bitmap2Bytes(value), saveTime);
}
/**
* 读取 bitmap 数据
*
* @param key
* @return bitmap 数据
*/
@Override
public Bitmap getAsBitmap(String key) {
if (getAsBinary(key) == null) {
return null;
}
return Utils.Bytes2Bimap(getAsBinary(key));
}
// =======================================
// ============= drawable 数据 读写 =============
// =======================================
/**
* 保存 drawable 到 缓存中
*
* @param key 保存的key
* @param value 保存的drawable数据
*/
@Override
public void put(String key, Drawable value) {
put(key, Utils.drawable2Bitmap(value));
}
/**
* 保存 drawable 到 缓存中
*
* @param key 保存的key
* @param value 保存的 drawable 数据
* @param saveTime 保存的时间,单位:秒
*/
@Override
public void put(String key, Drawable value, int saveTime) {
put(key, Utils.drawable2Bitmap(value), saveTime);
}
/**
* 读取 Drawable 数据
*
* @param key
* @return Drawable 数据
*/
@Override
public Drawable getAsDrawable(String key) {
if (getAsBinary(key) == null) {
return null;
}
return Utils.bitmap2Drawable(Utils.Bytes2Bimap(getAsBinary(key)));
}
/**
* 获取缓存文件
*
* @param key
* @return value 缓存的文件
*/
@Override
public File file(String key) {
File f = mCache.newFile(key);
if (f.exists())
return f;
return null;
}
/**
* 移除某个key
*
* @param key
* @return 是否移除成功
*/
@Override
public boolean remove(String key) {
return mCache.remove(key);
}
/**
* 清除所有数据
*/
@Override
public void clear() {
mCache.clear();
}
/**
* @author 杨福海(michael) www.yangfuhai.com
* @version 1.0
* @title 缓存管理器
*/
public class ACacheManager {
private final AtomicLong cacheSize;
private final AtomicInteger cacheCount;
private final long sizeLimit;
private final int countLimit;
private final Map<File, Long> lastUsageDates = Collections
.synchronizedMap(new HashMap<File, Long>());
protected File cacheDir;
private ACacheManager(File cacheDir, long sizeLimit, int countLimit) {
this.cacheDir = cacheDir;
this.sizeLimit = sizeLimit;
this.countLimit = countLimit;
cacheSize = new AtomicLong();
cacheCount = new AtomicInteger();
calculateCacheSizeAndCacheCount();
}
/**
* 计算 cacheSize和cacheCount
*/
private void calculateCacheSizeAndCacheCount() {
new Thread(new Runnable() {
@Override
public void run() {
int size = 0;
int count = 0;
File[] cachedFiles = cacheDir.listFiles();
if (cachedFiles != null) {
for (File cachedFile : cachedFiles) {
size += calculateSize(cachedFile);
count += 1;
lastUsageDates.put(cachedFile,
cachedFile.lastModified());
}
cacheSize.set(size);
cacheCount.set(count);
}
}
}).start();
}
private void put(File file) {
int curCacheCount = cacheCount.get();
while (curCacheCount + 1 > countLimit) {
long freedSize = removeNext();
cacheSize.addAndGet(-freedSize);
curCacheCount = cacheCount.addAndGet(-1);
}
cacheCount.addAndGet(1);
long valueSize = calculateSize(file);
long curCacheSize = cacheSize.get();
while (curCacheSize + valueSize > sizeLimit) {
long freedSize = removeNext();
curCacheSize = cacheSize.addAndGet(-freedSize);
}
cacheSize.addAndGet(valueSize);
Long currentTime = System.currentTimeMillis();
file.setLastModified(currentTime);
lastUsageDates.put(file, currentTime);
}
private File get(String key) {
File file = newFile(key);
Long currentTime = System.currentTimeMillis();
file.setLastModified(currentTime);
lastUsageDates.put(file, currentTime);
return file;
}
private File newFile(String key) {
if(!cacheDir.exists())cacheDir.mkdirs();
return new File(cacheDir, key.hashCode() + "");
}
private boolean remove(String key) {
File image = get(key);
return image.delete();
}
private void clear() {
lastUsageDates.clear();
cacheSize.set(0);
File[] files = cacheDir.listFiles();
if (files != null) {
for (File f : files) {
f.delete();
}
}
}
/**
* 移除旧的文件
*
* @return
*/
private long removeNext() {
if (lastUsageDates.isEmpty()) {
return 0;
}
Long oldestUsage = null;
File mostLongUsedFile = null;
Set<Entry<File, Long>> entries = lastUsageDates.entrySet();
synchronized (lastUsageDates) {
for (Entry<File, Long> entry : entries) {
if (mostLongUsedFile == null) {
mostLongUsedFile = entry.getKey();
oldestUsage = entry.getValue();
} else {
Long lastValueUsage = entry.getValue();
if (lastValueUsage < oldestUsage) {
oldestUsage = lastValueUsage;
mostLongUsedFile = entry.getKey();
}
}
}
}
long fileSize = calculateSize(mostLongUsedFile);
if (mostLongUsedFile.delete()) {
lastUsageDates.remove(mostLongUsedFile);
}
return fileSize;
}
private long calculateSize(File file) {
return file.length();
}
}
/**
* @author 杨福海(michael) www.yangfuhai.com
* @version 1.0
* @title 时间计算工具类
*/
private static class Utils {
/**
* 判断缓存的String数据是否到期
*
* @param str
* @return true:到期了 false:还没有到期
*/
private static boolean isDue(String str) {
return isDue(str.getBytes());
}
/**
* 判断缓存的byte数据是否到期
*
* @param data
* @return true:到期了 false:还没有到期
*/
private static boolean isDue(byte[] data) {
String[] strs = getDateInfoFromDate(data);
if (strs != null && strs.length == 2) {
String saveTimeStr = strs[0];
while (saveTimeStr.startsWith("0")) {
saveTimeStr = saveTimeStr
.substring(1, saveTimeStr.length());
}
long saveTime = Long.valueOf(saveTimeStr);
long deleteAfter = Long.valueOf(strs[1]);
if (System.currentTimeMillis() > saveTime + deleteAfter * 1000) {
return true;
}
}
return false;
}
private static String newStringWithDateInfo(int second, String strInfo) {
return createDateInfo(second) + strInfo;
}
private static byte[] newByteArrayWithDateInfo(int second, byte[] data2) {
byte[] data1 = createDateInfo(second).getBytes();
byte[] retdata = new byte[data1.length + data2.length];
System.arraycopy(data1, 0, retdata, 0, data1.length);
System.arraycopy(data2, 0, retdata, data1.length, data2.length);
return retdata;
}
private static String clearDateInfo(String strInfo) {
if (strInfo != null && hasDateInfo(strInfo.getBytes())) {
strInfo = strInfo.substring(strInfo.indexOf(mSeparator) + 1,
strInfo.length());
}
return strInfo;
}
private static byte[] clearDateInfo(byte[] data) {
if (hasDateInfo(data)) {
return copyOfRange(data, indexOf(data, mSeparator) + 1,
data.length);
}
return data;
}
private static boolean hasDateInfo(byte[] data) {
return data != null && data.length > 15 && data[13] == '-'
&& indexOf(data, mSeparator) > 14;
}
private static String[] getDateInfoFromDate(byte[] data) {
if (hasDateInfo(data)) {
String saveDate = new String(copyOfRange(data, 0, 13));
String deleteAfter = new String(copyOfRange(data, 14,
indexOf(data, mSeparator)));
return new String[]{saveDate, deleteAfter};
}
return null;
}
private static int indexOf(byte[] data, char c) {
for (int i = 0; i < data.length; i++) {
if (data[i] == c) {
return i;
}
}
return -1;
}
private static byte[] copyOfRange(byte[] original, int from, int to) {
int newLength = to - from;
if (newLength < 0)
throw new IllegalArgumentException(from + " > " + to);
byte[] copy = new byte[newLength];
System.arraycopy(original, from, copy, 0,
Math.min(original.length - from, newLength));
return copy;
}
private static final char mSeparator = ' ';
private static String createDateInfo(int second) {
String currentTime = System.currentTimeMillis() + "";
while (currentTime.length() < 13) {
currentTime = "0" + currentTime;
}
return currentTime + "-" + second + mSeparator;
}
/*
* Bitmap → byte[]
*/
private static byte[] Bitmap2Bytes(Bitmap bm) {
if (bm == null) {
return null;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}
/*
* byte[] → Bitmap
*/
private static Bitmap Bytes2Bimap(byte[] b) {
if (b.length == 0) {
return null;
}
return BitmapFactory.decodeByteArray(b, 0, b.length);
}
/*
* Drawable → Bitmap
*/
private static Bitmap drawable2Bitmap(Drawable drawable) {
if (drawable == null) {
return null;
}
// 取 drawable 的长宽
int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
// 取 drawable 的颜色格式
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565;
// 建立对应 bitmap
Bitmap bitmap = Bitmap.createBitmap(w, h, config);
// 建立对应 bitmap 的画布
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, w, h);
// 把 drawable 内容画到画布中
drawable.draw(canvas);
return bitmap;
}
/*
* Bitmap → Drawable
*/
@SuppressWarnings("deprecation")
private static Drawable bitmap2Drawable(Bitmap bm) {
if (bm == null) {
return null;
}
BitmapDrawable bd = new BitmapDrawable(bm);
bd.setTargetDensity(bm.getDensity());
return new BitmapDrawable(bm);
}
}
}
... ...
package com.mang.xdy.demo.utils.cache;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
public interface ICache {
void put(String key, String value);
void put(String key, String value, int saveTime);
String getAsString(String key);
void put(String key, JSONObject value);
void put(String key, JSONObject value, int saveTime);
JSONObject getAsJSONObject(String key);
void put(String key, JSONArray value);
void put(String key, JSONArray value, int saveTime);
JSONArray getAsJSONArray(String key);
void put(String key, byte[] value);
OutputStream put(String key) throws FileNotFoundException;
InputStream get(String key) throws FileNotFoundException;
void put(String key, byte[] value, int saveTime);
byte[] getAsBinary(String key);
void put(String key, Serializable value);
void put(String key, Serializable value, int saveTime);
Object getAsObject(String key);
void put(String key, Bitmap value);
void put(String key, Bitmap value, int saveTime);
Bitmap getAsBitmap(String key);
void put(String key, Drawable value);
void put(String key, Drawable value, int saveTime);
Drawable getAsDrawable(String key);
File file(String key);
boolean remove(String key);
void clear();
}
... ...
... ... @@ -8,26 +8,18 @@
tools:context="com.mang.xdy.demo.activity.VideoPlayActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="300dp">
android:layout_height="220dp">
<SurfaceView
android:id="@+id/surfaceview_playVideo"
android:layout_width="match_parent"
android:layout_height="10dp" />
android:layout_height="match_parent" />
<ImageView
android:id="@+id/img_playVideo_novideo"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_height="match_parent"
android:background="@mipmap/novideo"
/>
</RelativeLayout>
<SurfaceView
android:id="@+id/surfaceview_pubisherVideo"
android:layout_width="120dp"
android:layout_height="120dp"
android:visibility="gone"
/>
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
... ... @@ -40,47 +32,4 @@
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/white" />
<ImageView
android:id="@+id/img_playVideo_docShow"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="100dp" />
<com.mang.xdy.demo.widget.CanvasView
android:id="@+id/canvas_playVideo_showWhiteBroad"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="10dp" />
<TextView
android:id="@+id/tv_videoPlay_url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn_videoPlay_chat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="发送hello"
android:visibility="gone"
/>
<Button
android:id="@+id/btn_videoPlay_pubsherVideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:text="获取推流地址"
/>
</LinearLayout>
<Button
android:id="@+id/bt_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="停止视频"
android:visibility="gone"
android:clickable="false"
/>
</LinearLayout>
... ...
... ... @@ -6,9 +6,11 @@ package com.mang.xdy.bean;
public class AudioPlayBean {
/**
* mediaId : 983041
* fromNodeId : 253252
* userRole : host
* seek : 0
* rtmpUrl : rtmp://127.0.0.1:6000/live/h5dev_403074980_0_983041_1488258462
* m3u8Url : http://127.0.0.1:6001/live/h5dev_403074980_0_983041_1488258462/index.m3u8
... ... @@ -17,6 +19,7 @@ public class AudioPlayBean {
private int mediaId;
private int fromNodeId;
private String userRole;
private int seek;
private String rtmpUrl;
private String m3u8Url;
... ... @@ -38,6 +41,14 @@ public class AudioPlayBean {
this.fromNodeId = fromNodeId;
}
public String getUserRole() {
return userRole;
}
public void setUserRole(String userRole) {
this.userRole = userRole;
}
public int getSeek() {
return seek;
}
... ...
... ... @@ -96,6 +96,8 @@ public class XdyJsCore {
if(mOnXdyAsyncMessageListener !=null){
mOnXdyAsyncMessageListener.getSdyAsyncMessageListener(id,parmp);
}
//TODo 使用观察者传递数
XdySdk.getXdyInstance().notifyObserver(id,parmp);
}
}
... ...
... ... @@ -17,9 +17,7 @@ import com.mang.xdy.utils.XdyLogUtil;
*/
public class XdyPlayerCore {
private SurfaceView mSurfaceView = null;
private long playerHandle = 0;
private static final int PORTRAIT = 1; //竖屏
private static final int LANDSCAPE = 2; //横屏
private static final String TAG = "XdyPlayer";
... ... @@ -32,15 +30,14 @@ public class XdyPlayerCore {
static {
System.loadLibrary("SmartPlayer");
}
protected XdyPlayerCore(String rtmpUrl,SurfaceView mSurfaceView, Context mContext) {
this.mSurfaceView = mSurfaceView;
protected XdyPlayerCore(String rtmpUrl, Context mContext) {
this.mContext=mContext;
}
protected static XdyPlayerCore getXdyPlayerCore(String rtmpUrl,SurfaceView mSurfaceView, Context mContext){
protected static XdyPlayerCore getXdyPlayerCore(String rtmpUrl, Context mContext){
if(mXdyPlayerCore==null){
synchronized (XdyPlayerCore.class){
if(mXdyPlayerCore==null){
mXdyPlayerCore=new XdyPlayerCore(rtmpUrl, mSurfaceView, mContext);
mXdyPlayerCore=new XdyPlayerCore(rtmpUrl, mContext);
}
}
}
... ... @@ -61,9 +58,9 @@ public class XdyPlayerCore {
libPlayer = new SmartPlayerJni();
}
//TODO
// if(playerHandle==0) {
if(playerHandle==0) {
playerHandle = libPlayer.SmartPlayerInit(mContext);
// }
}
XdyLogUtil.e(TAG, "playVideoId" + playerHandle);
if (playerHandle == 0) {
XdyLogUtil.e(TAG, "视频初始化失败 ");
... ...
... ... @@ -15,12 +15,17 @@ import com.mang.xdy.bean.PublisherVideoReturnBean;
import com.mang.xdy.bean.VideoPlayBean;
import com.mang.xdy.cache.ACache;
import com.mang.xdy.common.Constants;
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.PlayerUtils;
import com.mang.xdy.utils.XdyLogUtil;
import com.mang.xdy.utils.XdyStringUtils;
import java.util.ArrayList;
import java.util.List;
import static com.mang.xdy.utils.PlayerUtils.getPublishPathAudio;
import static com.mang.xdy.utils.PlayerUtils.getPublishPathVideo;
... ... @@ -30,15 +35,15 @@ import static com.mang.xdy.utils.PlayerUtils.getPublishPathVideo;
* 受原先的文档设计的规则,所有方法的都是静态的方法,影响性能
* 考虑跟换文档,提升性能
*/
public class XdySdk {
public class XdySdk implements SubjectListener{
/**
* 用户初始化,还是调用各种方法,都需要统一的对外给出监听事件
*/
private static XdyJsCore mXdyJsCore;
private static XdyJsCore mXdyJsCore;
private static XdySdk mXdySdk;
private static Context mContext;
private static XdyPlayerCore mXdyPlayerCore;
private static XdyPublisherCore mXdyPublisherCore;
private static Context mContext;
private XdyPlayerCore mXdyPlayerCore;
private XdyPublisherCore mXdyPublisherCore;
/*消息管理*/
private static MsgManage mMsgManage;
... ... @@ -46,8 +51,29 @@ public class XdySdk {
/*缓存管理*/
private static ACache aCache;
//TODO 拿不到同步的数据先保留信息(必须释放,否者内存泄漏)
private static SurfaceView mSurfaceView;
private static Activity mActivity;
private SurfaceView mSurfaceView;
private Activity mActivity;
private List<ObserverListener> observerListenerList=new ArrayList<ObserverListener>();
@Override
public void add(ObserverListener observerListener) {
observerListenerList.add(observerListener);
}
@Override
public void notifyObserver(String type, String parameter) {
handleData(type,parameter);
}
@Override
public void remove(ObserverListener observerListener) {
if(observerListenerList.contains(observerListener)){
observerListenerList.remove(observerListener);
}
}
/**
* 对外提供的异步消息接收接口)
... ... @@ -60,12 +86,12 @@ public class XdySdk {
*/
void onXdyAsyncMessageReceiver(String type, String response);
}
private static OnXdyAsyncMessageLitener mOnXdyAsyncMessageLitener;
private OnXdyAsyncMessageLitener mOnXdyAsyncMessageLitener;
/**
* 设置监听
*/
public static void setOnXdyAsyncMessageLitener(OnXdyAsyncMessageLitener onXdyAsyncMessageLitener){
public void setOnXdyAsyncMessageLitener(OnXdyAsyncMessageLitener onXdyAsyncMessageLitener){
judgeCore();;
mOnXdyAsyncMessageLitener=onXdyAsyncMessageLitener;
}
... ... @@ -85,35 +111,36 @@ public class XdySdk {
if(context==null){
throw new IllegalArgumentException(Constants.ERROR_CONTENT_NULL);
}
mContext=context;
aCache=ACache.get(context);
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);
// 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);
}
/**
... ... @@ -121,8 +148,8 @@ public class XdySdk {
* @param type 类型
* @param argument 参数
*/
public static void api(String type,String argument){
judgeCore();
public void api(String type,String argument){
judgeCore();
//再次停止播放器
switch (type){
case "unPublishAudio":
... ... @@ -140,60 +167,44 @@ public class XdySdk {
}
mXdyJsCore.native2js(type, argument);
}
/**
* 接收视频播放的方法
* @param type
* @param rtmpUrl
* @param surfaceView
* @param context
* @deprecated
*/
public static void setAsyncApi(String type, String rtmpUrl, SurfaceView surfaceView,Context context) {
switch (type) {
// case "playVideo":
// /**
// * 重载推流
// * @param type
// * @param rtmpUrl
// * @param surfaceView
// * @param activity
// */
// public void api(String type, String rtmpUrl, SurfaceView surfaceView, Activity activity, SmartEventCallback smartEventCallback) {
// judgeString(type);
// judgeUrl(rtmpUrl);
// switch (type) {
// case Constants.PLAY_AUDIO:
// //播放音频
// mXdyPlayerCore= XdyPlayerCore.getXdyPlayerCore(rtmpUrl,null, activity);
// mXdyPlayerCore.playAudio(rtmpUrl,smartEventCallback);
// break;
// case Constants.PLAY_VIDEO:
// //播放视频
// mXdyPlayerCore = new XdyPlayerCore(rtmpUrl,surfaceView, context);
// mXdyPlayerCore= XdyPlayerCore.getXdyPlayerCore(rtmpUrl,surfaceView, activity);
// mXdyPlayerCore.playVideo(rtmpUrl, surfaceView,smartEventCallback);
// break;
}
}
/**
* 重载推流
* @param type
* @param rtmpUrl
* @param surfaceView
* @param activity
*/
public static void api(String type, String rtmpUrl, SurfaceView surfaceView, Activity activity, SmartEventCallback smartEventCallback) {
judgeString(type);
judgeUrl(rtmpUrl);
switch (type) {
case Constants.PLAY_AUDIO:
//播放音频
mXdyPlayerCore= XdyPlayerCore.getXdyPlayerCore(rtmpUrl,null, activity);
mXdyPlayerCore.playAudio(rtmpUrl,smartEventCallback);
break;
case Constants.PLAY_VIDEO:
//播放视频
mXdyPlayerCore= XdyPlayerCore.getXdyPlayerCore(rtmpUrl,surfaceView, activity);
mXdyPlayerCore.playVideo(rtmpUrl, surfaceView,smartEventCallback);
break;
case Constants.PUBLISH_VIDEO:
//打开推流视频
//用户打开推流的时候应该主动去获取推流地址
if(mXdyPublisherCore==null)
mXdyPublisherCore=new XdyPublisherCore(1,1,activity);
mXdyPublisherCore.publisher(rtmpUrl,surfaceView,smartEventCallback);
break;
case Constants.PUBLISH_AUDIO:
//只推送音频
if(mXdyPublisherCore==null)
mXdyPublisherCore=new XdyPublisherCore(1,0,activity);
mXdyPublisherCore.publisherAudio(rtmpUrl,smartEventCallback);
break;
}
}
// case Constants.PUBLISH_VIDEO:
// //打开推流视频
// //用户打开推流的时候应该主动去获取推流地址
// if(mXdyPublisherCore==null)
// mXdyPublisherCore=new XdyPublisherCore(1,1,activity);
// mXdyPublisherCore.publisher(rtmpUrl,surfaceView,smartEventCallback);
// break;
// case Constants.PUBLISH_AUDIO:
// //只推送音频
// if(mXdyPublisherCore==null)
// mXdyPublisherCore=new XdyPublisherCore(1,0,activity);
// mXdyPublisherCore.publisherAudio(rtmpUrl,smartEventCallback);
// break;
//
// }
// }
/**
* 测试封装 用过时标识区分
... ... @@ -204,10 +215,8 @@ public class XdySdk {
* @param
* @deprecated
*/
public static void api(String type,String mediaId, SurfaceView surfaceView, Activity activity,String ss) {
public void api(String type,String mediaId, SurfaceView surfaceView, Activity activity) {
judgeString(type);
//
Object o;
switch (type) {
case Constants.PLAY_AUDIO:
//播放音频
... ... @@ -215,18 +224,20 @@ public class XdySdk {
* 判断mediaId (仅播放需要)通过取得value 如果为空的话表示输入的数据有误
*
*/
String json= aCache.getAsString(mediaId);
if(TextUtils.isEmpty(json)){
String json_audio= aCache.getAsString(mediaId);
if(TextUtils.isEmpty(json_audio)){
//TODO/给出相应的提示表示没有 这个id
XdyLogUtil.e(TAG,"Play Audio Can not find this AudioId");
return;
}
AudioPlayBean audioPlayBean=JsonUtil.parseJsonToBean(json,AudioPlayBean.class);
AudioPlayBean audioPlayBean=JsonUtil.parseJsonToBean(json_audio,AudioPlayBean.class);
if(audioPlayBean!=null) {
if(mXdyPlayerCore==null)
mXdyPlayerCore = XdyPlayerCore.getXdyPlayerCore(audioPlayBean.getRtmpUrl(), null, activity);
if(mXdyPlayerCore==null) {
mXdyPlayerCore = XdyPlayerCore.getXdyPlayerCore(audioPlayBean.getRtmpUrl(), activity);
}
mXdyPlayerCore.playAudio(audioPlayBean.getRtmpUrl(), new EventHande());
}else{
XdyLogUtil.e(TAG,"Can not get play Audio response");
}
break;
case Constants.PLAY_VIDEO:
... ... @@ -238,15 +249,18 @@ public class XdySdk {
String json_video= aCache.getAsString(mediaId);
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){
if(mXdyPlayerCore==null)
mXdyPlayerCore= XdyPlayerCore.getXdyPlayerCore(videoPlayBean.getRtmpUrl(),surfaceView, activity);
if(mXdyPlayerCore==null) {
mXdyPlayerCore = XdyPlayerCore.getXdyPlayerCore(videoPlayBean.getRtmpUrl(), activity);
}
mXdyPlayerCore.playVideo(videoPlayBean.getRtmpUrl(), surfaceView,new EventHande());
}else{
//统一提示推流错误
XdyLogUtil.e(TAG,"Can not get play Video response");
}
break;
case Constants.PUBLISH_VIDEO:
... ... @@ -275,19 +289,19 @@ public class XdySdk {
}
}
/*判断是否被初始化*/
private static void judgeCore(){
private void judgeCore(){
if(mXdyJsCore==null){
throw new IllegalArgumentException(Constants.ERROR_XDYCORE_INIT);
}
}
/*判断type是否为空*/
private static void judgeString(String type){
private void judgeString(String type){
if(TextUtils.isEmpty(type)){
XdyLogUtil.e(TAG,Constants.ERROR_TYPE_NULL);
}
}
/*判断是否是合法的url*/
protected static void judgeUrl(String url){
protected void judgeUrl(String url){
if (url == null)
return;
... ... @@ -303,20 +317,20 @@ public class XdySdk {
}
}
// public static XdySdk getXdyInstance(){
// if(mXdySdk ==null){
// synchronized (XdySdk.class){
// mXdySdk =new XdySdk();
// }
// }
// return mXdySdk;
// }
public static XdySdk getXdyInstance(){
if(mXdySdk ==null){
synchronized (XdySdk.class){
mXdySdk =new XdySdk();
}
}
return mXdySdk;
}
/**
*core获取到的数据处理
* @param type
* @param response
*/
private static void handleData(String type,String response){
private void handleData(String type,String response){
//开始处理推流信息,用户只需要传递surfaceview activity, 内部处理url
/*需要处理的信息有playVideo 返回的url地址, 遇到video_play ,和
audio
... ... @@ -449,17 +463,20 @@ public class XdySdk {
/**
* 处理所有向外发送的接口数据
* @param type
* @param response
* @param parameter
*/
private static void handleListener(String type,String response){
private void handleListener(String type,String parameter){
if(mOnXdyAsyncMessageLitener!=null){
mOnXdyAsyncMessageLitener.onXdyAsyncMessageReceiver(type,response);
mOnXdyAsyncMessageLitener.onXdyAsyncMessageReceiver(type,parameter);
}
for(ObserverListener o:observerListenerList){
o.observerUpData(type,parameter);
}
}
/**
* 播放视频音频销毁方法
*/
public static void onPlayStop(){
public void onPlayStop(){
if(mXdyPlayerCore!=null) {
mXdyPlayerCore.onStopPlay();
mXdyPlayerCore=null;
... ... @@ -469,7 +486,7 @@ public class XdySdk {
/**
* 推送视频音频停止方法
*/
public static void onPublisherStop(){
public void onPublisherStop(){
if(mXdyPublisherCore!=null){
mXdyPublisherCore.onStopPublisher();
mXdyPublisherCore=null;
... ... @@ -482,7 +499,7 @@ public class XdySdk {
}
}
static class EventHande implements SmartEventCallback {
class EventHande implements SmartEventCallback {
@Override
public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) {
switch (code) {
... ...
package com.mang.xdy.listener;
/**
* Created by abao on 2017/4/18.
*/
public interface ObserverListener {
/**
*
* @param type 类型
* @param parameter 参数
*/
void observerUpData(String type,String parameter);
}
... ...
package com.mang.xdy.listener;
/**
* Created by abao on 2017/4/18.
*/
public interface SubjectListener {
void add(ObserverListener observerListener);
void notifyObserver(String type,String parameter);
void remove(ObserverListener observerListener);
}
... ...
... ... @@ -19,7 +19,7 @@ public class PlayerUtils {
public static void getPublishPathVideo() {
String tem = "{ \"type\": \"live\"}";
String s = XdyStringUtils.stringToJson(tem, true);
XdySdk.api(Constants.GET_VIDEO_PUBLISH_PATH, s);
XdySdk.getXdyInstance().api(Constants.GET_VIDEO_PUBLISH_PATH, s);
}
/**
... ... @@ -28,7 +28,7 @@ public class PlayerUtils {
public static void getPublishPathAudio() {
String tem = "{ \"type\": \"live\"}";
String s = XdyStringUtils.stringToJson(tem, true);
XdySdk.api(Constants.GET_AUDIO_PUBLISH_PATH, s);
XdySdk.getXdyInstance().api(Constants.GET_AUDIO_PUBLISH_PATH, s);
}
/**
... ... @@ -41,7 +41,7 @@ public class PlayerUtils {
publisherEntity.setPublishUrl(url);
String pamp = new Gson().toJson(publisherEntity);
XdyLogUtil.e("推流成功", "" + pamp);
XdySdk.api(Constants.PUBLISH_VIDEO, pamp);
XdySdk.getXdyInstance().api(Constants.PUBLISH_VIDEO, pamp);
}
}
... ... @@ -55,7 +55,7 @@ public class PlayerUtils {
publisherEntity.setPublishUrl(url);
String pamp = new Gson().toJson(publisherEntity);
XdyLogUtil.e("推流成功", "" + pamp);
XdySdk.api(Constants.PUBLISH_AUDIO, pamp);
XdySdk.getXdyInstance().api(Constants.PUBLISH_AUDIO, pamp);
}
}
}
... ...