huangxinbao

add xdysdk for push onPause() and resume().

modify package for push and play.
... ... @@ -53,4 +53,5 @@ dependencies {
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
compile 'com.qiniu:happy-dns:0.2.+'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar'
}
... ...
package com.mang.xdy.demo.activity;
;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.TabLayout;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.PermissionChecker;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
... ... @@ -25,13 +21,14 @@ import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.google.gson.Gson;
import com.mang.xdy.bean.VideoPlayBean;
import com.mang.xdy.cache.ACache;
import com.mang.xdy.common.Constants;
import com.mang.xdy.core.SPUtil;
import com.mang.xdy.utils.SPUtil;
import com.mang.xdy.core.XdySdk;
import com.mang.xdy.demo.R;
import com.mang.xdy.demo.adapter.SimpleFragmentPagerAdapter;
... ... @@ -46,6 +43,7 @@ import com.mang.xdy.demo.utils.ToastUtil;
import com.mang.xdy.demo.widget.dialog.LoginDialog;
import com.mang.xdy.demo.widget.view.NoScrollViewPager;
import com.mang.xdy.listener.ObserverListener;
import com.mang.xdy.utils.SystemUtils;
import com.mang.xdy.utils.UIUtils;
import com.mang.xdy.utils.XdyLogUtil;
import com.mang.xdy.utils.XdyStringUtils;
... ... @@ -54,6 +52,8 @@ import com.pili.pldroid.player.PLMediaPlayer;
import com.pili.pldroid.player.widget.PLVideoTextureView;
import com.pili.pldroid.player.widget.PLVideoView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;
import org.json.JSONObject;
... ... @@ -103,8 +103,13 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
ImageView mImageView_Back;
@BindView(R.id.tv_videoPlay_className)
TextView mTextView_ClassName;
@BindView(R.id.stl_videoPlay_tab)
SlidingTabLayout mSlidingTab;
/*课堂名字*/
private String className;
/*课堂类型*/
private int classType=1;
private String[] titles;
private Handler mmHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
... ... @@ -137,6 +142,8 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
jsonObject = new JSONObject(userJson);
seek = jsonObject.optLong("recordPlaybackMaxTime");
className=jsonObject.optString("className");
classType=jsonObject.optInt("classType");
} catch (JSONException e) {
e.printStackTrace();
}
... ... @@ -145,8 +152,13 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
}
if(replay) {
initRecordSeek(userJson);
}else {
if (classType == 1) {
img_videoPlay_start.setVisibility(View.GONE);
} else {
img_videoPlay_start.setVisibility(View.VISIBLE);
}
}
break;
case Constants.VIDEO_PLAY:
//播放视频
... ... @@ -188,6 +200,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); //屏幕常亮
setContentView(R.layout.activity_video_play);
EventBus.getDefault().register(this);
ButterKnife.bind(this);
aCache=ACache.get(this);
xdySdk = XdySdk.getXdyInstance();
... ... @@ -212,7 +225,6 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
if(!replay){
mVideoView.setVisibility(View.GONE);
mMediaContainer.setVisibility(View.GONE);
img_videoPlay_start.setVisibility(View.VISIBLE);
// btn_videoPlay_stopPublish.setVisibility(View.VISIBLE);
}else{
surfaceviewPlayVideo.setVisibility(View.GONE);
... ... @@ -246,6 +258,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
img_videoPlay_start.setEnabled(false);
btn_videoPlay_stopPublish.setEnabled(true);
sh = surfaceView_publish.getHolder();
sh.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
surfaceView_publish.setZOrderMediaOverlay(true);
xdySdk.api("publishVideo", "", surfaceView_publish, VideoPlayActivity.this);
isVideoMode=true;
... ... @@ -260,13 +273,37 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
});
}
public void setTablayout() {
// public void setTablayout() {
// pagerAdapter = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), this,replay);
// viewPager.setAdapter(pagerAdapter);
// viewPager.setOnRplayTouchListener(this);
// viewPager.setPagingEnabled(false);
// tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
// tabLayout.setupWithViewPager(viewPager,false);
// tabLayout.setTabMode(TabLayout.MODE_FIXED);
// }
public void setTablayout(){
titles = new String[]{"文档", "聊天"};
pagerAdapter = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), this,replay);
viewPager.setAdapter(pagerAdapter);
viewPager.setOnRplayTouchListener(this);
tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
tabLayout.setupWithViewPager(viewPager,false);
tabLayout.setTabMode(TabLayout.MODE_FIXED);
viewPager.setPagingEnabled(false);
mSlidingTab.setViewPager(viewPager, titles);
mSlidingTab.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelect(int position) {
if (1 == position && replay) {
//为了避免回访时切换界面出现桌面 暂时先这样写了
showMediaContainer(TIME_OUT);
}
}
@Override
public void onTabReselect(int position) {
}
});
}
//判断解析是否有密码
... ... @@ -323,7 +360,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
*/
public void playVideo(String response) {
progressDialogDismiss();
// progressDialogDismiss();
if(replay){
playRecord(response);
... ... @@ -362,6 +399,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
@Override
public void onBackPressed() {
UIUtils.closeDialog(mLoginDialog);
exit_dialog();
}
... ... @@ -440,6 +478,19 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
}
@Subscribe(threadMode = ThreadMode.POSTING)
public void finishActivity(String res){
if("home".equals(res)) {
this.finish();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}
@Override
protected void onPause() {
... ... @@ -453,7 +504,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
if(replay) {
xdySdk.api("pauseRecordPlayback", "");
}
// xdySdk.onPublisherPause();
xdySdk.onPublisherPause();
}
@Override
... ... @@ -467,13 +518,15 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
if(replay) {
xdySdk.api("startRecordPlayback", "");
}
// xdySdk.onPublisherResume();
xdySdk.onPublisherResume();
}
/**
* 错误情况退出
*/
public void exit() {
progressDialogDismiss();
isDefaultExit=true;
xdySdk.api("stopPublishVideo","");
xdySdk.api("leaveClass", "");
xdySdk.remove(this);
... ... @@ -534,7 +587,7 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
}
if (mErrorDialog != null)
return;
progressDialogDismiss();
mErrorDialog = new AlertDialog.Builder(this)
.setTitle("退出")
.setMessage("您设备的网络属于断开状态,请重新进入")
... ... @@ -548,7 +601,6 @@ public class VideoPlayActivity extends AppCompatActivity implements ObserverList
})
.create();
mErrorDialog.setCanceledOnTouchOutside(false);
mErrorDialog.show();
}
... ...
... ... @@ -27,14 +27,13 @@ import android.widget.TextView;
import com.mang.xdy.common.Constants;
import com.mang.xdy.core.SPUtil;
import com.mang.xdy.utils.SPUtil;
import com.mang.xdy.demo.R;
import com.mang.xdy.demo.bean.JoinClassSuccessEntity;
import com.mang.xdy.demo.bean.Message;
import com.mang.xdy.demo.fragment.ChatFragment;
import com.mang.xdy.demo.utils.JsonUtil;
import com.mang.xdy.demo.widget.chat.UrlUtils;
import com.mang.xdy.utils.XdyLogUtil;
import org.kymjs.kjframe.KJBitmap;
... ...
... ... @@ -16,14 +16,12 @@ 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.utils.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;
... ... @@ -33,7 +31,6 @@ 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.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
... ... @@ -43,7 +40,6 @@ import org.kymjs.kjframe.utils.KJLoger;
import org.kymjs.kjframe.utils.StringUtils;
import java.io.File;
import java.math.MathContext;
import java.util.ArrayList;
import java.util.List;
... ...
... ... @@ -11,6 +11,8 @@ import com.mang.xdy.demo.R;
import com.mang.xdy.demo.dialog.BaseDialog;
import com.mang.xdy.utils.UIUtils;
import org.greenrobot.eventbus.EventBus;
import me.yokeyword.fragmentation.SupportFragment;
... ... @@ -72,5 +74,7 @@ public class LoginDialog extends BaseDialog {
if (fragment != null && fragment.isAdded()) {
fragment.pop();
}
dismiss();
EventBus.getDefault().post("home");
}
}
... ...
... ... @@ -16,6 +16,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入课堂号"
android:inputType="number"
android:text="1332699420"/>
<TextView
android:layout_width="match_parent"
... ... @@ -25,6 +26,7 @@
android:id="@+id/edt_home_role"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入角色"
android:text="normal"
/>
<TextView
... ... @@ -37,6 +39,7 @@
android:id="@+id/edt_home_serviceIp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入服务器地址"
android:text="112.126.80.182:90"
/>
<TextView
... ... @@ -48,6 +51,7 @@
android:id="@+id/edt_home_userId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入用户id"
android:text="0"
/>
<Button
... ... @@ -55,13 +59,22 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="进入课堂"
android:textColor="@color/white"
android:background="@drawable/home_selector_bottom_btn_blue"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
/>
<Button
android:id="@+id/btn_home_enter_publisher"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:text="录制回放"
android:textColor="@color/white"
android:background="@drawable/home_selector_bottom_btn_green"
/>
</LinearLayout>
... ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_video_play"
android:layout_width="match_parent"
android:layout_height="match_parent"
... ... @@ -127,7 +128,25 @@
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<com.flyco.tablayout.SlidingTabLayout
android:id="@+id/stl_videoPlay_tab"
android:layout_width="match_parent"
android:layout_height="@dimen/ui_titlebar_height"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/fl_videoview_container"
android:background="#fafafa"
custom:tl_indicator_color="@color/home_tab_selected"
custom:tl_indicator_corner_radius="1.5dp"
custom:tl_indicator_height="@dimen/ui_DIMEN_5.0PX"
custom:tl_tab_space_equal="true"
custom:tl_textSelectColor="@color/home_tab_selected"
custom:tl_textUnselectColor="@color/home_tab_unselected"
custom:tl_textsize="@dimen/ui_DIMEN_28.0PX"/>
<com.mang.xdy.demo.widget.view.NoScrollViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
... ...
... ... @@ -81,14 +81,14 @@ public class Threeivity extends AppCompatActivity implements View.OnClickListene
// SmartPlayerNoLayout smartPlayerNoLayout=new SmartPlayerNoLayout(surface, Threeivity.this);
// startActivity(new Intent(Threeivity.this,SmartPlayer.class));
String url= "rtmp://123.56.205.116:6000/live/h5dev_1999957388_980_983041_1491813919";;
//// XdyPlayerCore xdyPlayer=new XdyPlayerCore(url,surface,Threeivity.this);
//// XdyPlayer xdyPlayer=new XdyPlayer(url,surface,Threeivity.this);
//// xdyPlayer.playVideo(url,surface);
// XdySdk.setAsyncApi("playAudio",url,null,Threeivity.this);
// XdySdk.setAsyncApi("playVideo",url,surface,Threeivity.this,new EventHande());
xdySdk.api("publishVideo",url,surface,Threeivity.this);
// xdyPlayer.playVideo("",surface);
// XdyPublisherCore xdyPublisherCore=new XdyPublisherCore(Threeivity.this);
// XdyPublisher xdyPublisherCore=new XdyPublisher(Threeivity.this);
// xdyPublisherCore.publish("",surface);
}
});
... ...
package com.mang.xdy.core;
import android.content.Context;
import android.content.SharedPreferences;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class SPUtil {
private static SharedPreferences mSp;
private static SharedPreferences getSharedPreferences(Context context) {
if (mSp == null) {
mSp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
}
return mSp;
}
public static void putBoolean(Context context, String key, boolean value) {
// SharedPreferences sp = mContext.getSharedPreferences("config",
// Context.MODE_PRIVATE);
getSharedPreferences(context).edit().putBoolean(key, value).commit();
}
public static boolean getBoolean(Context context, String key, boolean defValue) {
// SharedPreferences sp = mContext.getSharedPreferences("config",
// Context.MODE_PRIVATE);
return getSharedPreferences(context).getBoolean(key, defValue);
}
public static void putString(Context context, String key, String value) {
getSharedPreferences(context).edit().putString(key, value).commit();
}
public static String getString(Context context, String key, String defValue) {
return getSharedPreferences(context).getString(key, defValue);
}
public static void putInt(Context context, String key, int value) {
getSharedPreferences(context).edit().putInt(key, value).commit();
}
public static int getInt(Context context, String key, int defValue) {
return getSharedPreferences(context).getInt(key, defValue);
}
/**
* 移除一个字符串值
*
* @param context
* @param key
*/
public static void removeString(Context context, String key) {
getSharedPreferences(context).edit().remove(key).commit();
}
/**
* 把流里的内容解析成字符串
*
* @param is
* @return
* @throws IOException
*/
public static String streamToString(InputStream is) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = -1;
while ((len = is.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
String string = baos.toString();
baos.close();
is.close();
return string;
}
public static long getLong(String key,long defValue) {
return mSp.getLong(key, defValue);
}
public static void setLong(Context context, String key, Long value) {
getSharedPreferences(context).edit().putLong(key, value).commit();
}
}
... ... @@ -5,19 +5,24 @@ package com.mang.xdy.core;
*/
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
import android.text.NoCopySpan;
import android.text.TextUtils;
import android.webkit.JavascriptInterface;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.mang.xdy.common.Constants;
import com.mang.xdy.utils.XdyLogUtil;
import com.mang.xdy.utils.XdyStringUtils;
/**
* 需要提供两个参数的接口,一个参数的接口,同时给出回调()
* 数据的异常检测都放在最外层(便于给用户提示),这层默认数据都是完整
* 核心WebView 处理和调用的js
*/
... ... @@ -54,7 +59,6 @@ public class XdyJsCore {
if(context==null){
return;
}
//清理Webview缓存数据库
mXdyJavaScript=new XdyJavaScript();
mWebView=new WebView(context);
WebSettings webSettings=mWebView.getSettings();
... ... @@ -69,6 +73,23 @@ public class XdyJsCore {
// XdyLogUtil.e("message:"+message+" lineNumber:"+" sourceId:"+sourceID);
}
});
mWebView.setWebViewClient(new WebViewClient(){
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
mWebView.post(new Runnable() {
@Override
public void run() {
... ...
package com.mang.xdy.core;
import android.content.Context;
import android.util.Log;
import android.view.SurfaceView;
import com.daniulive.smartplayer.SmartPlayerJni;
import com.eventhandle.SmartEventCallback;
import com.mang.xdy.utils.XdyLogUtil;
/**
* Created by abao on 2017/4/5.
*/
/**
* 播放视频的方法核心方法(供内部调用,外部继续封装)
*/
public class XdyPlayerCore {
private long playerHandle = 0;
private static final int PORTRAIT = 1; //竖屏
private static final int LANDSCAPE = 2; //横屏
private static final String TAG = "XdyPlayer";
private SmartPlayerJni libPlayer = null;
private Context mContext;
/*是否正在播放,如果正在播放设置为TRUE,防止多次被实例化,*/
private boolean isPlaying=false;
private static XdyPlayerCore mXdyPlayerCore;
static {
System.loadLibrary("SmartPlayer");
}
protected XdyPlayerCore(String rtmpUrl, Context mContext) {
this.mContext=mContext;
}
protected static XdyPlayerCore getXdyPlayerCore(String rtmpUrl, Context mContext){
if(mXdyPlayerCore==null){
synchronized (XdyPlayerCore.class){
if(mXdyPlayerCore==null){
mXdyPlayerCore=new XdyPlayerCore(rtmpUrl, mContext);
}
}
}
return mXdyPlayerCore;
}
/**
* 播放视频的的调用的方法
* 如果surfaceView 为null则播放Audio
* @param rtmpUrl
* @param surfaceView
*/
public void playVideo(String rtmpUrl, SurfaceView surfaceView,SmartEventCallback smartEventCallback) {
// if (isPlaying) {
// return;
// }
if(libPlayer==null)
libPlayer = new SmartPlayerJni();
playerHandle = libPlayer.SmartPlayerInit(mContext);
if (playerHandle == 0) {
XdyLogUtil.e(TAG, "视频初始化失败 ");
return;
}
libPlayer.SetSmartPlayerEventCallback(playerHandle, smartEventCallback);
libPlayer.SmartPlayerSetSurface(playerHandle, surfaceView);
libPlayer.SmartPlayerSetAudioOutputType(playerHandle, 0);
libPlayer.SmartPlayerSetBuffer(playerHandle, 200);
int isPlaySuccessful = libPlayer.SmartPlayerStartPlayback(playerHandle, rtmpUrl);
if (isPlaySuccessful != 0) {
XdyLogUtil.e(TAG, "视频播放失败" + rtmpUrl);
}
// XdySdk.getXdyInstance().notifyObserver("video_success","");
XdyLogUtil.e(TAG, "视频播放成功" + rtmpUrl);
// isPlaying = true;
}
/**
* 播放音频
* @param rtmpUrl
* @param smartEventCallback
*/
public void playAudio(String rtmpUrl,SmartEventCallback smartEventCallback) {
if(libPlayer==null){
libPlayer = new SmartPlayerJni();
}
//TODO
if(playerHandle==0) {
playerHandle = libPlayer.SmartPlayerInit(mContext);
}
XdyLogUtil.e(TAG, "playVideoId" + playerHandle);
if (playerHandle == 0) {
XdyLogUtil.e(TAG, "音频初始化失败");
return;
}
libPlayer.SetSmartPlayerEventCallback(playerHandle, smartEventCallback);
//播放音频
libPlayer.SmartPlayerSetSurface(playerHandle, null);
int isPlaySuccessful = libPlayer.SmartPlayerStartPlayback(playerHandle, rtmpUrl);
if (isPlaySuccessful != 0) {
XdyLogUtil.e(TAG, "音频播放失败" + rtmpUrl);
}
XdyLogUtil.e(TAG, "音频播放成功" + rtmpUrl);
}
class EventHande implements SmartEventCallback {
@Override
public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) {
switch (code) {
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:
Log.i(TAG, "开始。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:
Log.i(TAG, "连接中。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:
Log.i(TAG, "连接失败。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:
Log.i(TAG, "连接成功。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
Log.i(TAG, "连接断开。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
Log.i(TAG, "关闭。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
Log.i(TAG, "收不到媒体数据,可能是url错误。。");
}
}
}
/**
* 结束时调用
*/
protected void onDestroy()
{
XdyLogUtil.i(TAG, "Run into destory++");
if(playerHandle!=0)
{
libPlayer.SmartPlayerClose(playerHandle);
playerHandle = 0;
}
}
/**
* 暂停方法
*/
protected void onPause(){
if(playerHandle!=0)
{
libPlayer.SmartPlayerClose(playerHandle);
playerHandle = 0;
}
isPlaying = false;
}
/**
* 停止播放,重置正在播放标识
*/
protected void onStopPlay() {
if(playerHandle!=0)
{
libPlayer.SmartPlayerClose(playerHandle);
playerHandle = 0;
}
isPlaying = false;
}
}
package com.mang.xdy.core;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.ImageFormat;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import com.daniulive.smartpublisher.SmartPublisherJni;
import com.eventhandle.SmartEventCallback;
import com.mang.xdy.utils.XdyLogUtil;
import com.voiceengine.NTAudioRecord;
import java.io.IOException;
import java.util.List;
/**
* Created by abao on 2017/4/6.
*/
@SuppressWarnings("deprecation")
public class XdyPublisherCore implements SurfaceHolder.Callback, Camera.PreviewCallback {
private SurfaceView mSurfaceView;
private SurfaceHolder pubSurfaceViewHolder;
Activity mActivity;
private SmartPublisherJni xdyPublisher;
private Camera.AutoFocusCallback myAutoFocusCallback = null;
NTAudioRecord audioRecord_ = null;
private static final int BACK = 2;
private static final int FRONT = 1; //前置摄像头标记
private int currentCameraType = BACK; //当前打开的摄像头标记
private Camera mCamera = null;
private boolean mPreviewRunning = false;
private int curCameraIndex = -1;
private int frameCount = 0;
private static String TAG="XdyPublisher";
private static final int PORTRAIT = 1; //竖屏
private static final int LANDSCAPE = 2; //横屏
private int currentOrigentation = PORTRAIT;
//默认都推送 0不推送 1推送
protected int audio_opt = 1;
protected int video_opt = 1;
int videoWidth = 640;
private int videoHight = 480;
/*是否推流的标志,true 开始推送,false不推送*/
private boolean isStart = false;
/*是否支持硬编码 默认不支持*/
private boolean is_hardware_encoder = false;
static {
System.loadLibrary("SmartPublisher");
}
public XdyPublisherCore(int audio_opt,int video_opt,Activity mActivity) {
this.audio_opt=audio_opt;
this.video_opt=video_opt;
this.mActivity = mActivity;
}
/**
* 开始推流(视频)
*
* @param rtmpUrls
*/
public void publisher(String rtmpUrls, SurfaceView pubSurfaceView,SmartEventCallback smartEventCallback) {
// if(isStart){
// return;
// }
mPreviewRunning = false;
this.mSurfaceView=pubSurfaceView;
if (xdyPublisher == null) {
xdyPublisher = new SmartPublisherJni();
}
isStart=true;
if(pubSurfaceViewHolder==null) {
pubSurfaceViewHolder = mSurfaceView.getHolder();
pubSurfaceViewHolder.addCallback(this);
pubSurfaceViewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
Log.i(TAG, "surfaceCreated..");
try {
currentCameraType = FRONT;
if (mCamera == null) {
mCamera = openCamera(currentCameraType);
mCamera.stopPreview();
initCamera(pubSurfaceViewHolder);
}
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "surfaceCreated: 异常了"+e.getMessage());
}
int i = xdyPublisher.SmartPublisherInit(mActivity, audio_opt,video_opt, videoWidth, videoHight);
XdyLogUtil.e(TAG, ": " + i);
xdyPublisher.SetSmartPublisherEventCallback(new EventHande());
XdyLogUtil.e(TAG,"url:"+rtmpUrls);
if (xdyPublisher.SmartPublisherSetURL(rtmpUrls) != 0) {
XdyLogUtil.e(TAG, "Failed to set publish stream URL..");
}
int isStarted = xdyPublisher.SmartPublisherStart(); // 0 成功
if (isStarted != 0) {
XdyLogUtil.e(TAG, "Failed to publish stream..");
} else {
XdyLogUtil.e(TAG, "publish successful");
// isStart = true;
}
CheckInitAudioRecorder();
}
/**
* 开始推流(只有音频)
*
* @param rtmpUrl
*/
public void publisherAudio(String rtmpUrl,SmartEventCallback smartEventCallback) {
// if(isStart){
// return;
// }
if (xdyPublisher == null) {
xdyPublisher = new SmartPublisherJni();
}
isStart=true;
XdyLogUtil.e(TAG, "surfaceCreated..");
int i = xdyPublisher.SmartPublisherInit(mActivity, audio_opt,video_opt, videoWidth, videoHight);
if(i!=0){
XdyLogUtil.e(TAG, "SmartPublisherInit:初始化返回值是0成功: " + i);
return;
}
xdyPublisher.SetSmartPublisherEventCallback(smartEventCallback);
if (xdyPublisher.SmartPublisherSetURL(rtmpUrl) != 0) {
XdyLogUtil.e(TAG, "Failed to set publish stream URL..");
}
if (0 != xdyPublisher.SmartPublisherSetRecorder(0)) {
XdyLogUtil.e(TAG, "SmartPublisherSetRecoder failed.");
return;
}
int isStarted = xdyPublisher.SmartPublisherStart(); // 0 成功
if (isStarted != 0) {
Log.e(TAG, "Failed to publish stream..");
} else {
Log.e(TAG, "publish successful");
// isStart = true;
}
CheckInitAudioRecorder();
}
void CheckInitAudioRecorder() {
if (audioRecord_ == null) {
audioRecord_ = new NTAudioRecord(mActivity, 1);
}
if (audioRecord_ != null) {
Log.e(TAG, "onCreate, call executeAudioRecordMethod..");
audioRecord_.executeAudioRecordMethod();
}
}
@SuppressLint("NewApi")
private Camera openCamera(int type) {
int frontIndex = -1;
int backIndex = -1;
int cameraCount = Camera.getNumberOfCameras();
Log.i(TAG, "cameraCount: " + cameraCount);
Camera.CameraInfo info = new Camera.CameraInfo();
for (int cameraIndex = 0; cameraIndex < cameraCount; cameraIndex++) {
Camera.getCameraInfo(cameraIndex, info);
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
frontIndex = cameraIndex;
} else if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
backIndex = cameraIndex;
}
}
currentCameraType = type;
if (type == FRONT && frontIndex != -1) {
curCameraIndex = frontIndex;
return Camera.open(frontIndex);
} else if (type == BACK && backIndex != -1) {
curCameraIndex = backIndex;
return Camera.open(backIndex);
}
return null;
}
private void initCamera(SurfaceHolder holder) {
Log.i(TAG, "initCamera..");
if (mPreviewRunning) {
if(mCamera!=null)
mCamera.stopPreview();
}
Camera.Parameters parameters;
try {
parameters = mCamera.getParameters();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
parameters.setPreviewSize(videoWidth, videoHight);
parameters.setPictureFormat(PixelFormat.JPEG);
parameters.setPreviewFormat(PixelFormat.YCbCr_420_SP);
setCameraDisplayOrientation(mActivity, curCameraIndex, mCamera);
mCamera.setParameters(parameters);
int bufferSize = (((videoWidth | 0xf) + 1) * videoHight * ImageFormat.getBitsPerPixel(parameters.getPreviewFormat())) / 8;
mCamera.addCallbackBuffer(new byte[bufferSize]);
mCamera.setPreviewCallbackWithBuffer(this);
try {
mCamera.setPreviewDisplay(holder);
} catch (Exception ex) {
// TODO Auto-generated catch block
if (null != mCamera) {
mCamera.release();
mCamera = null;
}
ex.printStackTrace();
}
mCamera.startPreview();
mCamera.autoFocus(myAutoFocusCallback);
mPreviewRunning = true;
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
XdyLogUtil.e(TAG,"holder Create");
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
initCamera(holder);
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
frameCount++;
if (frameCount % 3000 == 0) {
XdyLogUtil.i("OnPre", "gc+");
System.gc();
XdyLogUtil.i("OnPre", "gc-");
}
if (data == null) {
Camera.Parameters params = camera.getParameters();
Camera.Size size = params.getPreviewSize();
int bufferSize = (((size.width | 0x1f) + 1) * size.height * ImageFormat.getBitsPerPixel(params.getPreviewFormat())) / 8;
camera.addCallbackBuffer(new byte[bufferSize]);
} else {
if (isStart) {
xdyPublisher.SmartPublisherOnCaptureVideoData(data, data.length, currentCameraType, currentOrigentation);
}
camera.addCallbackBuffer(data);
}
}
//Check if it has back camera
private int findBackCamera() {
int cameraCount = 0;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
cameraCount = Camera.getNumberOfCameras();
for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
Camera.getCameraInfo(camIdx, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
return camIdx;
}
}
return -1;
}
//Check if it has front camera
private int findFrontCamera() {
int cameraCount = 0;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
cameraCount = Camera.getNumberOfCameras();
for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
Camera.getCameraInfo(camIdx, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
return camIdx;
}
}
return -1;
}
private void switchCamera() throws IOException {
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
mCamera.release();
if (currentCameraType == FRONT) {
mCamera = openCamera(BACK);
} else if (currentCameraType == BACK) {
mCamera = openCamera(FRONT);
}
initCamera(pubSurfaceViewHolder);
}
private void SetCameraFPS(Camera.Parameters parameters) {
if (parameters == null)
return;
int[] findRange = null;
int defFPS = 20 * 1000;
List<int[]> fpsList = parameters.getSupportedPreviewFpsRange();
if (fpsList != null && fpsList.size() > 0) {
for (int i = 0; i < fpsList.size(); ++i) {
int[] range = fpsList.get(i);
if (range != null
&& Camera.Parameters.PREVIEW_FPS_MIN_INDEX < range.length
&& Camera.Parameters.PREVIEW_FPS_MAX_INDEX < range.length) {
XdyLogUtil.i(TAG, "Camera index:" + i + " support min fps:" + range[Camera.Parameters.PREVIEW_FPS_MIN_INDEX]);
XdyLogUtil.i(TAG, "Camera index:" + i + " support max fps:" + range[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
if (findRange == null) {
if (defFPS <= range[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]) {
findRange = range;
XdyLogUtil.i(TAG, "Camera found appropriate fps, min fps:" + range[Camera.Parameters.PREVIEW_FPS_MIN_INDEX]
+ " ,max fps:" + range[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
}
}
}
}
}
if (findRange != null) {
parameters.setPreviewFpsRange(findRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], findRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
}
}
class EventHande implements SmartEventCallback {
@Override
public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) {
switch (code) {
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:
XdyLogUtil.i(TAG, "开始。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:
XdyLogUtil.i(TAG, "连接中。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:
XdyLogUtil.i(TAG, "连接失败。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:
XdyLogUtil.i(TAG, "连接成功。。");
//TODO
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
XdyLogUtil.i(TAG, "连接断开。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
XdyLogUtil.i(TAG, "关闭。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
XdyLogUtil.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
XdyLogUtil.i(TAG, "收不到媒体数据,可能是url错误。。");
}
}
}
private void setCameraDisplayOrientation(Activity activity, int cameraId, android.hardware.Camera camera) {
android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(cameraId, info);
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
int degrees = 0;
switch (rotation) {
case Surface.ROTATION_0:
degrees = 0;
break;
case Surface.ROTATION_90:
degrees = 90;
break;
case Surface.ROTATION_180:
degrees = 180;
break;
case Surface.ROTATION_270:
degrees = 270;
break;
}
int result;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = (info.orientation + degrees) % 360;
result = (360 - result) % 360;
} else {
// back-facing
result = (info.orientation - degrees + 360) % 360;
}
XdyLogUtil.i(TAG, "curDegree: " + result);
camera.setDisplayOrientation(result);
}
/**
* 停止推流
*/
protected void onStopPublisher() {
if (audioRecord_ != null) {
XdyLogUtil.i(TAG, "surfaceDestroyed, call StopRecording..");
audioRecord_.StopRecording();
audioRecord_ = null;
}
if (xdyPublisher != null) {
xdyPublisher.SmartPublisherStop();
}
if(mCamera!=null){
mCamera.release();//释放相机资源
mCamera=null;
}
XdyLogUtil.e("audio","执行");
isStart=false;
}
/**
* onPause 方法调用,不释放相机资源
*/
protected void onPausePublisher(){
isStart=false;
if (audioRecord_ != null) {
XdyLogUtil.i(TAG, "surfaceDestroyed, call StopRecording..");
audioRecord_.StopRecording();
audioRecord_ = null;
}
if (xdyPublisher != null) {
xdyPublisher.SmartPublisherStop();
}
if(mCamera!=null) {
mCamera.stopPreview();
}
}
public void onResumePublisher(){
isStart=true;
}
private int setHardwareEncoderKbps(int width, int height)
{
int hwEncoderKpbs = 0;
switch(width) {
case 176:
hwEncoderKpbs = 300;
break;
case 320:
hwEncoderKpbs = 500;
break;
case 640:
hwEncoderKpbs = 1000;
break;
case 1280:
hwEncoderKpbs = 1700;
break;
default:
hwEncoderKpbs = 1000;
}
return hwEncoderKpbs;
}
}
... ... @@ -21,6 +21,8 @@ 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.play.XdyPlayer;
import com.mang.xdy.play.XdyPublisher;
import com.mang.xdy.utils.JsonUtil;
import com.mang.xdy.utils.NetWorkUtils;
import com.mang.xdy.utils.PlayerUtils;
... ... @@ -46,11 +48,11 @@ public class XdySdk implements SubjectListener{
/**
* 用户初始化,还是调用各种方法,都需要统一的对外给出监听事件
*/
private static XdyJsCore mXdyJsCore;
private static XdyJsCore mXdyJsCore;
private static XdySdk mXdySdk;
private static Context mContext;
private XdyPlayerCore mXdyPlayerCore;
private XdyPublisherCore mXdyPublisherCore;
private static Context mContext;
private XdyPlayer mXdyPlayer;
private XdyPublisher mXdyPublisher;
/*消息管理*/
private static MsgManage mMsgManage;
... ... @@ -62,7 +64,7 @@ public class XdySdk implements SubjectListener{
//TODO 拿不到同步的数据先保留信息(必须释放,否者内存泄漏)
private SurfaceView mSurfaceView_Publish;
private Activity mActivity;
/*是否正在推流,mcu自动断开的时候使用,推流成功后才表示正在使用*/
/*是否正在推流,mcu自动断开,onPause使用的时候使用,推流成功后才表示正在使用*/
private boolean isPublisher =false;
// /*Audio 推送中,resume需要使用*/
private boolean isPublisherAudio=false;
... ... @@ -75,7 +77,7 @@ public class XdySdk implements SubjectListener{
/*推流地址*/
private String publish_url="";
/*保存nodeid ,自己的唯一标识*/
private int nodeId=0;
private int mNodeId =0;
@Override
public void add(ObserverListener observerListener) {
... ... @@ -97,7 +99,8 @@ public class XdySdk implements SubjectListener{
}
}
}
private XdySdk(){}
private XdySdk(){
}
private static Handler handler=new Handler(){
@Override
... ... @@ -149,6 +152,9 @@ public class XdySdk implements SubjectListener{
onPlayDestroy();
break;
}
if(!isRecordPlayBack &&!judegeNetOK()){
return;
}
handler.post(new Runnable() {
@Override
public void run() {
... ... @@ -169,6 +175,9 @@ public class XdySdk implements SubjectListener{
*/
public void api(String type,String mediaId, SurfaceView surfaceView, Activity activity) {
judgeString(type);
if(!isRecordPlayBack &&!judegeNetOK()){
return;
}
switch (type) {
case Constants.PLAY_AUDIO:
//判断mediaId (仅播放需要)通过取得value 如果为空的话表示输入的数据有误
... ... @@ -186,12 +195,12 @@ public class XdySdk implements SubjectListener{
//如果是回放给出。m3u8的id用户 用户需要自己获取play_url_audio=audioPlayBean.getReplay();
}else{
play_url_audio=audioPlayBean.getRtmpUrl() ;
if(mXdyPlayerCore==null) {
mXdyPlayerCore = XdyPlayerCore.getXdyPlayerCore(play_url_audio, activity);
if(mXdyPlayer ==null) {
mXdyPlayer = XdyPlayer.getXdyPlayerCore(play_url_audio, activity);
}else{
mXdyPlayerCore.onStopPlay();
mXdyPlayer.onStopPlay();
}
mXdyPlayerCore.playAudio(play_url_audio, new EventHande_Play());
mXdyPlayer.playAudio(play_url_audio, new EventHande_Play());
}
}else{
... ... @@ -215,13 +224,13 @@ public class XdySdk implements SubjectListener{
// play_url_video=videoPlayBean.getReplay();
}else{
play_url_video=videoPlayBean.getRtmpUrl();
if(mXdyPlayerCore==null) {
mXdyPlayerCore = XdyPlayerCore.getXdyPlayerCore(play_url_video, activity);
if(mXdyPlayer ==null) {
mXdyPlayer = XdyPlayer.getXdyPlayerCore(play_url_video, activity);
}else{
//重复播放时候
mXdyPlayerCore.onStopPlay();
mXdyPlayer.onStopPlay();
}
mXdyPlayerCore.playVideo(play_url_video, surfaceView,new EventHande_Play());
mXdyPlayer.playVideo(play_url_video, surfaceView,new EventHande_Play());
}
}else{
... ... @@ -243,7 +252,6 @@ public class XdySdk implements SubjectListener{
case Constants.PUBLISH_AUDIO:
//只推送音频
getPublishPathAudio();
// mSurfaceView=surfaceView;
mActivity=activity;
break;
... ... @@ -261,21 +269,17 @@ public class XdySdk implements SubjectListener{
XdyLogUtil.e(TAG,Constants.ERROR_TYPE_NULL);
}
}
/*判断是否是合法的url*/
protected void judgeUrl(String url){
if (url == null)
return;
// rtmp://
if (url.length() < 8) {
Log.e(TAG, "Input publish url error:" + url);
return;
}
if (!url.startsWith("rtmp://")) {
Log.e(TAG, "Input publish url error:" + url);
return;
/*判断网路是否正常*/
private boolean judegeNetOK(){
if( !NetWorkUtils.isNetworkConnected(mContext)){
String errorJson="{\n" +
" \"code\": 20000,\n" +
" \"reson\": \"无网络连接,请检查网络\"\n" +
"}";
notifyObserver(Constants.ERROR_CODE, errorJson);
return false;
}
return true;
}
public static XdySdk getXdyInstance(){
... ... @@ -306,7 +310,7 @@ public class XdySdk implements SubjectListener{
try {
jsonObject = new JSONObject(response);
isRecordPlayBack = jsonObject.optBoolean("isRecordPlayBack");
nodeId=jsonObject.optInt("nodeId");
mNodeId =jsonObject.optInt("mNodeId");
} catch (JSONException e) {
e.printStackTrace();
}
... ... @@ -333,16 +337,16 @@ public class XdySdk implements SubjectListener{
//TODo 给出提示
throw new IllegalArgumentException(Constants.ERROR_TYPE_ACTIVITY);
}
if (mXdyPublisherCore == null) {
mXdyPublisherCore = new XdyPublisherCore(1, 1, mActivity);
if (mXdyPublisher == null) {
mXdyPublisher = new XdyPublisher(1, 1, mActivity);
}else{
//todo 如果不为空的话是已经播放过,得清理上次的
mXdyPlayerCore.onPause();
// mXdyPlayer.onPause();
}
publish_url=video_url;
isPublisher =true;
isPublisherAudio=false;
mXdyPublisherCore.publisher(video_url,mSurfaceView_Publish, new EventHande_Publish());
mXdyPublisher.publisher(video_url,mSurfaceView_Publish, new EventHande_Publish());
// PlayerUtils.setPublishSendSuccessVideo(aCache.getAsString(Constants.GET_VIDEO_PUBLISH_PATH));
//// TODO: 2017/4/13 大牛连接成功回调没有监听到 暂时在这告知后台,(后续加上网路判断,摄像头判断)
setPublishSendSuccessVideo(video_url);
... ... @@ -379,13 +383,13 @@ public class XdySdk implements SubjectListener{
XdyLogUtil.e(TAG,"activity is null");
return;
}
if(mXdyPublisherCore==null) {
mXdyPublisherCore = new XdyPublisherCore(1, 0, mActivity);
if(mXdyPublisher ==null) {
mXdyPublisher = new XdyPublisher(1, 0, mActivity);
}else {
//todo 如果不为空的话是已经播放过,得清理上次的
mXdyPlayerCore.onPause();
// mXdyPlayer.onPause();
}
mXdyPublisherCore.publisherAudio(audio_url,new EventHande_Publish());
mXdyPublisher.publisherAudio(audio_url,new EventHande_Publish());
publish_url=audio_url;
isPublisher =true;
isPublisherAudio=true;
... ... @@ -441,7 +445,7 @@ public class XdySdk implements SubjectListener{
VideoPlayBean videoPlayBean= JsonUtil.parseJsonToBean(video,VideoPlayBean.class);
if(videoPlayBean!=null) {
// if(videoPlayBean.getMediaId()!=videoPlayBean.getFromNodeId()) {
if(nodeId!=videoPlayBean.getFromNodeId()) {
if(mNodeId !=videoPlayBean.getFromNodeId()) {
//过滤自己推送的video
aCache.put(videoPlayBean.getMediaId() + "", video);
handleListener(type, videoPlayBean.getMediaId() + "");
... ... @@ -455,7 +459,7 @@ public class XdySdk implements SubjectListener{
AudioPlayBean audioPlayBean=JsonUtil.parseJsonToBean(audio,AudioPlayBean.class);
if(audioPlayBean!=null){
// if(audioPlayBean.getMediaId()!=audioPlayBean.getFromNodeId()) {
if(nodeId!=audioPlayBean.getFromNodeId()) {
if(mNodeId !=audioPlayBean.getFromNodeId()) {
aCache.put(audioPlayBean.getMediaId() + "", audio);
handleListener(type, audioPlayBean.getMediaId() + "");
}
... ... @@ -521,9 +525,9 @@ public class XdySdk implements SubjectListener{
*/
public boolean onPlayStop(String id){
if(currentPlayId.equals(id)) {
if (mXdyPlayerCore != null) {
mXdyPlayerCore.onStopPlay();
// mXdyPlayerCore = null;
if (mXdyPlayer != null) {
mXdyPlayer.onStopPlay();
// mXdyPlayer = null;
}
return true;
... ... @@ -534,8 +538,8 @@ public class XdySdk implements SubjectListener{
* 退出时清除信息(重置js监听)
*/
public void removeAll(){
if(mXdyPlayerCore!=null) {
mXdyPlayerCore.onPause();
if(mXdyPlayer !=null) {
mXdyPlayer.onPause();
}
if(mXdyJsCore!=null&&!isRecordPlayBack) {
mXdyJsCore.init(mContext);
... ... @@ -547,9 +551,9 @@ public class XdySdk implements SubjectListener{
* 结束时调用
*/
public void onPlayDestroy(){
if (mXdyPlayerCore != null) {
mXdyPlayerCore.onStopPlay();
mXdyPlayerCore = null;
if (mXdyPlayer != null) {
mXdyPlayer.onStopPlay();
mXdyPlayer = null;
}
... ... @@ -560,9 +564,9 @@ public class XdySdk implements SubjectListener{
* @deprecated daniu sdk handle best
*/
public void onPublisherStop(){
if(mXdyPublisherCore!=null){
mXdyPublisherCore.onStopPublisher();
mXdyPublisherCore=null;
if(mXdyPublisher !=null){
mXdyPublisher.onStopPublisher();
mXdyPublisher =null;
}
//如果正在推流,msurfaceView ,mActivity不清空
if(!isPublisher) {
... ... @@ -580,10 +584,11 @@ public class XdySdk implements SubjectListener{
/**
* onPause 方法时走的周期
* 推送视频暂停调用,单独提出,不与play合并考虑到有后台继续推送的情况
*/
public void onPublisherPause(){
if(mXdyPublisherCore!=null){
mXdyPublisherCore.onPausePublisher();
if(mXdyPublisher !=null){
mXdyPublisher.onPausePublisher();
}
}
... ... @@ -598,13 +603,13 @@ public class XdySdk implements SubjectListener{
if(!isPublisher){
return;
}
if(mXdyPublisherCore!=null) {
mXdyPublisherCore.onResumePublisher();
if(mXdyPublisher !=null) {
mXdyPublisher.onResumePublisher();
if (!TextUtils.isEmpty(publish_url)) {
if(!isPublisherAudio){
mXdyPublisherCore.publisher(publish_url, mSurfaceView_Publish, new EventHande_Publish());
mXdyPublisher.publisher(publish_url, mSurfaceView_Publish, new EventHande_Publish());
}else{
mXdyPublisherCore.publisherAudio(publish_url,new EventHande_Publish());
mXdyPublisher.publisherAudio(publish_url,new EventHande_Publish());
}
}
... ...
... ... @@ -38,7 +38,7 @@ public class XdyStringUtils {
}
return resString;
}
/*判断url*/
public static void judgeUrl(String url){
if (url == null)
return;
... ...