huangxinbao

Android sdk目录 和测试demo目

正在显示 69 个修改的文件 包含 4402 行增加0 行删除

要显示太多修改。

为保证性能只显示 69 of 69+ 个文件。

*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
... ...
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
... ...
<component name="CopyrightManager">
<settings default="" />
</component>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="C:\Program Files\Android\Android Studio\gradle\gradle-2.14.1" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/XdyDemo" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/easeUI_CN" />
<option value="$PROJECT_DIR$/myapplication2" />
<option value="$PROJECT_DIR$/mylibrary" />
<option value="$PROJECT_DIR$/sdklibraryssss" />
<option value="$PROJECT_DIR$/smartPlayer" />
<option value="$PROJECT_DIR$/xdy" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<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">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/MyApplication.iml" filepath="$PROJECT_DIR$/MyApplication.iml" />
<module fileurl="file://$PROJECT_DIR$/XdyDemo/XdyDemo.iml" filepath="$PROJECT_DIR$/XdyDemo/XdyDemo.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/easeUI_CN/easeUI_CN.iml" filepath="$PROJECT_DIR$/easeUI_CN/easeUI_CN.iml" />
<module fileurl="file://$PROJECT_DIR$/myapplication2/myapplication2.iml" filepath="$PROJECT_DIR$/myapplication2/myapplication2.iml" />
<module fileurl="file://$PROJECT_DIR$/mylibrary/mylibrary.iml" filepath="$PROJECT_DIR$/mylibrary/mylibrary.iml" />
<module fileurl="file://$PROJECT_DIR$/sdklibraryssss/sdklibraryssss.iml" filepath="$PROJECT_DIR$/sdklibraryssss/sdklibraryssss.iml" />
<module fileurl="file://$PROJECT_DIR$/smartPlayer/smartPlayer.iml" filepath="$PROJECT_DIR$/smartPlayer/smartPlayer.iml" />
<module fileurl="file://$PROJECT_DIR$/xdy/xdy.iml" filepath="$PROJECT_DIR$/xdy/xdy.iml" />
</modules>
</component>
</project>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
... ...
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
applicationId "com.mang.xdy.demo"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
repositories {
flatDir {
dirs 'libs'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
compile project(':xdy')
compile 'com.google.code.gson:gson:2.7'
compile 'com.android.support:design:23.4.0'
}
... ...
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in D:\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
... ...
package com.mang.xdy.demo;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.mang.xdy.demo", appContext.getPackageName());
}
}
... ...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mang.xdy.demo">
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name=".application.XdyApplicaiton"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.VideoPlayActivity" />
<activity android:name=".activity.VideoPublisherActivity"></activity>
</application>
</manifest>
\ No newline at end of file
... ...
package com.mang.xdy.demo;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.google.gson.Gson;
import com.mang.xdy.demo.activity.VideoPlayActivity;
import com.mang.xdy.demo.activity.VideoPublisherActivity;
import com.mang.xdy.demo.bean.JoinClassBean;
import com.mang.xdy.utils.XdyLogUtil;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity {
@BindView(R.id.edt_home_classId)
EditText edtHomeClassId;
@BindView(R.id.edt_home_role)
EditText edtHomeRole;
@BindView(R.id.edt_home_serviceIp)
EditText edtHomeServiceIp;
@BindView(R.id.edt_home_userId)
EditText edtHomeUserId;
@BindView(R.id.btn_home_enter_class)
Button btnHomeEnterClass;
@BindView(R.id.btn_home_enter_publisher)
Button btn_home_enter_publisher;
/*一进来就要初始化,让后再调 加入课堂*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
@OnClick({R.id.btn_home_enter_class,R.id.btn_home_enter_publisher})
public void onViewClicked(View view) {
switch (view.getId()){
case R.id.btn_home_enter_class:
Intent intent=new Intent(MainActivity.this, VideoPlayActivity.class);
intent.putExtra("init",joinClass());
startActivity(intent);
break;
case R.id.btn_home_enter_publisher:
Intent intents=new Intent(MainActivity.this, VideoPublisherActivity.class);
intents.putExtra("init",joinClass());
startActivity(intents);
break;
}
}
public String joinClass(){
JoinClassBean joinClassBean=new JoinClassBean();
joinClassBean.setClassId(Integer.parseInt(edtHomeClassId.getText().toString()));
joinClassBean.setUserRole(edtHomeRole.getText().toString());
joinClassBean.setPortal(edtHomeServiceIp.getText().toString());
joinClassBean.setUserId(Integer.parseInt(edtHomeUserId.getText().toString()));
joinClassBean.setUserName("");
String joinclass=new Gson().toJson(joinClassBean);
XdyLogUtil.e("init 初始化",joinclass);
return joinclass;
}
}
... ...
package com.mang.xdy.demo.activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.media.Image;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.eventhandle.SmartEventCallback;
import com.google.gson.Gson;
import com.mang.xdy.core.XdySdk;
import com.mang.xdy.demo.R;
import com.mang.xdy.demo.adapter.SimpleFragmentPagerAdapter;
import com.mang.xdy.demo.bean.AudioPlayBean;
import com.mang.xdy.demo.bean.ChatBean;
import com.mang.xdy.demo.bean.DocEntity;
import com.mang.xdy.demo.bean.InitClassSuccessEntity;
import com.mang.xdy.demo.bean.JoinClass;
import com.mang.xdy.demo.bean.LiveBean;
import com.mang.xdy.demo.bean.VideoPlayBean;
import com.mang.xdy.demo.utils.JsonUtil;
import com.mang.xdy.demo.utils.ToastUtil;
import com.mang.xdy.utils.XdyLogUtil;
import com.mang.xdy.utils.XdyStringUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class 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;
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;
private String initClass = "";
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case -2:
//加入课堂输入用户名,密码
joinClass("", (Boolean) msg.obj);
break;
case -1:
//退出
XdySdk.setAsyncApi("leaveClass", "");
break;
case 0:
parseJoinClass((String) msg.obj,true);
break;
case 1:
//播放视频
playVideo((String) msg.obj);
XdyLogUtil.e(TAG,"当前线程 handdler:"+android.os.Process.myPid()+""+"线程:"+Thread.currentThread().getId()+"");
break;
case 2:
//播放音频
playAudio((String) msg.obj);
break;
case 3:
getDoc((String) msg.obj);
break;
case 4:
//发送消息
sendMeg();
break;
case 5:
//接受消息
getMsg((String) msg.obj);
break;
case 6:
//推流video
publisherVideo((String) msg.obj);
break;
case 7:
//停止播放
XdySdk.onPlayStop();
img_playVideo_novideo.setVisibility(View.GONE);
// surfaceviewPlayVideo.refreshDrawableState();;
// ToastUtil.showToastshort("播放音视/视频停止",VideoPlayActivity.this);
break;
}
}
};
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_play);
ButterKnife.bind(this);
// setTablayout();
init();
XdyLogUtil.e(TAG,"当前线程 main:"+android.os.Process.myPid()+"线程:"+Thread.currentThread().getId()+"");
XdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
@Override
public void onXdyAsyncMessageReceiver(String type, String response) {
Message message = Message.obtain();
switch (type) {
case "class_init_success":
ToastUtil.showToastshort("初始化课堂成功", VideoPlayActivity.this);
message.obj = response;
message.what = 0;
handler.sendMessage(message);
break;
case "class_join_success":
//加入课堂成功
ToastUtil.showToastshort("加入课堂成功", VideoPlayActivity.this);
break;
case "video_play":
//播放视频
XdyLogUtil.e(TAG, "执行了" + response);
XdyLogUtil.e(TAG,"当前线程 listerne:"+android.os.Process.myPid()+""+"线程:"+Thread.currentThread().getId()+"");
message.obj = response;
message.what = 1;
handler.sendMessage(message);
break;
case "audio_play":
//播放音频
message.obj = response;
message.what = 2;
handler.sendMessage(message);
break;
case "class_delete_roster":
// ToastUtil.showToastshort("离开课堂", VideoPlayActivity.this);
//人员离开
break;
case "chat_receive_message":
//监听聊天信息
message.obj = response;
message.what = 5;
handler.sendMessage(message);
break;
case "document_update":
//监听文档信息
message.obj = response;
message.what = 3;
// handler.sendMessage(message);
ToastUtil.showToastshort("文档更新" + response, VideoPlayActivity.this);
break;
case "whiteboard_annotation_update":
ToastUtil.showToastshort("白板信息更新" + response, VideoPlayActivity.this);
break;
case "live":
// String urls= "rtmp://player.daniulive.com:1935/hls/stream";;
//推流直播
// message.obj = response;
// message.what = 6;
// handler.sendMessage(message);
break;
case "video_stop":
handler.sendEmptyMessage(7);
break;
case "audio_stop":
break;
}
}
});
}
public void init() {
initClass = getIntent().getStringExtra("init");
XdySdk.setAsyncApi("init", initClass);
}
public void setTablayout() {
pagerAdapter = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), this);
viewPager = (ViewPager) findViewById(R.id.viewpager);
viewPager.setAdapter(pagerAdapter);
tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
tabLayout.setupWithViewPager(viewPager);
tabLayout.setTabMode(TabLayout.MODE_FIXED);
}
//判断解析是否有密码
public void parseJoinClass(String rsponse,boolean isShowPwd){
InitClassSuccessEntity initClassSuccessEntity=JsonUtil.parseJsonToBean(rsponse,InitClassSuccessEntity.class);
if(initClassSuccessEntity!=null)
if(initClassSuccessEntity.isPasswordRequired()){
personDialog=new PersonDialog(this,true);
}else{
personDialog=new PersonDialog(this,false);
userpwd="123321";
}
personDialog.show();
}
//加入课堂
public void joinClass(String rsponse,boolean isShowPwd) {
// String temp = "{\n" +
// " \"userName\":\"base\",\n" +
// " \"password\":\"123321\",\n" +
// " \"hasCamera\":false,\n" +
// " \"hasMicrophone\":false}";
JoinClass joinClass=new JoinClass();
joinClass.setHasCamera(false);
joinClass.setHasMicrophone(false);
joinClass.setUserName(username);
if(!isShowPwd){
joinClass.setPassword("123321");
}else{
joinClass.setPassword(userpwd);
}
String temp=new Gson().toJson(joinClass);
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e("加入课堂", jsonParmp);
XdySdk.setAsyncApi("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.setAsyncApi("playVideo", videoPlayBean.getRtmpUrl(), surfaceviewPlayVideo, VideoPlayActivity.this, new EventHande_Video());
img_playVideo_novideo.setVisibility(View.GONE);
ToastUtil.showToastshort("视频播放初始化",VideoPlayActivity.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.setAsyncApi("playAudio", audioPlayBean.getRtmpUrl(), null, VideoPlayActivity.this, new EventHande_Video());
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" +
// "}";
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e(TAG, "文档" + jsonParmp);
XdySdk.setAsyncApi("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.setAsyncApi("sendChatMsg", jsonParmp);
}
//获取聊天信息
public void getMsg(String msg) {
ChatBean chatBean = JsonUtil.parseJsonToBean(msg, ChatBean.class);
if (chatBean != null) {
btnVideoPlayChat.setText(chatBean.getMessage());
}
}
//获取推流地址
public void getPublish() {
String ids_new = "getVideoPublishPath";
String tem = "{ \"type\": \"live\"}";
String s = XdyStringUtils.stringToJson(tem, true);
XdySdk.setAsyncApi(ids_new, s);
}
public void publisherVideo(String response) {
XdySdk.onPlayStop();
String url = XdyStringUtils.stringToJson(response);
XdyLogUtil.e("调用任务了播视频了url:", "" + url);
String us = response.substring(1, response.length() - 1);
XdyLogUtil.e("调用任务了播视频了ursfdfl:", "" + us);
try {
LiveBean liveBean = new Gson().fromJson(url, LiveBean.class);
if (liveBean != null&&liveBean.getCode()==0) {
String url_text="rtmp://player.daniulive.com:1935/hls/stream";
// XdySdk.setAsyncApi("publishVideo", liveBean.getPublishUrl(), surfaceviewPlayVideo, VideoPlayActivity.this,new EventHande());
// tv_videoPlay_url.setText("推流地址:"+liveBean.getPublishUrl());
tv_videoPlay_url.setText("推流地址:"+url_text);
XdyLogUtil.e(TAG,liveBean.getPublishUrl());
XdySdk.setAsyncApi("publishVideo", url_text, surfaceview_pubisherVideo, VideoPlayActivity.this,new EventHande());
ToastUtil.showToastshort("推流初始化中",VideoPlayActivity.this);
}
} catch (Exception e) {
XdyLogUtil.e("调用任务了播视频了e", "" + e.getMessage());
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
@Override
protected void onDestroy() {
super.onDestroy();
XdySdk.onPlayStop();
}
@OnClick({R.id.btn_videoPlay_chat, R.id.btn_videoPlay_pubsherVideo})
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;
}
}
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, "连接成功。。");
//TODO
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
Log.i(TAG, "连接断开。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
Log.i(TAG, "关闭。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
Log.i(TAG, "收不到媒体数据,可能是url错误。。");
}
}
}
class EventHande_Video implements SmartEventCallback {
@Override
public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) {
switch (code) {
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:
Log.i(TAG, "开始。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:
Log.i(TAG, "连接中。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:
Log.i(TAG, "连接失败。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:
Log.i(TAG, "连接成功。。");
//TODO
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
Log.i(TAG, "连接断开。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
Log.i(TAG, "关闭。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
Log.i(TAG, "收不到媒体数据,可能是url错误。。");
}
}
}
class PersonDialog extends Dialog {
public PersonDialog(Context context) {
this(context, false);
}
public PersonDialog(Context context, boolean showPwd) {
this(context, R.style.bottom_dialog, showPwd);
}
public PersonDialog(Context context, int themeResId, boolean showPwd) {
super(context, themeResId);
init(context, showPwd);
}
public void init(Context context, boolean showPwd) {
View view = View.inflate(context, R.layout.dialog_item, null);
setContentView(view);
initView(view,showPwd);
setCanceledOnTouchOutside(false);
Window window = getWindow();
WindowManager.LayoutParams params = window.getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = dp2px(context, 220);
window.setAttributes(params);
window.setGravity(Gravity.CENTER);
}
public int dp2px(Context context, float dp) {
return (int) Math.ceil(context.getResources().getDisplayMetrics().density * dp);
}
public void initView(View view, final boolean showPwd){
final EditText edt_uername= (EditText) view.findViewById(R.id.dialog_edt_username);
final EditText edt_userpwd= (EditText) view.findViewById(R.id.dialog_edt_userpwd);
if(showPwd){
edt_userpwd.setVisibility(View.VISIBLE);
}else{
edt_userpwd.setVisibility(View.GONE);
}
Button btn_enter= (Button) view.findViewById(R.id.dialog_btn_enter);
btn_enter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
username=edt_uername.getText().toString();
userpwd=edt_userpwd.getText().toString();
if(TextUtils.isEmpty(username)){
ToastUtil.showToastshort("用户名不能为空",VideoPlayActivity.this);
return;
}
if(showPwd&&TextUtils.isEmpty(userpwd)){
ToastUtil.showToastshort("密码不能为空",VideoPlayActivity.this);
return;
}
dismiss();
Message message=Message.obtain();
message.what=-2;
message.obj=showPwd;
handler.sendMessage(message);
}
});
}
}
}
... ...
package com.mang.xdy.demo.activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.media.Image;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.eventhandle.SmartEventCallback;
import com.google.gson.Gson;
import com.mang.xdy.core.XdySdk;
import com.mang.xdy.demo.R;
import com.mang.xdy.demo.adapter.SimpleFragmentPagerAdapter;
import com.mang.xdy.demo.bean.AudioPlayBean;
import com.mang.xdy.demo.bean.ChatBean;
import com.mang.xdy.demo.bean.DocEntity;
import com.mang.xdy.demo.bean.InitClassSuccessEntity;
import com.mang.xdy.demo.bean.JoinClass;
import com.mang.xdy.demo.bean.LiveBean;
import com.mang.xdy.demo.bean.PublisherEntity;
import com.mang.xdy.demo.bean.VideoPlayBean;
import com.mang.xdy.demo.utils.JsonUtil;
import com.mang.xdy.demo.utils.ToastUtil;
import com.mang.xdy.utils.XdyLogUtil;
import com.mang.xdy.utils.XdyStringUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class VideoPublisherActivity 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;
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;
private String initClass = "";
private String publisherSuccess="";
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case -2:
//加入课堂输入用户名,密码
joinClass("", (Boolean) msg.obj);
break;
case -1:
//退出
XdySdk.setAsyncApi("leaveClass", "");
break;
case 0:
parseJoinClass((String) msg.obj,true);
break;
case 1:
//播放视频
playVideo((String) msg.obj);
XdyLogUtil.e(TAG,"当前线程 handdler:"+android.os.Process.myPid()+""+"线程:"+Thread.currentThread().getId()+"");
break;
case 2:
//播放音频
playAudio((String) msg.obj);
break;
case 3:
getDoc((String) msg.obj);
break;
case 4:
//发送消息
sendMeg();
break;
case 5:
//接受消息
getMsg((String) msg.obj);
break;
case 6:
//推流video
publisherVideo((String) msg.obj);
break;
case 7:
//停止播放
XdySdk.onPlayStop();
// img_playVideo_novideo.setVisibility(View.GONE);
// surfaceviewPlayVideo.refreshDrawableState();;
// ToastUtil.showToastshort("播放音视/视频停止",VideoPlayActivity.this);
break;
}
}
};
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_publisher);
ButterKnife.bind(this);
// setTablayout();
init();
XdyLogUtil.e(TAG,"当前线程 main:"+android.os.Process.myPid()+"线程:"+Thread.currentThread().getId()+"");
XdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
@Override
public void onXdyAsyncMessageReceiver(String type, String response) {
Message message = Message.obtain();
switch (type) {
case "class_init_success":
ToastUtil.showToastshort("初始化课堂成功", VideoPublisherActivity.this);
message.obj = response;
message.what = 0;
handler.sendMessage(message);
break;
case "class_join_success":
//加入课堂成功
ToastUtil.showToastshort("加入课堂成功", VideoPublisherActivity.this);
break;
// case "video_play":
// //播放视频
// XdyLogUtil.e(TAG, "执行了" + response);
// XdyLogUtil.e(TAG,"当前线程 listerne:"+android.os.Process.myPid()+""+"线程:"+Thread.currentThread().getId()+"");
// message.obj = response;
// message.what = 1;
// handler.sendMessage(message);
//
// break;
// case "audio_play":
// //播放音频
// message.obj = response;
// message.what = 2;
// handler.sendMessage(message);
// break;
// case "class_delete_roster":
//// ToastUtil.showToastshort("离开课堂", VideoPlayActivity.this);
// //人员离开
// break;
// case "chat_receive_message":
// //监听聊天信息
// message.obj = response;
// message.what = 5;
// handler.sendMessage(message);
// break;
// case "document_update":
// //监听文档信息
// message.obj = response;
// message.what = 3;
//// handler.sendMessage(message);
// ToastUtil.showToastshort("文档更新" + response, VideoPublisherActivity.this);
// break;
// case "whiteboard_annotation_update":
// ToastUtil.showToastshort("白板信息更新" + response, VideoPublisherActivity.this);
// break;
case "live":
// String urls= "rtmp://player.daniulive.com:1935/hls/stream";;
//推流直播
message.obj = response;
message.what = 6;
handler.sendMessage(message);
break;
case "video_stop":
// handler.sendEmptyMessage(7);
break;
case "audio_stop":
break;
}
}
});
}
public void init() {
initClass = getIntent().getStringExtra("init");
XdySdk.setAsyncApi("init", initClass);
}
public void setTablayout() {
pagerAdapter = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), this);
viewPager = (ViewPager) findViewById(R.id.viewpager);
viewPager.setAdapter(pagerAdapter);
tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
tabLayout.setupWithViewPager(viewPager);
tabLayout.setTabMode(TabLayout.MODE_FIXED);
}
//判断解析是否有密码
public void parseJoinClass(String rsponse,boolean isShowPwd){
InitClassSuccessEntity initClassSuccessEntity=JsonUtil.parseJsonToBean(rsponse,InitClassSuccessEntity.class);
if(initClassSuccessEntity!=null)
if(initClassSuccessEntity.isPasswordRequired()){
personDialog=new PersonDialog(this,true);
}else{
personDialog=new PersonDialog(this,false);
userpwd="123321";
}
personDialog.show();
}
//加入课堂
public void joinClass(String rsponse,boolean isShowPwd) {
// String temp = "{\n" +
// " \"userName\":\"base\",\n" +
// " \"password\":\"123321\",\n" +
// " \"hasCamera\":false,\n" +
// " \"hasMicrophone\":false}";
JoinClass joinClass=new JoinClass();
joinClass.setHasCamera(false);
joinClass.setHasMicrophone(false);
joinClass.setUserName(username);
if(!isShowPwd){
joinClass.setPassword("123321");
}else{
joinClass.setPassword(userpwd);
}
String temp=new Gson().toJson(joinClass);
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e("加入课堂", jsonParmp);
XdySdk.setAsyncApi("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.setAsyncApi("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.setAsyncApi("playAudio", audioPlayBean.getRtmpUrl(), null, VideoPublisherActivity.this, new EventHande_Video());
// img_playVideo_novideo.setVisibility(View.GONE);
ToastUtil.showToastshort("音频播放初始化",VideoPublisherActivity.this);
}
}
public void getDoc(String response) {
DocEntity docEntity = JsonUtil.parseJsonToBean(response, DocEntity.class);
if (docEntity != null && docEntity.getRelativeUrl() != null) {
String url = docEntity.getRelativeUrl();
String temp = "{\n" +
" \"type\": \"jpg\",\n" +
" \"pageNum\": 1,\n" +
" \"relativeUrl\": \" '" + url + "'\"\n" +
"}";
// String temp = "{\n" +
// " \"type\": \"jpg\",\n" +
// " \"pageNum\": 1,\n" +
// " \"relativeUrl\": \"/DocSharing/data/1087553281/20170409-204600041/d32594763768243bddc64934be5088a0.jpg\"\n" +
// "}";
String jsonParmp = XdyStringUtils.stringToJson(temp, true);
XdyLogUtil.e(TAG, "文档" + jsonParmp);
XdySdk.setAsyncApi("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.setAsyncApi("sendChatMsg", jsonParmp);
}
//获取聊天信息
public void getMsg(String msg) {
ChatBean chatBean = JsonUtil.parseJsonToBean(msg, ChatBean.class);
if (chatBean != null) {
btnVideoPlayChat.setText(chatBean.getMessage());
}
}
//获取推流地址
public void getPublish() {
String ids_new = "getVideoPublishPath";
String tem = "{ \"type\": \"live\"}";
String s = XdyStringUtils.stringToJson(tem, true);
XdySdk.setAsyncApi(ids_new, s);
}
public void publisherVideo(String response) {
XdySdk.onPlayStop();
String url = XdyStringUtils.stringToJson(response);
XdyLogUtil.e("调用任务了播视频了url:", "" + url);
String us = response.substring(1, response.length() - 1);
XdyLogUtil.e("调用任务了播视频了ursfdfl:", "" + us);
try {
LiveBean liveBean = new Gson().fromJson(url, LiveBean.class);
if (liveBean != null&&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();
XdySdk.setAsyncApi("publishVideo", liveBean.getPublishUrl(), surfaceview_pubisherVideo, VideoPublisherActivity.this,new EventHande());
XdyLogUtil.e(TAG,liveBean.getPublishUrl());
ToastUtil.showToastshort("推流初始化中",VideoPublisherActivity.this);
PublisherEntity publisherEntity=new PublisherEntity();
if(!TextUtils.isEmpty(publisherSuccess)) {
publisherEntity.setPublishUrl(publisherSuccess);
String pamp= new Gson().toJson(publisherEntity);
XdyLogUtil.e("推流成功",""+pamp);
XdySdk.setAsyncApi("publishVideo",pamp);
}
}
} catch (Exception e) {
XdyLogUtil.e("调用任务了播视频了e", "" + e.getMessage());
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
@Override
protected void onDestroy() {
super.onDestroy();
XdySdk.onPlayStop();
}
@OnClick({R.id.btn_videoPlay_chat, R.id.btn_videoPlay_pubsherVideo})
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;
}
}
class EventHande implements SmartEventCallback {
@Override
public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) {
switch (code) {
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:
Log.i(TAG, "开始。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:
Log.i(TAG, "连接中。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:
Log.i(TAG, "连接失败。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:
Log.i(TAG, "连接成功。。");
// PublisherEntity publisherEntity=new PublisherEntity();
// if(TextUtils.isEmpty(publisherSuccess)) {
// publisherEntity.setPublishUrl(publisherSuccess);
// XdySdk.setAsyncApi("publishVideo", new Gson().toJson(publisherEntity));
// }
//TODO
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
Log.i(TAG, "连接断开。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
Log.i(TAG, "关闭。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
Log.i(TAG, "收不到媒体数据,可能是url错误。。");
}
}
}
class EventHande_Video implements SmartEventCallback {
@Override
public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) {
switch (code) {
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:
Log.i(TAG, "开始。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:
Log.i(TAG, "连接中。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:
Log.i(TAG, "连接失败。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:
Log.i(TAG, "连接成功。。");
//TODO
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
Log.i(TAG, "连接断开。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
Log.i(TAG, "关闭。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
Log.i(TAG, "收不到媒体数据,可能是url错误。。");
}
}
}
class PersonDialog extends Dialog {
public PersonDialog(Context context) {
this(context, false);
}
public PersonDialog(Context context, boolean showPwd) {
this(context, R.style.bottom_dialog, showPwd);
}
public PersonDialog(Context context, int themeResId, boolean showPwd) {
super(context, themeResId);
init(context, showPwd);
}
public void init(Context context, boolean showPwd) {
View view = View.inflate(context, R.layout.dialog_item, null);
setContentView(view);
initView(view,showPwd);
setCanceledOnTouchOutside(false);
Window window = getWindow();
WindowManager.LayoutParams params = window.getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = dp2px(context, 220);
window.setAttributes(params);
window.setGravity(Gravity.CENTER);
}
public int dp2px(Context context, float dp) {
return (int) Math.ceil(context.getResources().getDisplayMetrics().density * dp);
}
public void initView(View view, final boolean showPwd){
final EditText edt_uername= (EditText) view.findViewById(R.id.dialog_edt_username);
final EditText edt_userpwd= (EditText) view.findViewById(R.id.dialog_edt_userpwd);
if(showPwd){
edt_userpwd.setVisibility(View.VISIBLE);
}else{
edt_userpwd.setVisibility(View.GONE);
}
Button btn_enter= (Button) view.findViewById(R.id.dialog_btn_enter);
btn_enter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
username=edt_uername.getText().toString();
userpwd=edt_userpwd.getText().toString();
if(TextUtils.isEmpty(username)){
ToastUtil.showToastshort("用户名不能为空",VideoPublisherActivity.this);
return;
}
if(showPwd&&TextUtils.isEmpty(userpwd)){
ToastUtil.showToastshort("密码不能为空",VideoPublisherActivity.this);
return;
}
dismiss();
Message message=Message.obtain();
message.what=-2;
message.obj=showPwd;
handler.sendMessage(message);
}
});
}
}
}
... ...
package com.mang.xdy.demo.adapter;
/**
* Created by huang on 2017/4/9.
*/
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import com.mang.xdy.demo.fragment.PageFragment;
public class SimpleFragmentPagerAdapter extends FragmentPagerAdapter {
final int PAGE_COUNT = 3;
private String tabTitles[] = new String[]{"tab1","tab2","tab3"};
private Context context;
public SimpleFragmentPagerAdapter(FragmentManager fm,Context context) {
super(fm);
this.context = context;
}
@Override
public Fragment getItem(int position) {
return PageFragment.newInstance(position + 1);
}
@Override
public int getCount() {
return PAGE_COUNT;
}
@Override
public CharSequence getPageTitle(int position) {
return tabTitles[position];
}
}
\ No newline at end of file
... ...
package com.mang.xdy.demo.application;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import com.mang.xdy.core.XdySdk;
/**
* Created by abao on 2017/3/30.
*/
public class XdyApplicaiton extends Application {
private static Activity activityList;
private static Context context;
@Override
public void onCreate() {
super.onCreate();
context=this;
XdySdk.init(this);
}
public static Activity getActivity(){
return activityList;
}
public static void setActivity(Activity activity){
activityList=activity;
}
public static Context getInstance(){
return context;
}
}
... ...
package com.mang.xdy.demo.bean;
/**
* Created by huang on 2017/4/9.
*/
public class AudioPlayBean {
/**
* mediaId : 983041
* fromNodeId : 253252
* 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
* replay : http://127.0.0.1:6001/live/h5dev_403074980_0_983041_1488258462/total.m3u8
*/
private int mediaId;
private int fromNodeId;
private int seek;
private String rtmpUrl;
private String m3u8Url;
private String replay;
public int getMediaId() {
return mediaId;
}
public void setMediaId(int mediaId) {
this.mediaId = mediaId;
}
public int getFromNodeId() {
return fromNodeId;
}
public void setFromNodeId(int fromNodeId) {
this.fromNodeId = fromNodeId;
}
public int getSeek() {
return seek;
}
public void setSeek(int seek) {
this.seek = seek;
}
public String getRtmpUrl() {
return rtmpUrl;
}
public void setRtmpUrl(String rtmpUrl) {
this.rtmpUrl = rtmpUrl;
}
public String getM3u8Url() {
return m3u8Url;
}
public void setM3u8Url(String m3u8Url) {
this.m3u8Url = m3u8Url;
}
public String getReplay() {
return replay;
}
public void setReplay(String replay) {
this.replay = replay;
}
}
... ...
package com.mang.xdy.demo.bean;
/**
* Created by huang on 2017/4/9.
*/
public class ChatBean {
/**
* fromNodeId : 1484207995
* toNodeId : 0
* message : Hello world!
* fromName : MyName
* fromRole : normal
*/
private int fromNodeId;
private int toNodeId;
private String message;
private String fromName;
private String fromRole;
public int getFromNodeId() {
return fromNodeId;
}
public void setFromNodeId(int fromNodeId) {
this.fromNodeId = fromNodeId;
}
public int getToNodeId() {
return toNodeId;
}
public void setToNodeId(int toNodeId) {
this.toNodeId = toNodeId;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getFromName() {
return fromName;
}
public void setFromName(String fromName) {
this.fromName = fromName;
}
public String getFromRole() {
return fromRole;
}
public void setFromRole(String fromRole) {
this.fromRole = fromRole;
}
}
... ...
package com.mang.xdy.demo.bean;
/**
* Created by huang on 2017/4/9.
*/
public class DocEntity {
/**
* itemIdx : 749428394
* owner : 747132023
* from : 747132023
* curPageNo : 1
* pageNum : 1
* fileType : jpg
* creatUserId : 0
* relativeUrl : /DocSharing/data/1087553281/20170409-204600041/d32594763768243bddc64934be5088a0.jpg
* url :
* curV : 0
* curH : 0
* scale : 100
* visible : true
* action : 1
* docId : 8ab3b0ed5b4fb08d015b52bf009e0b7e
* fileName : 19462408_171130083000_2.jpg
* dynamicTS : 0
* md5 :
* showType : 0
*/
private int itemIdx;
private int owner;
private int from;
private int curPageNo;
private int pageNum;
private String fileType;
private String creatUserId;
private String relativeUrl;
private String url;
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;
public int getItemIdx() {
return itemIdx;
}
public void setItemIdx(int itemIdx) {
this.itemIdx = itemIdx;
}
public int getOwner() {
return owner;
}
public void setOwner(int owner) {
this.owner = owner;
}
public int getFrom() {
return from;
}
public void setFrom(int from) {
this.from = from;
}
public int getCurPageNo() {
return curPageNo;
}
public void setCurPageNo(int curPageNo) {
this.curPageNo = curPageNo;
}
public int getPageNum() {
return pageNum;
}
public void setPageNum(int pageNum) {
this.pageNum = pageNum;
}
public String getFileType() {
return fileType;
}
public void setFileType(String fileType) {
this.fileType = fileType;
}
public String getCreatUserId() {
return creatUserId;
}
public void setCreatUserId(String creatUserId) {
this.creatUserId = creatUserId;
}
public String getRelativeUrl() {
return relativeUrl;
}
public void setRelativeUrl(String relativeUrl) {
this.relativeUrl = relativeUrl;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public int getCurV() {
return curV;
}
public void setCurV(int curV) {
this.curV = curV;
}
public int getCurH() {
return curH;
}
public void setCurH(int curH) {
this.curH = curH;
}
public int getScale() {
return scale;
}
public void setScale(int scale) {
this.scale = scale;
}
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
public int getAction() {
return action;
}
public void setAction(int action) {
this.action = action;
}
public String getDocId() {
return docId;
}
public void setDocId(String docId) {
this.docId = docId;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getDynamicTS() {
return dynamicTS;
}
public void setDynamicTS(String dynamicTS) {
this.dynamicTS = dynamicTS;
}
public String getMd5() {
return md5;
}
public void setMd5(String md5) {
this.md5 = md5;
}
public int getShowType() {
return showType;
}
public void setShowType(int showType) {
this.showType = showType;
}
}
... ...
package com.mang.xdy.demo.bean;
/**
* Created by abao on 2017/4/10.
*/
public class InitClassSuccessEntity {
/**
* siteId : h5test
* passwordRequired : true
* userRole : normal
* classId : 222333
* userId : 0
* userName :
* classType : 1
*/
private String siteId;
private boolean passwordRequired;
private String userRole;
private int classId;
private String userId;
private String userName;
private int classType;
public String getSiteId() {
return siteId;
}
public void setSiteId(String siteId) {
this.siteId = siteId;
}
public boolean isPasswordRequired() {
return passwordRequired;
}
public void setPasswordRequired(boolean passwordRequired) {
this.passwordRequired = passwordRequired;
}
public String getUserRole() {
return userRole;
}
public void setUserRole(String userRole) {
this.userRole = userRole;
}
public int getClassId() {
return classId;
}
public void setClassId(int classId) {
this.classId = classId;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public int getClassType() {
return classType;
}
public void setClassType(int classType) {
this.classType = classType;
}
}
... ...
package com.mang.xdy.demo.bean;
/**
* Created by abao on 2017/4/10. 加入课堂
*/
public class JoinClass {
/**
* userName : 小明
* password : 123321
* hasCamera : false
* hasMicrophone : false
*/
private String userName;
private String password;
private boolean hasCamera;
private boolean hasMicrophone;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public boolean isHasCamera() {
return hasCamera;
}
public void setHasCamera(boolean hasCamera) {
this.hasCamera = hasCamera;
}
public boolean isHasMicrophone() {
return hasMicrophone;
}
public void setHasMicrophone(boolean hasMicrophone) {
this.hasMicrophone = hasMicrophone;
}
}
... ...
package com.mang.xdy.demo.bean;
/**
* Created by huang on 2017/4/9.
*/
public class JoinClassBean {
/**
* classId : 123456
* portal : 127.0.0.1:80
* userRole : normal
* userName :
* userId : 0
*/
private int classId;
private String portal;
private String userRole;
private String userName;
private int userId;
public int getClassId() {
return classId;
}
public void setClassId(int classId) {
this.classId = classId;
}
public String getPortal() {
return portal;
}
public void setPortal(String portal) {
this.portal = portal;
}
public String getUserRole() {
return userRole;
}
public void setUserRole(String userRole) {
this.userRole = userRole;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
}
... ...
package com.mang.xdy.demo.bean;
/**
* Created by abao on 2017/4/10.
*/
public class JoinClassSuccessEntity {
/**
* docServer : 101.200.150.192:80
* classId : 526661904
* h5Module : 0
* isHost : false
* maxAudioChannels : 1
* maxVideoChannels : 1
* maxMediaChannels : 2
* mcuDelay : 3000
* msType : 1
* nodeId : 613317321
* password : 222222
* passwordRequired : true
* role : 1
* siteId : h5test
* topNodeID : 101
* userId : 0
* userName : mcuTest1486613317
* userRole : normal
* classType : 1
* classTimestamp : 10
* recordPlaybackMaxTime : 0
*/
private String docServer;
private int classId;
private int h5Module;
private boolean isHost;
private int maxAudioChannels;
private int maxVideoChannels;
private int maxMediaChannels;
private int mcuDelay;
private int msType;
private int nodeId;
private String password;
private boolean passwordRequired;
private int role;
private String siteId;
private int topNodeID;
private String userId;
private String userName;
private String userRole;
private int classType;
private int classTimestamp;
private int recordPlaybackMaxTime;
public String getDocServer() {
return docServer;
}
public void setDocServer(String docServer) {
this.docServer = docServer;
}
public int getClassId() {
return classId;
}
public void setClassId(int classId) {
this.classId = classId;
}
public int getH5Module() {
return h5Module;
}
public void setH5Module(int h5Module) {
this.h5Module = h5Module;
}
public boolean isIsHost() {
return isHost;
}
public void setIsHost(boolean isHost) {
this.isHost = isHost;
}
public int getMaxAudioChannels() {
return maxAudioChannels;
}
public void setMaxAudioChannels(int maxAudioChannels) {
this.maxAudioChannels = maxAudioChannels;
}
public int getMaxVideoChannels() {
return maxVideoChannels;
}
public void setMaxVideoChannels(int maxVideoChannels) {
this.maxVideoChannels = maxVideoChannels;
}
public int getMaxMediaChannels() {
return maxMediaChannels;
}
public void setMaxMediaChannels(int maxMediaChannels) {
this.maxMediaChannels = maxMediaChannels;
}
public int getMcuDelay() {
return mcuDelay;
}
public void setMcuDelay(int mcuDelay) {
this.mcuDelay = mcuDelay;
}
public int getMsType() {
return msType;
}
public void setMsType(int msType) {
this.msType = msType;
}
public int getNodeId() {
return nodeId;
}
public void setNodeId(int nodeId) {
this.nodeId = nodeId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public boolean isPasswordRequired() {
return passwordRequired;
}
public void setPasswordRequired(boolean passwordRequired) {
this.passwordRequired = passwordRequired;
}
public int getRole() {
return role;
}
public void setRole(int role) {
this.role = role;
}
public String getSiteId() {
return siteId;
}
public void setSiteId(String siteId) {
this.siteId = siteId;
}
public int getTopNodeID() {
return topNodeID;
}
public void setTopNodeID(int topNodeID) {
this.topNodeID = topNodeID;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserRole() {
return userRole;
}
public void setUserRole(String userRole) {
this.userRole = userRole;
}
public int getClassType() {
return classType;
}
public void setClassType(int classType) {
this.classType = classType;
}
public int getClassTimestamp() {
return classTimestamp;
}
public void setClassTimestamp(int classTimestamp) {
this.classTimestamp = classTimestamp;
}
public int getRecordPlaybackMaxTime() {
return recordPlaybackMaxTime;
}
public void setRecordPlaybackMaxTime(int recordPlaybackMaxTime) {
this.recordPlaybackMaxTime = recordPlaybackMaxTime;
}
}
... ...
package com.mang.xdy.demo.bean;
/**
* Created by abao on 2017/4/7.
*/
public class LiveBean {
/**
* code : 0
* data :
* publishUrl : rtmp: 123.56.205.116: 6000/live/h5dev_1184939098_0_983041_1491555151
*/
private int code;
private String data;
private String publishUrl;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public String getPublishUrl() {
return publishUrl;
}
public void setPublishUrl(String publishUrl) {
this.publishUrl = publishUrl;
}
}
... ...
package com.mang.xdy.demo.bean;
/**
* Created by abao on 2017/4/10.
*/
public class PublisherEntity {
/**
* publishUrl :
*/
private String publishUrl;
public String getPublishUrl() {
return publishUrl;
}
public void setPublishUrl(String publishUrl) {
this.publishUrl = publishUrl;
}
}
... ...
package com.mang.xdy.demo.bean;
// FIXME generate failure method set and get MediaId
// FIXME generate failure field _$Replay151
// FIXME generate failure field _$RtmpUrl165
// FIXME generate failure field _$M3u8Url177
// FIXME generate failure field _$UserName168
/**
* Created by huang on 2017/4/9.
*/
public class VideoPlayBean {
/**
* mediaId : 983041
* fromNodeId : 735605646
* userName : base
* m3u8Url : http://123.56.73.119:6001/live/h5dev_1184939098_980_983041_1491735653/index.m3u8
* rtmpUrl : rtmp://123.56.205.116:6000/live/h5dev_1184939098_980_983041_1491735653
* replay : http://123.56.73.119:6001/live/h5dev_1184939098_980_983041_1491735653/total.m3u8
* seek : 0
*/
private int mediaId;
private int fromNodeId;
private String userName;
private String m3u8Url;
private String rtmpUrl;
private String replay;
private int seek;
public int getMediaId() {
return mediaId;
}
public void setMediaId(int mediaId) {
this.mediaId = mediaId;
}
public int getFromNodeId() {
return fromNodeId;
}
public void setFromNodeId(int fromNodeId) {
this.fromNodeId = fromNodeId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getM3u8Url() {
return m3u8Url;
}
public void setM3u8Url(String m3u8Url) {
this.m3u8Url = m3u8Url;
}
public String getRtmpUrl() {
return rtmpUrl;
}
public void setRtmpUrl(String rtmpUrl) {
this.rtmpUrl = rtmpUrl;
}
public String getReplay() {
return replay;
}
public void setReplay(String replay) {
this.replay = replay;
}
public int getSeek() {
return seek;
}
public void setSeek(int seek) {
this.seek = seek;
}
}
... ...
package com.mang.xdy.demo.fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.mang.xdy.demo.R;
/**
* Created by huang on 2017/4/9.
*/
public class PageFragment extends Fragment {
public static final String ARG_PAGE = "ARG_PAGE";
private int mPage;
public static PageFragment newInstance(int page) {
Bundle args = new Bundle();
args.putInt(ARG_PAGE, page);
PageFragment pageFragment = new PageFragment();
pageFragment.setArguments(args);
return pageFragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPage = getArguments().getInt(ARG_PAGE);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_page, container, false);
TextView textView = (TextView) view;
textView.setText("Fragment #" + mPage);
return view;
}
}
\ No newline at end of file
... ...
package com.mang.xdy.demo.utils;
import android.text.TextUtils;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.json.JSONException;
import org.json.JSONObject;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 封装的是使用Gson解析json的方法
*
* @author Administrator
*/
public class JsonUtil {
private static final String TAG = JsonUtil.class.getSimpleName();
/**
* 把一个map变成json字符串
*
* @param map
* @return
*/
public static String parseMapToJson(Map<?, ?> map) {
try {
Gson gson = new Gson();
return gson.toJson(map);
} catch (Exception e) {
}
return null;
}
public static String parseListToJson(List<?> list) {
try {
Gson gson = new Gson();
return gson.toJson(list);
} catch (Exception e) {
}
return null;
}
/**
* 把一个json字符串变成对象
*
* @param json
* @param cls
* @return
*/
public static <T> T parseJsonToBean(String json, Class<T> cls) {
Gson gson = new Gson();
T t = null;
try {
t = gson.fromJson(json, cls);
} catch (Exception e) {
Log.e(TAG,e.getMessage());
e.printStackTrace();
}
return t;
}
/**
* 把json字符串变成map
*
* @param json
* @return
*/
public static HashMap<String, Object> parseJsonToMap(String json) {
Gson gson = new Gson();
Type type = new TypeToken<HashMap<String, Object>>() {
}.getType();
HashMap<String, Object> map = null;
try {
map = gson.fromJson(json, type);
} catch (Exception e) {
}
return map;
}
/**
* 把json字符串变成集合
* params: new TypeToken<List<yourbean>>(){}.getType(),
*
* @param json
* @param type new TypeToken<List<yourbean>>(){}.getType()
* @return
*/
public static List<?> parseJsonToList(String json, Type type) {
Gson gson = new Gson();
List<?> list = gson.fromJson(json, type);
return list;
}
/**
* 获取json串中某个字段的值,注意,只能获取同一层级的value
*
* @param json
* @param key
* @return
*/
public static String getFieldValue(String json, String key) {
if (TextUtils.isEmpty(json))
return null;
if (!json.contains(key))
return "";
JSONObject jsonObject = null;
String value = null;
try {
jsonObject = new JSONObject(json);
value = jsonObject.getString(key);
} catch (JSONException e) {
e.printStackTrace();
}
return value;
}
}
... ...
package com.mang.xdy.demo.utils;
import android.content.Context;
import android.widget.Toast;
public class ToastUtil {
private static Toast toast;
/**
* 没有延迟的吐司,可连点
*
* @param text
*/
public static void showToast(String text, Context context) {
if (toast == null) {
toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
} else {
// LinearLayout linearLayout = (LinearLayout) toast.getView();
// TextView messageTextView = (TextView) linearLayout.getChildAt(0);
// messageTextView.setTextSize(15);
toast.setText(text);//如果不为空,则直接改变当前toast的文本
}
toast.show();
}
/**
* 短吐司
*
* @param text
* @param context
*/
public static void showToastshort(String text, Context context) {
try {
if (toast == null) {
toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
} else {
toast.setText(text);//如果不为空,则直接改变当前toast的文本
}
toast.show();
}catch (Exception e){
}
}
}
... ...
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
** Copyright 2010, The Android Open Source Project
**
** 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.
*/
-->
<accelerateInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:factor="1.5" />
... ...
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
** Copyright 2010, The Android Open Source Project
**
** 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.
*/
-->
<accelerateInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:factor="2.5" />
... ...
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
** Copyright 2010, The Android Open Source Project
**
** 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.
*/
-->
<decelerateInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:factor="1.5" />
... ...
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
** Copyright 2010, The Android Open Source Project
**
** 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.
*/
-->
<decelerateInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:factor="2.5" />
... ...
<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/res/anim/fade_in.xml
**
** Copyright 2007, The Android Open Source Project
**
** 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.
*/
-->
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromYDelta="10%" android:toYDelta="0"
android:interpolator="@anim/decelerate_quint"
android:duration="@android:integer/config_shortAnimTime"/>
<alpha android:fromAlpha="0.5" android:toAlpha="1.0"
android:interpolator="@anim/decelerate_cubic"
android:duration="@android:integer/config_shortAnimTime" />
</set>
... ...
<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/res/anim/fade_out.xml
**
** Copyright 2007, The Android Open Source Project
**
** 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.
*/
-->
<set
android:shareInterpolator="false"
xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="0" android:toYDelta="10%"
android:interpolator="@anim/accelerate_quint"
android:duration="@android:integer/config_shortAnimTime"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
android:interpolator="@anim/accelerate_cubic"
android:duration="@android:integer/config_shortAnimTime"/>
</set>
... ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.mang.xdy.demo.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="课堂Id"
/>
<EditText
android:id="@+id/edt_home_classId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1184939098"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="角色"/>
<EditText
android:id="@+id/edt_home_role"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="normal"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="服务器地址"
/>
<EditText
android:id="@+id/edt_home_serviceIp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="112.126.80.182:90"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="用户id"
/>
<EditText
android:id="@+id/edt_home_userId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0"
/>
<Button
android:id="@+id/btn_home_enter_class"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="进入课堂"
/>
<Button
android:id="@+id/btn_home_enter_publisher"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="推流服务"
/>
</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"
android:id="@+id/activity_video_play"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.mang.xdy.demo.activity.VideoPlayActivity">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<SurfaceView
android:id="@+id/surfaceview_playVideo"
android:layout_width="match_parent"
android:layout_height="300dp" />
<ImageView
android:id="@+id/img_playVideo_novideo"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@mipmap/novideo"
/>
</RelativeLayout>
<SurfaceView
android:id="@+id/surfaceview_pubisherVideo"
android:layout_width="match_parent"
android:layout_height="120dp"
android:visibility="gone"/>
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/white" />
<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"
/>
<Button
android:id="@+id/btn_videoPlay_pubsherVideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:text="获取推流地址"
/>
</LinearLayout>
</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"
android:id="@+id/activity_video_play"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.mang.xdy.demo.activity.VideoPlayActivity">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
>
<SurfaceView
android:id="@+id/surfaceview_playVideo"
android:layout_width="match_parent"
android:layout_height="200dp"
android:visibility="gone"/>
<ImageView
android:id="@+id/img_playVideo_novideo"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@mipmap/novideo"
/>
</RelativeLayout>
<SurfaceView
android:id="@+id/surfaceview_pubisherVideo"
android:layout_width="match_parent"
android:layout_height="300dp" />
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/white" />
<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:text="获取推流地址"
/>
</LinearLayout>
</LinearLayout>
... ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:gravity="center"
android:background="#ffffff"
android:layout_height="wrap_content">
<EditText
android:id="@+id/dialog_edt_username"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:hint="用户名"/>
<EditText
android:id="@+id/dialog_edt_userpwd"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:hint="密码"/>
<Button
android:id="@+id/dialog_btn_enter"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="登录"
/>
</LinearLayout>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
\ No newline at end of file
... ...
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
<dimen name="activity_horizontal_margin">64dp</dimen>
</resources>
... ...
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
... ...
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
... ...
<resources>
<string name="app_name">学点云</string>
</resources>
... ...
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="bottom_dialog" parent="android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowAnimationStyle">@style/Animation_Bottom_Dialog</item>
</style>
<style name="Animation_Bottom_Dialog">
<item name="android:windowEnterAnimation">@anim/input_method_enter</item>
<item name="android:windowExitAnimation">@anim/input_method_exit</item>
</style>
</resources>
... ...
package com.mang.xdy.demo;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
... ...
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "xdycom.abao.myapplication"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// ndk {
// // 设置支持的SO库架构
// abiFilters 'arm64-v8a' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
// }
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
repositories {
flatDir {
dirs 'libs'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.0'
testCompile 'junit:junit:4.12'
compile project(':xdy')
compile 'com.tencent.bugly:crashreport:2.5.0'
compile 'com.google.code.gson:gson:2.7'
compile'com.android.support:design:22.2.0'
}
... ...
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\admin\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
... ...
package xdycom.abao.myapplication;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("xdycom.abao.myapplication", appContext.getPackageName());
}
}
... ...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xdycom.abao.myapplication">
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name=".application.MyApplicaiton"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Threeivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyService"
android:enabled="true"
android:exported="true" />
<activity android:name=".SecondActivity" />
<activity android:name=".MainActivity" />
<activity android:name=".LunchActivity" />
<activity android:name="com.daniulive.smartplayer.SmartPlayer" />
<activity android:name=".WebviewActivity"></activity>
</application>
</manifest>
\ No newline at end of file
... ...
package xdycom.abao.myapplication;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.Toast;
import xdycom.abao.myapplication.application.MyApplicaiton;
import xdycom.abao.myapplication.utisl.StringUtils;
import xdycom.abao.myapplication.utisl.XdyWebView;
public class LunchActivity extends AppCompatActivity implements View.OnClickListener{
private Button bt_start;
private MyWebView myWebView;
WebView webView;
private final static String URL="http://h5.test.3mang.com/web/";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lunch);
bt_start= (Button) this.findViewById(R.id.bt_start);
bt_start.setOnClickListener(this);
init();
// initData();
}
public void init (){
bt_start= (Button) this.findViewById(R.id.bt_start);
bt_start.setOnClickListener(this);
// myWebView= (MyWebView) this.findViewById(R.id.mywebview);
}
public void initData(){
myWebView=new MyWebView(this);
myWebView.setWebChromeClient(new WebChromeClient(){
});
myWebView.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
myWebView.loadUrl(URL);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
Log.e("webview","errorCode"+errorCode);
}
});
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.bt_start:
// initClass();
// initClass();
inidwebView();
break;
}
}
/**
* 初始化课堂
*/
public void initClass(){
View view= LayoutInflater.from(this).inflate(R.layout.activity_main,null);
webView= (WebView) view.findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient(){
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
}
});
webView.setWebChromeClient(new WebChromeClient(){
@Override
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
super.onConsoleMessage(message, lineNumber, sourceID);
Log.e(null,"Message:"+message+" lineNumber:");
}
});
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new MyJs(),"xdyAndroid" );
webView.loadUrl(URL);
String id="init";
String jsonParmps="{\n" +
" \"classId\": 527720984,\n" +
" \"portal\": \"112.126.80.182:90\",\n" +
" \"userRole\": \"normal\",\n" +
" \"userName\": \"\",\n" +
" \"userId\": 0\n" +
"}";
String jsonParmp= StringUtils.stringToJson(jsonParmps,true);
_native2js(id,jsonParmp);
}
class MyJs {
@JavascriptInterface
public String _js2native(String id,String parmp){
/* _native2js("接口名称","参数为JOSN字符串")*/
Log.e("js2native","id:"+id+" parmp:"+parmp);
return parmp;
}
@JavascriptInterface
public String _js2native(String parmp){
/* _native2js("接口名称","参数为JOSN字符串")*/
Log.e("js2native", " parmp:"+parmp);
return parmp;
}
}
public String _native2js( String id, String parmp) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.evaluateJavascript("javascript:_native2js('" + id + "','" + parmp + "')", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
Log.e("显示:界面","啊哈");
}
});
} else {
// mWebView.loadUrl("javascript:imageVal('init')");
}
}
return "";
}
public void inidwebView(){
WebView xdyWebView=new WebView(this);
xdyWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
return super.shouldOverrideUrlLoading(view, request);
}
});
xdyWebView.getSettings().setJavaScriptEnabled(true);//支持Html5标签
xdyWebView.getSettings().setDomStorageEnabled(true);//支持Html5标签
xdyWebView.addJavascriptInterface(new MyJs(),"xdyAndroid");
xdyWebView.loadUrl(URL);
String id="init";
String jsonParmps="{\n" +
" \"classId\": 527720984,\n" +
" \"portal\": \"112.126.80.182:90\",\n" +
" \"userRole\": \"normal\",\n" +
" \"userName\": \"\",\n" +
" \"userId\": 0\n" +
"}";
String jsonParmp= StringUtils.stringToJson(jsonParmps,true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
xdyWebView.evaluateJavascript("javascript:_native2js('" + id + "','" + jsonParmp + "')", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
Log.e("显示:界面","啊哈");
}
});
} else {
xdyWebView.loadUrl("javascript:imageVal('init')");
}
}
}
... ...
package xdycom.abao.myapplication;
import android.app.Application;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.webkit.ConsoleMessage;
import android.webkit.JavascriptInterface;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.Toast;
import xdycom.abao.myapplication.application.MyApplicaiton;
import xdycom.abao.myapplication.sdk.GetRtmp;
import xdycom.abao.myapplication.sdk.MessageType;
import static xdycom.abao.myapplication.sdk.MessageType.CLASS_INIT_SUCCESS;
/**
* 3.28 目前获取能初始化成功,注意需要对传入进来的jso需要n进行护处理,
* 遗漏:获取js返回值的时候接受方法有问题。。。
* 现在坑爹的需要布局的情况得到了解决,下步开始封装了
*/
public class MainActivity extends AppCompatActivity {
private WebView mWebView;
private Button bt_getScorce,bt_initClass,bt_class,bt_text;
private final static String URL="http://h5.test.3mang.com/web/";
private boolean isFirst=false;
private EditText et_text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView= (WebView) this.findViewById(R.id.webview);
bt_getScorce= (Button) this.findViewById(R.id.bt_getScorce);
bt_initClass= (Button) this.findViewById(R.id.bt_initClass);
et_text= (EditText) this.findViewById(R.id.et_text);
bt_class= (Button) this.findViewById(R.id.bt_class);
bt_text= (Button) this.findViewById(R.id.bt_text);
init();
}
public void init(){
WebSettings webSettings=mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(new MyJs(),"xdyAndroid");
mWebView.loadUrl(URL);
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
Log.e("webview", message + " -- From line " + lineNumber + " of " + sourceID);
String id="";
String jsonParmp="";
//需要解析
// switch(message){
// case "class_init_success":
if(!isFirst) {
// id = "joinClass";
// String temp = "{\n" +
// " \"userName\": \"\",\n" +
// " \"password\": \"\",\n" +
// " \"hasCamera\": true,\n" +
// " \"hasMicrophone\": true\n" +
// "}";
// jsonParmp = stringToJson(temp, true);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// mWebView.evaluateJavascript("javascript:_native2js('" + id + "','" + jsonParmp + "')", new ValueCallback<String>() {
// @Override
// public void onReceiveValue(String value) {
// Toast.makeText(MainActivity.this, "回调调用js" +
// "" + value, Toast.LENGTH_SHORT).show();
// }
// });
// } else {
//
// mWebView.loadUrl("javascript:imageVal('init')");
// }
// break;
// }
isFirst=true;
}
}
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
return super.onConsoleMessage(consoleMessage);
}
});
bt_getScorce.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//// (1).ios/android调用: _native2js("接口名称","参数为JOSN字符串")
//// (2).sdk发送消息给ios/android: _js2native("事件消息名称","参数为JOSN字符串")
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// mWebView.evaluateJavascript("javascript:_native2js('" + interfaceName + ",'" + content + "')", new ValueCallback<String>() {
// @Override
// public void onReceiveValue(String value) {
// Toast.makeText(MainActivity.this,"回调调用js" +
// ""+value, Toast.LENGTH_SHORT).show();
//
// }
// });
// } else {
// mWebView.loadUrl("javascript:_native2js('" + interfaceName + ",'" + content + "')");
// }
GetRtmp getRtmp=new GetRtmp(MainActivity.this);
// String jsonParmp="{\n" +
// " \"classId\": 527720984,\n" +
// " \"portal\": \"127.0.0.1:80\",\n" +
// " \"userRole\": \"normal\",\n" +
// " \"userName\": \"\",\n" +
// " \"userId\": 0\n" +
// "}"
// ;
// String rtmpString=getRtmp._native2js("init",jsonParmp);
// Log.e("rtmpString:",jsonParmp);
// Toast.makeText(MainActivity.this,rtmpString+"",Toast.LENGTH_LONG).show();
String joinClass="{\n" +
" \"userName\": \"base\",\n" +
" \"password\": \"123456\",\n" +
" \"hasCamera\": false,\n" +
" \"hasMicrophone\": false\n" +
"}";
// String rtmpString_joinClass=getRtmp._native2js("class_init_success","");
// Log.e("rtmpString_joinClass:",joinClass);
// Toast.makeText(MainActivity.this,rtmpString_joinClass+"",Toast.LENGTH_SHORT).show();
String id="init";
String jsonParmps="{\n" +
" \"classId\": 527720984,\n" +
" \"portal\": \"112.126.80.182:90\",\n" +
" \"userRole\": \"normal\",\n" +
" \"userName\": \"\",\n" +
" \"userId\": 0\n" +
"}";
String jsonParmp=stringToJson(jsonParmps,true);
Log.e("转化后的json:",""+jsonParmp);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mWebView.evaluateJavascript("javascript:_native2js('" + id + "','"+jsonParmp+"')", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
Toast.makeText(MainActivity.this, "回调调用js" +
"" + value, Toast.LENGTH_SHORT).show();
}
});
}else{
mWebView.loadUrl("javascript:imageVal('init')");
}
}
});
bt_initClass.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String id="";
String jsonParmp="";
id = "joinClass";
String temp = "{\n" +
" \"userName\":\"base\",\n" +
" \"password\":\"123321\",\n" +
" \"hasCamera\":false,\n" +
" \"hasMicrophone\":false}";
// id = "chat_receive_message";
// String temp = "{\"fromNodeId\": 772410521,\n" +
// " \"toNodeId\": 0,\n" +
// " \"message\": \"Hello world!\",\n" +
// " \"fromName\": \"MyName\",\n" +
// " \"fromRole\": \"normal\"\n" +
// "}";
jsonParmp = stringToJson(temp, true);
GetRtmp getRtmp=new GetRtmp(MainActivity.this);
getRtmp._native2js(id,jsonParmp);
_native2js(id,jsonParmp);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// mWebView.evaluateJavascript("javascript:_native2js('" + id + "','" + jsonParmp + "')", new ValueCallback<String>() {
// @Override
// public void onReceiveValue(String value) {
// Toast.makeText(MainActivity.this, "回调调用js" +
// "" + value, Toast.LENGTH_SHORT).show();
// }
// });
// } else {
//
// mWebView.loadUrl("javascript:imageVal('init')");
// }
}
});
bt_class.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String id= et_text.getText().toString();
// String id= "sendStartClass";
if(TextUtils.isEmpty(id)){
id="video_play";
}
id="video_play";
_native2js(id);
_native2js(id,"");
// String id;
// id = "chat_receive_message";
//// id = "sendChatMsg";
//
// String temp = "{\"fromNodeId\": 772410521,\n" +
// " \"toNodeId\": 0,\n" +
// " \"message\": \"Helloss world!\",\n" +
// " \"fromName\": \"base\",\n" +
// " \"fromRole\": \"normal\"\n" +
// "}";
//// String temp = "{ \"message\":\"Helloss world!\",\n" +
//// " \"to\":772410521}";
// String jsonParmp;
// jsonParmp = stringToJson(temp, true);
// _native2js(id,jsonParmp);
}
});
bt_text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String id="init";
String jsonParmps="{\n" +
" \"classId\": 527720984,\n" +
" \"portal\": \"112.126.80.182:90\",\n" +
" \"userRole\": \"normal\",\n" +
" \"userName\": \"\",\n" +
" \"userId\": 0\n" +
"}";
String jsonParmp=stringToJson(jsonParmps,true);
GetRtmp getRtmp=new GetRtmp(MainActivity.this);
getRtmp._native2js(id,jsonParmp);
}
});
}
class MyJs {
@JavascriptInterface
public String _js2native(String id,String parmp){
/* _native2js("接口名称","参数为JOSN字符串")*/
Log.e("js2native","id:"+id+" parmp:"+parmp);
return parmp;
}
@JavascriptInterface
public String _js2native(String parmp){
/* _native2js("接口名称","参数为JOSN字符串")*/
Log.e("js2native", " parmp:"+parmp);
return parmp;
}
}
public static String stringToJson(String s,boolean isJSjson){
StringBuffer sb = new StringBuffer();
for(int i=0; i<s.length(); i++){
char c =s.charAt(i);
switch(c){
case'\'': if(isJSjson) {sb.append("\\\'");}else{sb.append("\'");} break;
case'\"': if(!isJSjson) {sb.append("\\\"");}else{sb.append("\"");} break;
case'\\':sb.append("\\\\"); break; //如果不处理单引号,可以释放此段代码,若结合StringDanYinToJSON()处理单引号就必须注释掉该段代码
case'/': sb.append("\\/");break;
case'\b':sb.append("\\b");break;//退格
case'\f':sb.append("\\f");break;//走纸换页
case'\n':sb.append("\\n");break;//换行
case'\r':sb.append("\\r");break;//回车
case'\t':sb.append("\\t");break;//横向跳格
default: sb.append(c);
}}
return sb.toString();
}
/**
* 获取推流地址
* @return
*/
public String _native2js( String id, String parmp) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mWebView.evaluateJavascript("javascript:_native2js('" + id + "','" + parmp + "')", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
Toast.makeText(MainActivity.this, "回调调用js" +
"" + value, Toast.LENGTH_SHORT).show();
}
});
} else {
// mWebView.loadUrl("javascript:imageVal('init')");
}
}
return "";
}
/**
* 获取推流地址 一个参数
* @return
*/
public String _native2js( String id) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mWebView.evaluateJavascript("javascript:_native2js('" + id + "')", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
Toast.makeText(MainActivity.this, "回调调用js" +
"" + value, Toast.LENGTH_SHORT).show();
}
});
} else {
// mWebView.loadUrl("javascript:imageVal('init')");
}
}
return "";
}
}
... ...
package xdycom.abao.myapplication;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class MyService extends Service {
public MyService() {
}
private static MainActivity INSTANCE;
public static MainActivity getINSTANCE(){
return INSTANCE;
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
super.onDestroy();
}
}
... ...
package xdycom.abao.myapplication;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.webkit.ValueCallback;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Toast;
/**
* Created by abao on 2017/3/30.
*/
public class MyWebView extends WebView {
private final static String URL="http://h5.test.3mang.com/web/";
public MyWebView(Context context) {
super(context);
// myWebView=new MyWebView(context);
// WebSettings webSettings=myWebView.getSettings();
// webSettings.setJavaScriptEnabled(true);
// myWebView.addJavascriptInterface(new MyJs(),"xdyAndroid");
//
// myWebView.loadUrl(URL);
}
public MyWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
class MyJs {
@JavascriptInterface
public String _js2native(String id,String parmp){
/* _native2js("接口名称","参数为JOSN字符串")*/
Log.e("js2native","id:"+id+" parmp:"+parmp);
return parmp;
}
@JavascriptInterface
public String _js2native(String parmp){
/* _native2js("接口名称","参数为JOSN字符串")*/
Log.e("js2native", " parmp:"+parmp);
return parmp;
}
}
/**
* 获取推流地址
* @return
*/
public String _native2js( String id, String parmp) {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// myWebView.evaluateJavascript("javascript:_native2js('" + id + "','" + parmp + "')", new ValueCallback<String>() {
// @Override
// public void onReceiveValue(String value) {
// Log.e("MSG_evaluate","_native2js"+value);
// }
// });
// } else {
//
//// mWebView.loadUrl("javascript:imageVal('init')");
// }
return "";
}
}
... ...
package xdycom.abao.myapplication;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.ValueCallback;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.Toast;
import xdycom.abao.myapplication.application.MyApplicaiton;
import xdycom.abao.myapplication.utisl.StringUtils;
import xdycom.abao.myapplication.view.WebViewBase;
public class SecondActivity extends AppCompatActivity {
WebView webViewBase;
private final static String URL="http://h5.test.3mang.com/web/";
private Button bt_class;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
bt_class= (Button) this.findViewById(R.id.bt_class);
bt_class.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String id="init";
String jsonParmps="{\n" +
" \"classId\": 527720984,\n" +
" \"portal\": \"112.126.80.182:90\",\n" +
" \"userRole\": \"normal\",\n" +
" \"userName\": \"\",\n" +
" \"userId\": 0\n" +
"}";
String jsonParmp= StringUtils.stringToJson(jsonParmps,true);
Log.e("转化后的json:",""+jsonParmp);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webViewBase.evaluateJavascript("javascript:_native2js('" + id + "','"+jsonParmp+"')", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
Toast.makeText(SecondActivity.this, "回调调用js" +
"" + value, Toast.LENGTH_SHORT).show();
}
});
}else{
webViewBase.loadUrl("javascript:imageVal('init')");
}
}
});
init();
}
public void init(){
webViewBase=new WebView(MyApplicaiton.getInstance());
WebSettings webSettings=webViewBase.getSettings();
webSettings.setJavaScriptEnabled(true);
// webViewBase.setWebViewClient(new WebViewClient(){
// @Override
// public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
// return super.shouldOverrideUrlLoading(view, request);
// }
// });
webViewBase.addJavascriptInterface(new MyJs(),"xdyAndroid");
webViewBase.loadUrl(URL);
}
class MyJs {
@JavascriptInterface
public String _js2native(String id,String parmp){
/* _native2js("接口名称","参数为JOSN字符串")*/
Log.e("s3sjs2native","id:"+id+" parmp:"+parmp);
return parmp;
}
@JavascriptInterface
public String _js2native(String parmp){
/* _native2js("接口名称","参数为JOSN字符串")*/
Log.e("js2native", " parmp:"+parmp);
return parmp;
}
}
}
... ...
package xdycom.abao.myapplication;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import com.eventhandle.SmartEventCallback;
import com.google.gson.Gson;
import com.mang.xdy.core.XdySdk;
import com.mang.xdy.utils.XdyLogUtil;
import com.mang.xdy.utils.XdyStringUtils;
import xdycom.abao.myapplication.entity.LiveBean;
import xdycom.abao.myapplication.utisl.StringUtils;
import static xdycom.abao.myapplication.MainActivity.stringToJson;
public class Threeivity extends AppCompatActivity implements View.OnClickListener{
private Button bt_three,bt_video
,bt_paudio,bt_stopaudiopub,bt_back,bt_stopReco;
private WebView webView;
private final static String URL="http://h5.test.3mang.com/web/";
private SurfaceView surface;
private Button bt_stop;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_threeivity);
bt_three= (Button) findViewById(R.id.bt_three);
bt_video= (Button) findViewById(R.id.bt_video);
surface= (SurfaceView) findViewById(R.id.surface);
bt_stop= (Button) findViewById(R.id.bt_stop);
bt_paudio= (Button) findViewById(R.id.bt_paudio);
bt_paudio.setOnClickListener(this);
bt_stopaudiopub= (Button) findViewById(R.id.bt_stopaudiopub);
bt_back= (Button) findViewById(R.id.bt_back);
bt_back.setOnClickListener(this);
bt_stopaudiopub.setOnClickListener(this);
bt_stopReco= (Button) findViewById(R.id.bt_stopReco);
bt_stopReco.setOnClickListener(this);
bt_three.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String id="init";
String jsonParmps="{\n" +
" \"classId\": 1184939098,\n" +
" \"portal\": \"112.126.80.182:90\",\n" +
" \"userRole\": \"normal\",\n" +
" \"userName\": \"\",\n" +
" \"userId\": 0\n" +
"}";
String jsonParmp= StringUtils.stringToJson(jsonParmps,true);
getSdySdk(id,jsonParmp);
}
});
bt_video.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String id = "joinClass";
String temp = "{\n" +
" \"userName\":\"base\",\n" +
" \"password\":\"123321\",\n" +
" \"hasCamera\":false,\n" +
" \"hasMicrophone\":false}";
// "}";
String jsonParmp = stringToJson(temp, true);
getSdySdk(id,jsonParmp);
// SmartPlayerNoLayout smartPlayerNoLayout=new SmartPlayerNoLayout(surface, Threeivity.this);
// startActivity(new Intent(Threeivity.this,SmartPlayer.class));
String url= "rtmp://123.56.205.116:6000/live/h5dev_1999957388_980_983041_1491813919";;
//// XdyPlayerCore xdyPlayer=new XdyPlayerCore(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.setAsyncApi("publishVideo",url,surface,Threeivity.this,new EventHande());
// xdyPlayer.playVideo("",surface);
// XdyPublisherCore xdyPublisherCore=new XdyPublisherCore(Threeivity.this);
// xdyPublisherCore.publish("",surface);
}
});
bt_stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
XdySdk.onPlayStop();
// XdySdk.onPublisherStop();;
}
});
init();
}
public void init(){
webView=new WebView(this);
WebSettings settings=webView.getSettings();
settings.setJavaScriptEnabled(true);
webView.addJavascriptInterface(new MyJsH(),"xdyAndroid");
webView.loadUrl(URL);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.bt_paudio:
//开始推送音频
String url= "rtmp://player.daniulive.com:1935/hls/stream";;
XdySdk.setAsyncApi("publishAudio",url,surface,Threeivity.this);
break;
case R.id.bt_stopaudiopub:
//停止
// XdySdk.setAsyncApi("unPublishAudio","");
String id="initRecordPlayback";
// String id="startRecordPlayback";
String param="{\n" +
" \"classId\": 479270427 ,\n" +
" \"portal\": \"112.126.80.182:90\",\n" +
" \"userRole\": \"normal\",\n" +
" \"userName\": \"\",\n" +
" \"userId\": 0\n" +
"}";
String ss=StringUtils.stringToJson(param,true);
XdySdk.setAsyncApi(id,ss);
break;
case R.id.bt_back:
// String id="initRecordPlayback";
String ids="startRecordPlayback";
// String param="{\n" +
// " \"classId\": 1184939098,\n" +
// " \"portal\": \"112.126.80.182:90\",\n" +
// " \"userRole\": \"normal\",\n" +
// " \"userName\": \"\",\n" +
// " \"userId\": 0\n" +
// "}";
// String ss=StringUtils.stringToJson(param,true);
XdySdk.setAsyncApi(ids,"");
break;
case R.id.bt_stopReco:
// String isd="stopRecordPlayback";
// XdySdk.setAsyncApi(isd,"");
// String ids_new="seekRecordPlayback";
// String tem="{\n" +
// " \"time\": 50\n" +
// "}";
// String s= StringUtils.stringToJson(tem,true);
// XdySdk.setAsyncApi(ids_new,s);
String ids_new="getVideoPublishPath";
String tem="{ \"type\": \"live\"}";
String s= StringUtils.stringToJson(tem,true);
XdySdk.setAsyncApi(ids_new,s);
break;
}
}
class MyJsH{
@JavascriptInterface
public String _js2native(String id,String parmp){
/* _native2js("接口名称","参数为JOSN字符串")*/
Log.e("s3sjs2native","id:"+id+" parmp:"+parmp);
return parmp;
}
}
public void getSdySdk(String id,String parameter){
// XdyCore core=XdyCore.getInstance(MyApplicaiton.getInstance());
// core.native2js(id,parameter);
// core.setXdyAsyncMessageListener(new XdyCore.XdyAsyncMessageListener() {
// @Override
// public void getSdyAsyncMessageListener(String s, String s1) {
// LogUtil.e("java_native",s+":"+s1);
// }
// });
XdySdk.setAsyncApi(id,parameter);
// XdySdk.getXdyInstance().setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
// @Override
// public void onXdyAsyncMessageReceiver(String type, String response) {
// XdyLogUtil.e("学点云",type+":"+response);
// }
// });
XdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
@Override
public void onXdyAsyncMessageReceiver(String type, String response) {
XdyLogUtil.e("学点云static", type + ":" + response);
// if ("video_play".equals(type)) {
// MessageBean messageBean = new Gson().fromJson(response, MessageBean.class);
// if (messageBean != null) {
//// Intent intent = new Intent(Threeivity.this, SmartPlayer.class);
//// intent.putExtra("url", messageBean.getRtmpUrl() + "");
//// startActivity(intent);
// Toast.makeText(Threeivity.this, messageBean.getRtmpUrl(), Toast.LENGTH_SHORT).show();
//// SmartPlayerNoLayout smartPlayerNoLayout=new SmartPlayerNoLayout(surface,Threeivity.this);
// }
// }
if("live".equals(type)){
// String urls= "rtmp://player.daniulive.com:1935/hls/stream";;
String url = XdyStringUtils.stringToJson(response);
XdyLogUtil.e("调用任务了播视频了url:",""+url);
String us=response.substring(1,response.length()-1);
XdyLogUtil.e("调用任务了播视频了ursfdfl:",""+us);
try {
LiveBean liveBean = new Gson().fromJson(url, LiveBean.class);
if (liveBean != null) {
XdySdk.setAsyncApi("publishVideo", liveBean.getPublishUrl(), surface, Threeivity.this);
XdyLogUtil.e("调用任务了播视频了","哈哈哈哈");
}
}catch (Exception e){
XdyLogUtil.e("调用任务了播视频了e",""+e.getMessage());
XdyLogUtil.e("调用任务了播视频了url:",""+url);
}
}
}
});
}
public void playMedia(){
Intent intent = new Intent(Intent.ACTION_VIEW);
String bpath = "http://123.56.73.119:6001/live/h5dev_1184939098_980_983041_1491533378/total.m3u8";
intent.setDataAndType(Uri.parse(bpath), "video/*");
startActivity(intent);
}
}
class EventHande implements SmartEventCallback {
private static String TAG="THREURL";
@Override
public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) {
switch (code) {
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:
Log.i(TAG, "开始。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:
Log.i(TAG, "连接中。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:
Log.i(TAG, "连接失败。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:
Log.i(TAG, "连接成功。。");
//TODO
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
Log.i(TAG, "连接断开。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
Log.i(TAG, "关闭。。");
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
break;
case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
Log.i(TAG, "收不到媒体数据,可能是url错误。。");
}
}
}
... ...
package xdycom.abao.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
public class WebviewActivity extends AppCompatActivity {
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
mWebView= (WebView) this.findViewById(R.id.webview);
WebSettings webSettings=mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
// mWebView.addJavascriptInterface(new XdyJavaScript(), APIContants.NATIVE_JS_LINK);
mWebView.setWebChromeClient(new WebChromeClient(){
@Override
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
super.onConsoleMessage(message, lineNumber, sourceID);
Log.e("浏览器message",message+"linumber"+lineNumber+"sourceId"+sourceID);
}
});
mWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
return super.shouldOverrideUrlLoading(view, request);
}
});
mWebView.loadUrl("http://10.118.1.155:8080/?classId=2006998200&userId=980&userName=base&userRole=normal&portalIP=112.126.80.182&portalPort=90&m=136d61bd4648286c40445b29acbd7edc");
}
}
... ...
package xdycom.abao.myapplication;
/**
* Created by abao on 2017/3/30.
*/
import android.content.Context;
import android.os.Build;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import com.mang.xdy.core.APIContants;
import com.mang.xdy.utils.XdyLogUtil;
/**
* 需要提供两个参数的接口,一个参数的接口,同时给出回调(或者广播的方式)
* 数据的异常检测都放在最外层(便于给用户提示),这层默认数据都是完整
* 核心WebView 处理和调用的js
*/
public class XdyCore {
private WebView mWebView;
private static XdyCore mXdyCore;
/**
* 异步对外回调接口,所有回调都在此完成
*/
protected interface OnXdyAsyncMessageListener {
void getSdyAsyncMessageListener(String id, String parameter);
};
private OnXdyAsyncMessageListener mOnXdyAsyncMessageListener;
/**
* 设置Async监听
* @param onXdyAsyncMessageListener
*/
protected void setXdyAsyncMessageListener(OnXdyAsyncMessageListener onXdyAsyncMessageListener){
mOnXdyAsyncMessageListener = onXdyAsyncMessageListener;
}
private XdyCore(Context context) {
if(context==null){
return;
}
init(context);
}
/**
* 初始化
* @param context
*/
protected void init(Context context){
mWebView=new WebView(context);
WebSettings webSettings=mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
// mWebView.addJavascriptInterface(new XdyJavaScript(), APIContants.NATIVE_JS_LINK);
mWebView.setWebChromeClient(new WebChromeClient(){
@Override
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
super.onConsoleMessage(message, lineNumber, sourceID);
Log.e("浏览器message",message+"linumber"+lineNumber+"sourceId"+sourceID);
}
});
mWebView.loadUrl("http://10.118.1.155:8080/?classId=2006998200&userId=980&userName=base&userRole=normal&portalIP=112.126.80.182&portalPort=90&m=136d61bd4648286c40445b29acbd7edc");
}
/**
* 获取XdyCore实例
* @param context
* @return
*/
protected final static XdyCore getInstance(Context context){
if(mXdyCore==null){
synchronized(XdyCore.class){
if(mXdyCore==null){
mXdyCore=new XdyCore(context);
}
}
}
return mXdyCore;
}
/**
* 异步Js2Native
*/
protected class XdyJavaScript{
@JavascriptInterface
public void _js2native(String id,String parmp){
/* _native2js("接口名称","参数为JOSN字符串")*/
XdyLogUtil.e("s3sjs2native","id:"+id+" parmp:"+parmp);
if(mOnXdyAsyncMessageListener !=null){
mOnXdyAsyncMessageListener.getSdyAsyncMessageListener(id,parmp);
}
}
}
/**
* native调用js
* @param id
* @param parameter
*/
protected void native2js(String id,String parameter){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mWebView.evaluateJavascript("javascript:_native2js('" + id + "','"+parameter+"')", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
}
});
}else{
mWebView.loadUrl("javascript:_native2js('" + id + "','"+parameter+"')");
}
}
}
... ...
package xdycom.abao.myapplication.application;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import com.mang.xdy.core.XdySdk;
import com.tencent.bugly.crashreport.CrashReport;
/**
* Created by abao on 2017/3/30.
*/
public class MyApplicaiton extends Application {
private static Activity activityList;
private static Context context;
@Override
public void onCreate() {
super.onCreate();
context=this;
XdySdk.init(this);
CrashReport.initCrashReport(getApplicationContext(), "注册时申请的APPID", false);
}
public static Activity getActivity(){
return activityList;
}
public static void setActivity(Activity activity){
activityList=activity;
}
public static Context getInstance(){
return context;
}
}
... ...
package xdycom.abao.myapplication.entity;
/**
* Created by abao on 2017/4/7.
*/
public class LiveBean {
/**
* code : 0
* data :
* publishUrl : rtmp: 123.56.205.116: 6000/live/h5dev_1184939098_0_983041_1491555151
*/
private int code;
private String data;
private String publishUrl;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public String getPublishUrl() {
return publishUrl;
}
public void setPublishUrl(String publishUrl) {
this.publishUrl = publishUrl;
}
}
... ...
package xdycom.abao.myapplication.entity;
/**
* Created by admin on 2017/3/28.
*/
public class MessageBean {
/**
* mediaId : 983041
* fromNodeId : 952527798
* userName : base
* m3u8Url : http://123.56.73.119:6001/live/h5dev_1184939098_980_983041_1490952529/index.m3u8
* rtmpUrl : rtmp://123.56.69.230:6000/live/h5dev_1184939098_980_983041_1490952529
* replay : http://123.56.73.119:6001/live/h5dev_1184939098_980_983041_1490952529/total.m3u8
* seek : 0
*/
private int mediaId;
private int fromNodeId;
private String userName;
private String m3u8Url;
private String rtmpUrl;
private String replay;
private int seek;
public int getMediaId() {
return mediaId;
}
public void setMediaId(int mediaId) {
this.mediaId = mediaId;
}
public int getFromNodeId() {
return fromNodeId;
}
public void setFromNodeId(int fromNodeId) {
this.fromNodeId = fromNodeId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getM3u8Url() {
return m3u8Url;
}
public void setM3u8Url(String m3u8Url) {
this.m3u8Url = m3u8Url;
}
public String getRtmpUrl() {
return rtmpUrl;
}
public void setRtmpUrl(String rtmpUrl) {
this.rtmpUrl = rtmpUrl;
}
public String getReplay() {
return replay;
}
public void setReplay(String replay) {
this.replay = replay;
}
public int getSeek() {
return seek;
}
public void setSeek(int seek) {
this.seek = seek;
}
}
... ...