huangxinbao

Android sdk目录 和测试demo目

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

要显示太多修改。

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

  1 +*.iml
  2 +.gradle
  3 +/local.properties
  4 +/.idea/workspace.xml
  5 +/.idea/libraries
  6 +.DS_Store
  7 +/build
  8 +/captures
  9 +.externalNativeBuild
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="CompilerConfiguration">
  4 + <resourceExtensions />
  5 + <wildcardResourcePatterns>
  6 + <entry name="!?*.java" />
  7 + <entry name="!?*.form" />
  8 + <entry name="!?*.class" />
  9 + <entry name="!?*.groovy" />
  10 + <entry name="!?*.scala" />
  11 + <entry name="!?*.flex" />
  12 + <entry name="!?*.kt" />
  13 + <entry name="!?*.clj" />
  14 + <entry name="!?*.aj" />
  15 + </wildcardResourcePatterns>
  16 + <annotationProcessing>
  17 + <profile default="true" name="Default" enabled="false">
  18 + <processorPath useClasspath="true" />
  19 + </profile>
  20 + </annotationProcessing>
  21 + </component>
  22 +</project>
  1 +<component name="CopyrightManager">
  2 + <settings default="" />
  3 +</component>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="GradleSettings">
  4 + <option name="linkedExternalProjectsSettings">
  5 + <GradleProjectSettings>
  6 + <option name="distributionType" value="LOCAL" />
  7 + <option name="externalProjectPath" value="$PROJECT_DIR$" />
  8 + <option name="gradleHome" value="C:\Program Files\Android\Android Studio\gradle\gradle-2.14.1" />
  9 + <option name="modules">
  10 + <set>
  11 + <option value="$PROJECT_DIR$" />
  12 + <option value="$PROJECT_DIR$/XdyDemo" />
  13 + <option value="$PROJECT_DIR$/app" />
  14 + <option value="$PROJECT_DIR$/easeUI_CN" />
  15 + <option value="$PROJECT_DIR$/myapplication2" />
  16 + <option value="$PROJECT_DIR$/mylibrary" />
  17 + <option value="$PROJECT_DIR$/sdklibraryssss" />
  18 + <option value="$PROJECT_DIR$/smartPlayer" />
  19 + <option value="$PROJECT_DIR$/xdy" />
  20 + </set>
  21 + </option>
  22 + <option name="resolveModulePerSourceSet" value="false" />
  23 + </GradleProjectSettings>
  24 + </option>
  25 + </component>
  26 +</project>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="EntryPointsManager">
  4 + <entry_points version="2.0" />
  5 + </component>
  6 + <component name="NullableNotNullManager">
  7 + <option name="myDefaultNullable" value="android.support.annotation.Nullable" />
  8 + <option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
  9 + <option name="myNullables">
  10 + <value>
  11 + <list size="4">
  12 + <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
  13 + <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
  14 + <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
  15 + <item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
  16 + </list>
  17 + </value>
  18 + </option>
  19 + <option name="myNotNulls">
  20 + <value>
  21 + <list size="4">
  22 + <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
  23 + <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
  24 + <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
  25 + <item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
  26 + </list>
  27 + </value>
  28 + </option>
  29 + </component>
  30 + <component name="ProjectLevelVcsManager" settingsEditedManually="false">
  31 + <OptionsSetting value="true" id="Add" />
  32 + <OptionsSetting value="true" id="Remove" />
  33 + <OptionsSetting value="true" id="Checkout" />
  34 + <OptionsSetting value="true" id="Update" />
  35 + <OptionsSetting value="true" id="Status" />
  36 + <OptionsSetting value="true" id="Edit" />
  37 + <ConfirmationsSetting value="0" id="Add" />
  38 + <ConfirmationsSetting value="0" id="Remove" />
  39 + </component>
  40 + <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">
  41 + <output url="file://$PROJECT_DIR$/build/classes" />
  42 + </component>
  43 + <component name="ProjectType">
  44 + <option name="id" value="Android" />
  45 + </component>
  46 +</project>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="ProjectModuleManager">
  4 + <modules>
  5 + <module fileurl="file://$PROJECT_DIR$/MyApplication.iml" filepath="$PROJECT_DIR$/MyApplication.iml" />
  6 + <module fileurl="file://$PROJECT_DIR$/XdyDemo/XdyDemo.iml" filepath="$PROJECT_DIR$/XdyDemo/XdyDemo.iml" />
  7 + <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
  8 + <module fileurl="file://$PROJECT_DIR$/easeUI_CN/easeUI_CN.iml" filepath="$PROJECT_DIR$/easeUI_CN/easeUI_CN.iml" />
  9 + <module fileurl="file://$PROJECT_DIR$/myapplication2/myapplication2.iml" filepath="$PROJECT_DIR$/myapplication2/myapplication2.iml" />
  10 + <module fileurl="file://$PROJECT_DIR$/mylibrary/mylibrary.iml" filepath="$PROJECT_DIR$/mylibrary/mylibrary.iml" />
  11 + <module fileurl="file://$PROJECT_DIR$/sdklibraryssss/sdklibraryssss.iml" filepath="$PROJECT_DIR$/sdklibraryssss/sdklibraryssss.iml" />
  12 + <module fileurl="file://$PROJECT_DIR$/smartPlayer/smartPlayer.iml" filepath="$PROJECT_DIR$/smartPlayer/smartPlayer.iml" />
  13 + <module fileurl="file://$PROJECT_DIR$/xdy/xdy.iml" filepath="$PROJECT_DIR$/xdy/xdy.iml" />
  14 + </modules>
  15 + </component>
  16 +</project>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="RunConfigurationProducerService">
  4 + <option name="ignoredProducers">
  5 + <set>
  6 + <option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
  7 + <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
  8 + <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
  9 + </set>
  10 + </option>
  11 + </component>
  12 +</project>
  1 +apply plugin: 'com.android.application'
  2 +
  3 +android {
  4 + compileSdkVersion 25
  5 + buildToolsVersion '25.0.2'
  6 +
  7 + defaultConfig {
  8 + applicationId "com.mang.xdy.demo"
  9 + minSdkVersion 15
  10 + targetSdkVersion 25
  11 + versionCode 1
  12 + versionName "1.0"
  13 +
  14 + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  15 +
  16 + }
  17 + buildTypes {
  18 + release {
  19 + minifyEnabled false
  20 + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  21 + }
  22 + }
  23 + repositories {
  24 + flatDir {
  25 + dirs 'libs'
  26 + }
  27 + }
  28 +}
  29 +
  30 +dependencies {
  31 + compile fileTree(include: ['*.jar'], dir: 'libs')
  32 + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
  33 + exclude group: 'com.android.support', module: 'support-annotations'
  34 + })
  35 + compile 'com.android.support:appcompat-v7:25.3.1'
  36 + testCompile 'junit:junit:4.12'
  37 + compile 'com.jakewharton:butterknife:8.5.1'
  38 + annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
  39 + compile project(':xdy')
  40 + compile 'com.google.code.gson:gson:2.7'
  41 + compile 'com.android.support:design:23.4.0'
  42 +}
  1 +# Add project specific ProGuard rules here.
  2 +# By default, the flags in this file are appended to flags specified
  3 +# in D:\sdk/tools/proguard/proguard-android.txt
  4 +# You can edit the include path and order by changing the proguardFiles
  5 +# directive in build.gradle.
  6 +#
  7 +# For more details, see
  8 +# http://developer.android.com/guide/developing/tools/proguard.html
  9 +
  10 +# Add any project specific keep options here:
  11 +
  12 +# If your project uses WebView with JS, uncomment the following
  13 +# and specify the fully qualified class name to the JavaScript interface
  14 +# class:
  15 +#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
  16 +# public *;
  17 +#}
  1 +package com.mang.xdy.demo;
  2 +
  3 +import android.content.Context;
  4 +import android.support.test.InstrumentationRegistry;
  5 +import android.support.test.runner.AndroidJUnit4;
  6 +
  7 +import org.junit.Test;
  8 +import org.junit.runner.RunWith;
  9 +
  10 +import static org.junit.Assert.*;
  11 +
  12 +/**
  13 + * Instrumentation test, which will execute on an Android device.
  14 + *
  15 + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
  16 + */
  17 +@RunWith(AndroidJUnit4.class)
  18 +public class ExampleInstrumentedTest {
  19 + @Test
  20 + public void useAppContext() throws Exception {
  21 + // Context of the app under test.
  22 + Context appContext = InstrumentationRegistry.getTargetContext();
  23 +
  24 + assertEquals("com.mang.xdy.demo", appContext.getPackageName());
  25 + }
  26 +}
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3 + package="com.mang.xdy.demo">
  4 +
  5 + <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  6 + <uses-permission android:name="android.permission.INTERNET" />
  7 + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  8 + <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  9 + <uses-permission android:name="android.permission.READ_LOGS" />
  10 + <uses-permission android:name="android.permission.CAMERA" />
  11 + <uses-permission android:name="android.permission.RECORD_AUDIO" />
  12 + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  13 +
  14 + <uses-feature android:name="android.hardware.camera" />
  15 + <uses-feature android:name="android.hardware.camera.autofocus" />
  16 +
  17 + <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
  18 + <uses-permission android:name="android.permission.INTERNET" />
  19 + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  20 + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  21 + <uses-permission android:name="android.permission.RECORD_AUDIO" />
  22 + <uses-permission android:name="android.permission.WAKE_LOCK" />
  23 + <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  24 + <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
  25 + <uses-permission android:name="android.permission.CAMERA" />
  26 + <uses-permission android:name="android.permission.VIBRATE" />
  27 +
  28 + <application
  29 + android:name=".application.XdyApplicaiton"
  30 + android:allowBackup="true"
  31 + android:icon="@mipmap/ic_launcher"
  32 + android:label="@string/app_name"
  33 + android:supportsRtl="true"
  34 + android:theme="@style/AppTheme">
  35 + <activity android:name=".MainActivity">
  36 + <intent-filter>
  37 + <action android:name="android.intent.action.MAIN" />
  38 +
  39 + <category android:name="android.intent.category.LAUNCHER" />
  40 + </intent-filter>
  41 + </activity>
  42 + <activity android:name=".activity.VideoPlayActivity" />
  43 + <activity android:name=".activity.VideoPublisherActivity"></activity>
  44 + </application>
  45 +
  46 +</manifest>
  1 +package com.mang.xdy.demo;
  2 +
  3 +import android.content.Intent;
  4 +import android.os.Bundle;
  5 +import android.support.v7.app.AppCompatActivity;
  6 +import android.view.View;
  7 +import android.widget.Button;
  8 +import android.widget.EditText;
  9 +
  10 +import com.google.gson.Gson;
  11 +import com.mang.xdy.demo.activity.VideoPlayActivity;
  12 +import com.mang.xdy.demo.activity.VideoPublisherActivity;
  13 +import com.mang.xdy.demo.bean.JoinClassBean;
  14 +import com.mang.xdy.utils.XdyLogUtil;
  15 +
  16 +import butterknife.BindView;
  17 +import butterknife.ButterKnife;
  18 +import butterknife.OnClick;
  19 +
  20 +public class MainActivity extends AppCompatActivity {
  21 +
  22 + @BindView(R.id.edt_home_classId)
  23 + EditText edtHomeClassId;
  24 + @BindView(R.id.edt_home_role)
  25 + EditText edtHomeRole;
  26 + @BindView(R.id.edt_home_serviceIp)
  27 + EditText edtHomeServiceIp;
  28 + @BindView(R.id.edt_home_userId)
  29 + EditText edtHomeUserId;
  30 + @BindView(R.id.btn_home_enter_class)
  31 + Button btnHomeEnterClass;
  32 + @BindView(R.id.btn_home_enter_publisher)
  33 + Button btn_home_enter_publisher;
  34 + /*一进来就要初始化,让后再调 加入课堂*/
  35 + @Override
  36 + protected void onCreate(Bundle savedInstanceState) {
  37 + super.onCreate(savedInstanceState);
  38 + setContentView(R.layout.activity_main);
  39 + ButterKnife.bind(this);
  40 + }
  41 +
  42 + @OnClick({R.id.btn_home_enter_class,R.id.btn_home_enter_publisher})
  43 + public void onViewClicked(View view) {
  44 + switch (view.getId()){
  45 +
  46 + case R.id.btn_home_enter_class:
  47 + Intent intent=new Intent(MainActivity.this, VideoPlayActivity.class);
  48 + intent.putExtra("init",joinClass());
  49 + startActivity(intent);
  50 + break;
  51 + case R.id.btn_home_enter_publisher:
  52 + Intent intents=new Intent(MainActivity.this, VideoPublisherActivity.class);
  53 + intents.putExtra("init",joinClass());
  54 + startActivity(intents);
  55 + break;
  56 + }
  57 + }
  58 +
  59 + public String joinClass(){
  60 + JoinClassBean joinClassBean=new JoinClassBean();
  61 + joinClassBean.setClassId(Integer.parseInt(edtHomeClassId.getText().toString()));
  62 + joinClassBean.setUserRole(edtHomeRole.getText().toString());
  63 + joinClassBean.setPortal(edtHomeServiceIp.getText().toString());
  64 + joinClassBean.setUserId(Integer.parseInt(edtHomeUserId.getText().toString()));
  65 + joinClassBean.setUserName("");
  66 + String joinclass=new Gson().toJson(joinClassBean);
  67 + XdyLogUtil.e("init 初始化",joinclass);
  68 + return joinclass;
  69 +
  70 + }
  71 +}
  1 +package com.mang.xdy.demo.activity;
  2 +
  3 +import android.app.AlertDialog;
  4 +import android.app.Dialog;
  5 +import android.content.Context;
  6 +import android.content.DialogInterface;
  7 +import android.media.Image;
  8 +import android.os.Bundle;
  9 +import android.os.Handler;
  10 +import android.os.Message;
  11 +import android.support.design.widget.TabLayout;
  12 +import android.support.v4.view.ViewPager;
  13 +import android.support.v7.app.AppCompatActivity;
  14 +import android.text.TextUtils;
  15 +import android.util.Log;
  16 +import android.view.Gravity;
  17 +import android.view.SurfaceView;
  18 +import android.view.View;
  19 +import android.view.Window;
  20 +import android.view.WindowManager;
  21 +import android.widget.Button;
  22 +import android.widget.EditText;
  23 +import android.widget.ImageView;
  24 +import android.widget.TextView;
  25 +import android.widget.Toast;
  26 +
  27 +import com.eventhandle.SmartEventCallback;
  28 +import com.google.gson.Gson;
  29 +import com.mang.xdy.core.XdySdk;
  30 +import com.mang.xdy.demo.R;
  31 +import com.mang.xdy.demo.adapter.SimpleFragmentPagerAdapter;
  32 +import com.mang.xdy.demo.bean.AudioPlayBean;
  33 +import com.mang.xdy.demo.bean.ChatBean;
  34 +import com.mang.xdy.demo.bean.DocEntity;
  35 +import com.mang.xdy.demo.bean.InitClassSuccessEntity;
  36 +import com.mang.xdy.demo.bean.JoinClass;
  37 +import com.mang.xdy.demo.bean.LiveBean;
  38 +import com.mang.xdy.demo.bean.VideoPlayBean;
  39 +import com.mang.xdy.demo.utils.JsonUtil;
  40 +import com.mang.xdy.demo.utils.ToastUtil;
  41 +import com.mang.xdy.utils.XdyLogUtil;
  42 +import com.mang.xdy.utils.XdyStringUtils;
  43 +
  44 +import butterknife.BindView;
  45 +import butterknife.ButterKnife;
  46 +import butterknife.OnClick;
  47 +
  48 +public class VideoPlayActivity extends AppCompatActivity {
  49 + private final static String TAG = "VideoPlayActivity";
  50 + @BindView(R.id.btn_videoPlay_pubsherVideo)
  51 + Button btnVideoPlayPubsherVideo;
  52 + @BindView(R.id.btn_videoPlay_chat)
  53 + Button btnVideoPlayChat;
  54 + @BindView(R.id.tv_videoPlay_url)
  55 + TextView tv_videoPlay_url;
  56 + @BindView(R.id.surfaceview_pubisherVideo)
  57 + SurfaceView surfaceview_pubisherVideo;
  58 + @BindView(R.id.img_playVideo_novideo)
  59 + ImageView img_playVideo_novideo;
  60 + private String username="";
  61 + private String userpwd="";
  62 + private PersonDialog personDialog;
  63 + private SimpleFragmentPagerAdapter pagerAdapter;
  64 +
  65 + private ViewPager viewPager;
  66 +
  67 + private TabLayout tabLayout;
  68 + @BindView(R.id.surfaceview_playVideo)
  69 + SurfaceView surfaceviewPlayVideo;
  70 + private String initClass = "";
  71 + private Handler handler = new Handler() {
  72 + @Override
  73 + public void handleMessage(Message msg) {
  74 + super.handleMessage(msg);
  75 + switch (msg.what) {
  76 + case -2:
  77 + //加入课堂输入用户名,密码
  78 + joinClass("", (Boolean) msg.obj);
  79 + break;
  80 + case -1:
  81 + //退出
  82 + XdySdk.setAsyncApi("leaveClass", "");
  83 + break;
  84 + case 0:
  85 + parseJoinClass((String) msg.obj,true);
  86 + break;
  87 + case 1:
  88 + //播放视频
  89 + playVideo((String) msg.obj);
  90 + XdyLogUtil.e(TAG,"当前线程 handdler:"+android.os.Process.myPid()+""+"线程:"+Thread.currentThread().getId()+"");
  91 + break;
  92 + case 2:
  93 + //播放音频
  94 + playAudio((String) msg.obj);
  95 + break;
  96 + case 3:
  97 + getDoc((String) msg.obj);
  98 + break;
  99 + case 4:
  100 + //发送消息
  101 + sendMeg();
  102 + break;
  103 + case 5:
  104 + //接受消息
  105 + getMsg((String) msg.obj);
  106 + break;
  107 + case 6:
  108 + //推流video
  109 + publisherVideo((String) msg.obj);
  110 + break;
  111 + case 7:
  112 + //停止播放
  113 + XdySdk.onPlayStop();
  114 + img_playVideo_novideo.setVisibility(View.GONE);
  115 +// surfaceviewPlayVideo.refreshDrawableState();;
  116 +// ToastUtil.showToastshort("播放音视/视频停止",VideoPlayActivity.this);
  117 + break;
  118 +
  119 + }
  120 + }
  121 + };
  122 +
  123 + @Override
  124 + protected void onCreate(final Bundle savedInstanceState) {
  125 + super.onCreate(savedInstanceState);
  126 + setContentView(R.layout.activity_video_play);
  127 + ButterKnife.bind(this);
  128 +// setTablayout();
  129 + init();
  130 + XdyLogUtil.e(TAG,"当前线程 main:"+android.os.Process.myPid()+"线程:"+Thread.currentThread().getId()+"");
  131 + XdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
  132 + @Override
  133 + public void onXdyAsyncMessageReceiver(String type, String response) {
  134 + Message message = Message.obtain();
  135 + switch (type) {
  136 + case "class_init_success":
  137 + ToastUtil.showToastshort("初始化课堂成功", VideoPlayActivity.this);
  138 + message.obj = response;
  139 + message.what = 0;
  140 + handler.sendMessage(message);
  141 + break;
  142 + case "class_join_success":
  143 + //加入课堂成功
  144 + ToastUtil.showToastshort("加入课堂成功", VideoPlayActivity.this);
  145 + break;
  146 + case "video_play":
  147 + //播放视频
  148 + XdyLogUtil.e(TAG, "执行了" + response);
  149 + XdyLogUtil.e(TAG,"当前线程 listerne:"+android.os.Process.myPid()+""+"线程:"+Thread.currentThread().getId()+"");
  150 + message.obj = response;
  151 + message.what = 1;
  152 + handler.sendMessage(message);
  153 +
  154 + break;
  155 + case "audio_play":
  156 + //播放音频
  157 + message.obj = response;
  158 + message.what = 2;
  159 + handler.sendMessage(message);
  160 + break;
  161 + case "class_delete_roster":
  162 +// ToastUtil.showToastshort("离开课堂", VideoPlayActivity.this);
  163 + //人员离开
  164 + break;
  165 + case "chat_receive_message":
  166 + //监听聊天信息
  167 + message.obj = response;
  168 + message.what = 5;
  169 + handler.sendMessage(message);
  170 + break;
  171 + case "document_update":
  172 + //监听文档信息
  173 + message.obj = response;
  174 + message.what = 3;
  175 +// handler.sendMessage(message);
  176 + ToastUtil.showToastshort("文档更新" + response, VideoPlayActivity.this);
  177 + break;
  178 + case "whiteboard_annotation_update":
  179 + ToastUtil.showToastshort("白板信息更新" + response, VideoPlayActivity.this);
  180 + break;
  181 + case "live":
  182 +// String urls= "rtmp://player.daniulive.com:1935/hls/stream";;
  183 + //推流直播
  184 +// message.obj = response;
  185 +// message.what = 6;
  186 +// handler.sendMessage(message);
  187 + break;
  188 + case "video_stop":
  189 + handler.sendEmptyMessage(7);
  190 + break;
  191 + case "audio_stop":
  192 +
  193 + break;
  194 + }
  195 + }
  196 + });
  197 + }
  198 +
  199 + public void init() {
  200 + initClass = getIntent().getStringExtra("init");
  201 + XdySdk.setAsyncApi("init", initClass);
  202 +
  203 + }
  204 +
  205 + public void setTablayout() {
  206 + pagerAdapter = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), this);
  207 + viewPager = (ViewPager) findViewById(R.id.viewpager);
  208 + viewPager.setAdapter(pagerAdapter);
  209 + tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
  210 + tabLayout.setupWithViewPager(viewPager);
  211 + tabLayout.setTabMode(TabLayout.MODE_FIXED);
  212 + }
  213 + //判断解析是否有密码
  214 + public void parseJoinClass(String rsponse,boolean isShowPwd){
  215 + InitClassSuccessEntity initClassSuccessEntity=JsonUtil.parseJsonToBean(rsponse,InitClassSuccessEntity.class);
  216 + if(initClassSuccessEntity!=null)
  217 + if(initClassSuccessEntity.isPasswordRequired()){
  218 + personDialog=new PersonDialog(this,true);
  219 + }else{
  220 + personDialog=new PersonDialog(this,false);
  221 + userpwd="123321";
  222 + }
  223 + personDialog.show();
  224 + }
  225 + //加入课堂
  226 + public void joinClass(String rsponse,boolean isShowPwd) {
  227 +
  228 +// String temp = "{\n" +
  229 +// " \"userName\":\"base\",\n" +
  230 +// " \"password\":\"123321\",\n" +
  231 +// " \"hasCamera\":false,\n" +
  232 +// " \"hasMicrophone\":false}";
  233 + JoinClass joinClass=new JoinClass();
  234 + joinClass.setHasCamera(false);
  235 + joinClass.setHasMicrophone(false);
  236 + joinClass.setUserName(username);
  237 + if(!isShowPwd){
  238 + joinClass.setPassword("123321");
  239 + }else{
  240 + joinClass.setPassword(userpwd);
  241 + }
  242 + String temp=new Gson().toJson(joinClass);
  243 + String jsonParmp = XdyStringUtils.stringToJson(temp, true);
  244 + XdyLogUtil.e("加入课堂", jsonParmp);
  245 + XdySdk.setAsyncApi("joinClass", jsonParmp);
  246 + }
  247 +
  248 + public void playVideo(String response) {
  249 + VideoPlayBean videoPlayBean = JsonUtil.parseJsonToBean(response, VideoPlayBean.class);
  250 + if (videoPlayBean != null && videoPlayBean.getRtmpUrl() != null)
  251 + XdyLogUtil.e(TAG, "执行了ss" + videoPlayBean.getRtmpUrl());
  252 + XdySdk.setAsyncApi("playVideo", videoPlayBean.getRtmpUrl(), surfaceviewPlayVideo, VideoPlayActivity.this, new EventHande_Video());
  253 + img_playVideo_novideo.setVisibility(View.GONE);
  254 + ToastUtil.showToastshort("视频播放初始化",VideoPlayActivity.this);
  255 + }
  256 +
  257 + public void playAudio(String response) {
  258 + AudioPlayBean audioPlayBean = JsonUtil.parseJsonToBean(response, AudioPlayBean.class);
  259 + if (audioPlayBean != null && audioPlayBean.getRtmpUrl() != null) {
  260 + XdyLogUtil.e(TAG, "执行了" + audioPlayBean.getRtmpUrl());
  261 + XdySdk.setAsyncApi("playAudio", audioPlayBean.getRtmpUrl(), null, VideoPlayActivity.this, new EventHande_Video());
  262 + img_playVideo_novideo.setVisibility(View.GONE);
  263 + ToastUtil.showToastshort("音频播放初始化",VideoPlayActivity.this);
  264 + }
  265 + }
  266 +
  267 + public void getDoc(String response) {
  268 + DocEntity docEntity = JsonUtil.parseJsonToBean(response, DocEntity.class);
  269 + if (docEntity != null && docEntity.getRelativeUrl() != null) {
  270 +
  271 + String url = docEntity.getRelativeUrl();
  272 + String temp = "{\n" +
  273 + " \"type\": \"jpg\",\n" +
  274 + " \"pageNum\": 1,\n" +
  275 + " \"relativeUrl\": \" '" + url + "'\"\n" +
  276 + "}";
  277 +// String temp = "{\n" +
  278 +// " \"type\": \"jpg\",\n" +
  279 +// " \"pageNum\": 1,\n" +
  280 +// " \"relativeUrl\": \"/DocSharing/data/1087553281/20170409-204600041/d32594763768243bddc64934be5088a0.jpg\"\n" +
  281 +// "}";
  282 +
  283 +
  284 + String jsonParmp = XdyStringUtils.stringToJson(temp, true);
  285 + XdyLogUtil.e(TAG, "文档" + jsonParmp);
  286 + XdySdk.setAsyncApi("getDocImageFullPath", jsonParmp);
  287 + }
  288 + }
  289 +
  290 + public void sendMeg() {
  291 + String temp = "{\n" +
  292 + " \"message\": \"固定发送测试 hello\",\n" +
  293 + " \"to\": 0\n" +
  294 + "}";
  295 + String jsonParmp = XdyStringUtils.stringToJson(temp, true);
  296 + XdyLogUtil.e(TAG, "聊天" + jsonParmp);
  297 + XdySdk.setAsyncApi("sendChatMsg", jsonParmp);
  298 +
  299 + }
  300 +
  301 + //获取聊天信息
  302 + public void getMsg(String msg) {
  303 + ChatBean chatBean = JsonUtil.parseJsonToBean(msg, ChatBean.class);
  304 + if (chatBean != null) {
  305 + btnVideoPlayChat.setText(chatBean.getMessage());
  306 + }
  307 +
  308 + }
  309 +
  310 + //获取推流地址
  311 + public void getPublish() {
  312 + String ids_new = "getVideoPublishPath";
  313 + String tem = "{ \"type\": \"live\"}";
  314 + String s = XdyStringUtils.stringToJson(tem, true);
  315 + XdySdk.setAsyncApi(ids_new, s);
  316 + }
  317 +
  318 + public void publisherVideo(String response) {
  319 + XdySdk.onPlayStop();
  320 + String url = XdyStringUtils.stringToJson(response);
  321 + XdyLogUtil.e("调用任务了播视频了url:", "" + url);
  322 + String us = response.substring(1, response.length() - 1);
  323 + XdyLogUtil.e("调用任务了播视频了ursfdfl:", "" + us);
  324 + try {
  325 + LiveBean liveBean = new Gson().fromJson(url, LiveBean.class);
  326 +
  327 + if (liveBean != null&&liveBean.getCode()==0) {
  328 + String url_text="rtmp://player.daniulive.com:1935/hls/stream";
  329 +// XdySdk.setAsyncApi("publishVideo", liveBean.getPublishUrl(), surfaceviewPlayVideo, VideoPlayActivity.this,new EventHande());
  330 +// tv_videoPlay_url.setText("推流地址:"+liveBean.getPublishUrl());
  331 + tv_videoPlay_url.setText("推流地址:"+url_text);
  332 + XdyLogUtil.e(TAG,liveBean.getPublishUrl());
  333 + XdySdk.setAsyncApi("publishVideo", url_text, surfaceview_pubisherVideo, VideoPlayActivity.this,new EventHande());
  334 + ToastUtil.showToastshort("推流初始化中",VideoPlayActivity.this);
  335 + }
  336 + } catch (Exception e) {
  337 + XdyLogUtil.e("调用任务了播视频了e", "" + e.getMessage());
  338 +
  339 + }
  340 +
  341 + }
  342 +
  343 + @Override
  344 + public void onBackPressed() {
  345 +
  346 + super.onBackPressed();
  347 + }
  348 +
  349 +
  350 +
  351 + @Override
  352 + protected void onDestroy() {
  353 + super.onDestroy();
  354 + XdySdk.onPlayStop();
  355 + }
  356 +
  357 + @OnClick({R.id.btn_videoPlay_chat, R.id.btn_videoPlay_pubsherVideo})
  358 + public void onViewClicked(View view) {
  359 + switch (view.getId()) {
  360 + case R.id.btn_videoPlay_chat:
  361 + handler.sendEmptyMessage(4);
  362 + break;
  363 + case R.id.btn_videoPlay_pubsherVideo:
  364 + getPublish();
  365 + break;
  366 + }
  367 + }
  368 + class EventHande implements SmartEventCallback {
  369 + @Override
  370 + public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) {
  371 + switch (code) {
  372 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:
  373 + Log.i(TAG, "开始。。");
  374 + break;
  375 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:
  376 + Log.i(TAG, "连接中。。");
  377 + break;
  378 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:
  379 + Log.i(TAG, "连接失败。。");
  380 + break;
  381 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:
  382 + Log.i(TAG, "连接成功。。");
  383 + //TODO
  384 + break;
  385 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
  386 + Log.i(TAG, "连接断开。。");
  387 + break;
  388 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
  389 + Log.i(TAG, "关闭。。");
  390 + break;
  391 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
  392 + Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
  393 + break;
  394 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
  395 + Log.i(TAG, "收不到媒体数据,可能是url错误。。");
  396 + }
  397 +
  398 + }
  399 + }
  400 +
  401 +
  402 + class EventHande_Video implements SmartEventCallback {
  403 + @Override
  404 + public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) {
  405 + switch (code) {
  406 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:
  407 + Log.i(TAG, "开始。。");
  408 + break;
  409 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:
  410 + Log.i(TAG, "连接中。。");
  411 + break;
  412 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:
  413 + Log.i(TAG, "连接失败。。");
  414 + break;
  415 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:
  416 + Log.i(TAG, "连接成功。。");
  417 +
  418 + //TODO
  419 + break;
  420 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
  421 + Log.i(TAG, "连接断开。。");
  422 + break;
  423 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
  424 + Log.i(TAG, "关闭。。");
  425 + break;
  426 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
  427 + Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
  428 + break;
  429 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
  430 + Log.i(TAG, "收不到媒体数据,可能是url错误。。");
  431 + }
  432 +
  433 + }
  434 + }
  435 + class PersonDialog extends Dialog {
  436 + public PersonDialog(Context context) {
  437 + this(context, false);
  438 +
  439 + }
  440 +
  441 + public PersonDialog(Context context, boolean showPwd) {
  442 + this(context, R.style.bottom_dialog, showPwd);
  443 + }
  444 +
  445 + public PersonDialog(Context context, int themeResId, boolean showPwd) {
  446 + super(context, themeResId);
  447 + init(context, showPwd);
  448 + }
  449 +
  450 + public void init(Context context, boolean showPwd) {
  451 + View view = View.inflate(context, R.layout.dialog_item, null);
  452 + setContentView(view);
  453 + initView(view,showPwd);
  454 + setCanceledOnTouchOutside(false);
  455 + Window window = getWindow();
  456 + WindowManager.LayoutParams params = window.getAttributes();
  457 + params.width = WindowManager.LayoutParams.MATCH_PARENT;
  458 + params.height = dp2px(context, 220);
  459 + window.setAttributes(params);
  460 + window.setGravity(Gravity.CENTER);
  461 + }
  462 +
  463 + public int dp2px(Context context, float dp) {
  464 + return (int) Math.ceil(context.getResources().getDisplayMetrics().density * dp);
  465 + }
  466 + public void initView(View view, final boolean showPwd){
  467 + final EditText edt_uername= (EditText) view.findViewById(R.id.dialog_edt_username);
  468 + final EditText edt_userpwd= (EditText) view.findViewById(R.id.dialog_edt_userpwd);
  469 + if(showPwd){
  470 + edt_userpwd.setVisibility(View.VISIBLE);
  471 + }else{
  472 + edt_userpwd.setVisibility(View.GONE);
  473 + }
  474 + Button btn_enter= (Button) view.findViewById(R.id.dialog_btn_enter);
  475 + btn_enter.setOnClickListener(new View.OnClickListener() {
  476 + @Override
  477 + public void onClick(View v) {
  478 + username=edt_uername.getText().toString();
  479 + userpwd=edt_userpwd.getText().toString();
  480 + if(TextUtils.isEmpty(username)){
  481 + ToastUtil.showToastshort("用户名不能为空",VideoPlayActivity.this);
  482 + return;
  483 + }
  484 + if(showPwd&&TextUtils.isEmpty(userpwd)){
  485 + ToastUtil.showToastshort("密码不能为空",VideoPlayActivity.this);
  486 + return;
  487 + }
  488 + dismiss();
  489 + Message message=Message.obtain();
  490 + message.what=-2;
  491 + message.obj=showPwd;
  492 + handler.sendMessage(message);
  493 + }
  494 + });
  495 + }
  496 + }
  497 +}
  1 +package com.mang.xdy.demo.activity;
  2 +
  3 + import android.app.AlertDialog;
  4 + import android.app.Dialog;
  5 + import android.content.Context;
  6 + import android.content.DialogInterface;
  7 + import android.media.Image;
  8 + import android.os.Bundle;
  9 + import android.os.Handler;
  10 + import android.os.Message;
  11 + import android.support.design.widget.TabLayout;
  12 + import android.support.v4.view.ViewPager;
  13 + import android.support.v7.app.AppCompatActivity;
  14 + import android.text.TextUtils;
  15 + import android.util.Log;
  16 + import android.view.Gravity;
  17 + import android.view.SurfaceView;
  18 + import android.view.View;
  19 + import android.view.Window;
  20 + import android.view.WindowManager;
  21 + import android.widget.Button;
  22 + import android.widget.EditText;
  23 + import android.widget.ImageView;
  24 + import android.widget.TextView;
  25 + import android.widget.Toast;
  26 +
  27 + import com.eventhandle.SmartEventCallback;
  28 + import com.google.gson.Gson;
  29 + import com.mang.xdy.core.XdySdk;
  30 + import com.mang.xdy.demo.R;
  31 + import com.mang.xdy.demo.adapter.SimpleFragmentPagerAdapter;
  32 + import com.mang.xdy.demo.bean.AudioPlayBean;
  33 + import com.mang.xdy.demo.bean.ChatBean;
  34 + import com.mang.xdy.demo.bean.DocEntity;
  35 + import com.mang.xdy.demo.bean.InitClassSuccessEntity;
  36 + import com.mang.xdy.demo.bean.JoinClass;
  37 + import com.mang.xdy.demo.bean.LiveBean;
  38 + import com.mang.xdy.demo.bean.PublisherEntity;
  39 + import com.mang.xdy.demo.bean.VideoPlayBean;
  40 + import com.mang.xdy.demo.utils.JsonUtil;
  41 + import com.mang.xdy.demo.utils.ToastUtil;
  42 + import com.mang.xdy.utils.XdyLogUtil;
  43 + import com.mang.xdy.utils.XdyStringUtils;
  44 +
  45 + import butterknife.BindView;
  46 + import butterknife.ButterKnife;
  47 + import butterknife.OnClick;
  48 +
  49 +public class VideoPublisherActivity extends AppCompatActivity {
  50 + private final static String TAG = "VideoPlayActivity";
  51 + @BindView(R.id.btn_videoPlay_pubsherVideo)
  52 + Button btnVideoPlayPubsherVideo;
  53 + @BindView(R.id.btn_videoPlay_chat)
  54 + Button btnVideoPlayChat;
  55 + @BindView(R.id.tv_videoPlay_url)
  56 + TextView tv_videoPlay_url;
  57 + @BindView(R.id.surfaceview_pubisherVideo)
  58 + SurfaceView surfaceview_pubisherVideo;
  59 +// @BindView(R.id.img_playVideo_novideo)
  60 +// ImageView img_playVideo_novideo;
  61 + private String username="";
  62 + private String userpwd="";
  63 + private PersonDialog personDialog;
  64 + private SimpleFragmentPagerAdapter pagerAdapter;
  65 +
  66 + private ViewPager viewPager;
  67 +
  68 + private TabLayout tabLayout;
  69 + @BindView(R.id.surfaceview_playVideo)
  70 + SurfaceView surfaceviewPlayVideo;
  71 + private String initClass = "";
  72 + private String publisherSuccess="";
  73 + private Handler handler = new Handler() {
  74 + @Override
  75 + public void handleMessage(Message msg) {
  76 + super.handleMessage(msg);
  77 + switch (msg.what) {
  78 + case -2:
  79 + //加入课堂输入用户名,密码
  80 + joinClass("", (Boolean) msg.obj);
  81 + break;
  82 + case -1:
  83 + //退出
  84 + XdySdk.setAsyncApi("leaveClass", "");
  85 + break;
  86 + case 0:
  87 + parseJoinClass((String) msg.obj,true);
  88 + break;
  89 + case 1:
  90 + //播放视频
  91 + playVideo((String) msg.obj);
  92 + XdyLogUtil.e(TAG,"当前线程 handdler:"+android.os.Process.myPid()+""+"线程:"+Thread.currentThread().getId()+"");
  93 + break;
  94 + case 2:
  95 + //播放音频
  96 + playAudio((String) msg.obj);
  97 + break;
  98 + case 3:
  99 + getDoc((String) msg.obj);
  100 + break;
  101 + case 4:
  102 + //发送消息
  103 + sendMeg();
  104 + break;
  105 + case 5:
  106 + //接受消息
  107 + getMsg((String) msg.obj);
  108 + break;
  109 + case 6:
  110 + //推流video
  111 + publisherVideo((String) msg.obj);
  112 + break;
  113 + case 7:
  114 + //停止播放
  115 + XdySdk.onPlayStop();
  116 +// img_playVideo_novideo.setVisibility(View.GONE);
  117 +// surfaceviewPlayVideo.refreshDrawableState();;
  118 +// ToastUtil.showToastshort("播放音视/视频停止",VideoPlayActivity.this);
  119 + break;
  120 +
  121 + }
  122 + }
  123 + };
  124 +
  125 + @Override
  126 + protected void onCreate(final Bundle savedInstanceState) {
  127 + super.onCreate(savedInstanceState);
  128 + setContentView(R.layout.activity_video_publisher);
  129 + ButterKnife.bind(this);
  130 +// setTablayout();
  131 + init();
  132 + XdyLogUtil.e(TAG,"当前线程 main:"+android.os.Process.myPid()+"线程:"+Thread.currentThread().getId()+"");
  133 + XdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
  134 + @Override
  135 + public void onXdyAsyncMessageReceiver(String type, String response) {
  136 + Message message = Message.obtain();
  137 + switch (type) {
  138 + case "class_init_success":
  139 + ToastUtil.showToastshort("初始化课堂成功", VideoPublisherActivity.this);
  140 + message.obj = response;
  141 + message.what = 0;
  142 + handler.sendMessage(message);
  143 + break;
  144 + case "class_join_success":
  145 + //加入课堂成功
  146 + ToastUtil.showToastshort("加入课堂成功", VideoPublisherActivity.this);
  147 + break;
  148 +// case "video_play":
  149 +// //播放视频
  150 +// XdyLogUtil.e(TAG, "执行了" + response);
  151 +// XdyLogUtil.e(TAG,"当前线程 listerne:"+android.os.Process.myPid()+""+"线程:"+Thread.currentThread().getId()+"");
  152 +// message.obj = response;
  153 +// message.what = 1;
  154 +// handler.sendMessage(message);
  155 +//
  156 +// break;
  157 +// case "audio_play":
  158 +// //播放音频
  159 +// message.obj = response;
  160 +// message.what = 2;
  161 +// handler.sendMessage(message);
  162 +// break;
  163 +// case "class_delete_roster":
  164 +//// ToastUtil.showToastshort("离开课堂", VideoPlayActivity.this);
  165 +// //人员离开
  166 +// break;
  167 +// case "chat_receive_message":
  168 +// //监听聊天信息
  169 +// message.obj = response;
  170 +// message.what = 5;
  171 +// handler.sendMessage(message);
  172 +// break;
  173 +// case "document_update":
  174 +// //监听文档信息
  175 +// message.obj = response;
  176 +// message.what = 3;
  177 +//// handler.sendMessage(message);
  178 +// ToastUtil.showToastshort("文档更新" + response, VideoPublisherActivity.this);
  179 +// break;
  180 +// case "whiteboard_annotation_update":
  181 +// ToastUtil.showToastshort("白板信息更新" + response, VideoPublisherActivity.this);
  182 +// break;
  183 + case "live":
  184 +// String urls= "rtmp://player.daniulive.com:1935/hls/stream";;
  185 + //推流直播
  186 + message.obj = response;
  187 + message.what = 6;
  188 + handler.sendMessage(message);
  189 + break;
  190 + case "video_stop":
  191 +// handler.sendEmptyMessage(7);
  192 + break;
  193 + case "audio_stop":
  194 +
  195 + break;
  196 + }
  197 + }
  198 + });
  199 + }
  200 +
  201 + public void init() {
  202 + initClass = getIntent().getStringExtra("init");
  203 + XdySdk.setAsyncApi("init", initClass);
  204 +
  205 + }
  206 +
  207 + public void setTablayout() {
  208 + pagerAdapter = new SimpleFragmentPagerAdapter(getSupportFragmentManager(), this);
  209 + viewPager = (ViewPager) findViewById(R.id.viewpager);
  210 + viewPager.setAdapter(pagerAdapter);
  211 + tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
  212 + tabLayout.setupWithViewPager(viewPager);
  213 + tabLayout.setTabMode(TabLayout.MODE_FIXED);
  214 + }
  215 + //判断解析是否有密码
  216 + public void parseJoinClass(String rsponse,boolean isShowPwd){
  217 + InitClassSuccessEntity initClassSuccessEntity=JsonUtil.parseJsonToBean(rsponse,InitClassSuccessEntity.class);
  218 + if(initClassSuccessEntity!=null)
  219 + if(initClassSuccessEntity.isPasswordRequired()){
  220 + personDialog=new PersonDialog(this,true);
  221 + }else{
  222 + personDialog=new PersonDialog(this,false);
  223 + userpwd="123321";
  224 + }
  225 + personDialog.show();
  226 + }
  227 + //加入课堂
  228 + public void joinClass(String rsponse,boolean isShowPwd) {
  229 +
  230 +// String temp = "{\n" +
  231 +// " \"userName\":\"base\",\n" +
  232 +// " \"password\":\"123321\",\n" +
  233 +// " \"hasCamera\":false,\n" +
  234 +// " \"hasMicrophone\":false}";
  235 + JoinClass joinClass=new JoinClass();
  236 + joinClass.setHasCamera(false);
  237 + joinClass.setHasMicrophone(false);
  238 + joinClass.setUserName(username);
  239 + if(!isShowPwd){
  240 + joinClass.setPassword("123321");
  241 + }else{
  242 + joinClass.setPassword(userpwd);
  243 + }
  244 + String temp=new Gson().toJson(joinClass);
  245 + String jsonParmp = XdyStringUtils.stringToJson(temp, true);
  246 + XdyLogUtil.e("加入课堂", jsonParmp);
  247 + XdySdk.setAsyncApi("joinClass", jsonParmp);
  248 + }
  249 +
  250 + public void playVideo(String response) {
  251 + VideoPlayBean videoPlayBean = JsonUtil.parseJsonToBean(response, VideoPlayBean.class);
  252 + if (videoPlayBean != null && videoPlayBean.getRtmpUrl() != null)
  253 + XdyLogUtil.e(TAG, "执行了ss" + videoPlayBean.getRtmpUrl());
  254 + XdySdk.setAsyncApi("playVideo", videoPlayBean.getRtmpUrl(), surfaceviewPlayVideo, VideoPublisherActivity.this, new EventHande_Video());
  255 +// img_playVideo_novideo.setVisibility(View.GONE);
  256 + ToastUtil.showToastshort("视频播放初始化",VideoPublisherActivity.this);
  257 + }
  258 +
  259 + public void playAudio(String response) {
  260 + AudioPlayBean audioPlayBean = JsonUtil.parseJsonToBean(response, AudioPlayBean.class);
  261 + if (audioPlayBean != null && audioPlayBean.getRtmpUrl() != null) {
  262 + XdyLogUtil.e(TAG, "执行了" + audioPlayBean.getRtmpUrl());
  263 + XdySdk.setAsyncApi("playAudio", audioPlayBean.getRtmpUrl(), null, VideoPublisherActivity.this, new EventHande_Video());
  264 +// img_playVideo_novideo.setVisibility(View.GONE);
  265 + ToastUtil.showToastshort("音频播放初始化",VideoPublisherActivity.this);
  266 + }
  267 + }
  268 +
  269 + public void getDoc(String response) {
  270 + DocEntity docEntity = JsonUtil.parseJsonToBean(response, DocEntity.class);
  271 + if (docEntity != null && docEntity.getRelativeUrl() != null) {
  272 +
  273 + String url = docEntity.getRelativeUrl();
  274 + String temp = "{\n" +
  275 + " \"type\": \"jpg\",\n" +
  276 + " \"pageNum\": 1,\n" +
  277 + " \"relativeUrl\": \" '" + url + "'\"\n" +
  278 + "}";
  279 +// String temp = "{\n" +
  280 +// " \"type\": \"jpg\",\n" +
  281 +// " \"pageNum\": 1,\n" +
  282 +// " \"relativeUrl\": \"/DocSharing/data/1087553281/20170409-204600041/d32594763768243bddc64934be5088a0.jpg\"\n" +
  283 +// "}";
  284 +
  285 +
  286 + String jsonParmp = XdyStringUtils.stringToJson(temp, true);
  287 + XdyLogUtil.e(TAG, "文档" + jsonParmp);
  288 + XdySdk.setAsyncApi("getDocImageFullPath", jsonParmp);
  289 + }
  290 + }
  291 +
  292 + public void sendMeg() {
  293 + String temp = "{\n" +
  294 + " \"message\": \"固定发送测试 hello\",\n" +
  295 + " \"to\": 0\n" +
  296 + "}";
  297 + String jsonParmp = XdyStringUtils.stringToJson(temp, true);
  298 + XdyLogUtil.e(TAG, "聊天" + jsonParmp);
  299 + XdySdk.setAsyncApi("sendChatMsg", jsonParmp);
  300 +
  301 + }
  302 +
  303 + //获取聊天信息
  304 + public void getMsg(String msg) {
  305 + ChatBean chatBean = JsonUtil.parseJsonToBean(msg, ChatBean.class);
  306 + if (chatBean != null) {
  307 + btnVideoPlayChat.setText(chatBean.getMessage());
  308 + }
  309 +
  310 + }
  311 +
  312 + //获取推流地址
  313 + public void getPublish() {
  314 + String ids_new = "getVideoPublishPath";
  315 + String tem = "{ \"type\": \"live\"}";
  316 + String s = XdyStringUtils.stringToJson(tem, true);
  317 + XdySdk.setAsyncApi(ids_new, s);
  318 + }
  319 +
  320 + public void publisherVideo(String response) {
  321 + XdySdk.onPlayStop();
  322 + String url = XdyStringUtils.stringToJson(response);
  323 + XdyLogUtil.e("调用任务了播视频了url:", "" + url);
  324 + String us = response.substring(1, response.length() - 1);
  325 + XdyLogUtil.e("调用任务了播视频了ursfdfl:", "" + us);
  326 + try {
  327 + LiveBean liveBean = new Gson().fromJson(url, LiveBean.class);
  328 +
  329 + if (liveBean != null&&liveBean.getCode()==0&&liveBean.getPublishUrl()!=null) {
  330 +// String url_text="rtmp://player.daniulive.com:1935/hls/stream";
  331 +// String url_text="rtmp://123.56.205.116:6000/live/h5dev_1999957388_980_983041_1491813919";
  332 + publisherSuccess=liveBean.getPublishUrl();
  333 + XdySdk.setAsyncApi("publishVideo", liveBean.getPublishUrl(), surfaceview_pubisherVideo, VideoPublisherActivity.this,new EventHande());
  334 + XdyLogUtil.e(TAG,liveBean.getPublishUrl());
  335 +
  336 + ToastUtil.showToastshort("推流初始化中",VideoPublisherActivity.this);
  337 + PublisherEntity publisherEntity=new PublisherEntity();
  338 + if(!TextUtils.isEmpty(publisherSuccess)) {
  339 + publisherEntity.setPublishUrl(publisherSuccess);
  340 + String pamp= new Gson().toJson(publisherEntity);
  341 + XdyLogUtil.e("推流成功",""+pamp);
  342 + XdySdk.setAsyncApi("publishVideo",pamp);
  343 + }
  344 +
  345 + }
  346 + } catch (Exception e) {
  347 + XdyLogUtil.e("调用任务了播视频了e", "" + e.getMessage());
  348 +
  349 + }
  350 +
  351 + }
  352 +
  353 + @Override
  354 + public void onBackPressed() {
  355 +
  356 + super.onBackPressed();
  357 + }
  358 +
  359 +
  360 +
  361 + @Override
  362 + protected void onDestroy() {
  363 + super.onDestroy();
  364 + XdySdk.onPlayStop();
  365 + }
  366 +
  367 + @OnClick({R.id.btn_videoPlay_chat, R.id.btn_videoPlay_pubsherVideo})
  368 + public void onViewClicked(View view) {
  369 + switch (view.getId()) {
  370 + case R.id.btn_videoPlay_chat:
  371 + handler.sendEmptyMessage(4);
  372 + break;
  373 + case R.id.btn_videoPlay_pubsherVideo:
  374 + getPublish();
  375 + break;
  376 + }
  377 + }
  378 + class EventHande implements SmartEventCallback {
  379 + @Override
  380 + public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) {
  381 + switch (code) {
  382 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:
  383 + Log.i(TAG, "开始。。");
  384 + break;
  385 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:
  386 + Log.i(TAG, "连接中。。");
  387 + break;
  388 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:
  389 + Log.i(TAG, "连接失败。。");
  390 + break;
  391 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:
  392 + Log.i(TAG, "连接成功。。");
  393 +// PublisherEntity publisherEntity=new PublisherEntity();
  394 +// if(TextUtils.isEmpty(publisherSuccess)) {
  395 +// publisherEntity.setPublishUrl(publisherSuccess);
  396 +// XdySdk.setAsyncApi("publishVideo", new Gson().toJson(publisherEntity));
  397 +// }
  398 + //TODO
  399 + break;
  400 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
  401 + Log.i(TAG, "连接断开。。");
  402 + break;
  403 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
  404 + Log.i(TAG, "关闭。。");
  405 + break;
  406 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
  407 + Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
  408 + break;
  409 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
  410 + Log.i(TAG, "收不到媒体数据,可能是url错误。。");
  411 + }
  412 +
  413 + }
  414 + }
  415 +
  416 +
  417 + class EventHande_Video implements SmartEventCallback {
  418 + @Override
  419 + public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) {
  420 + switch (code) {
  421 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:
  422 + Log.i(TAG, "开始。。");
  423 + break;
  424 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:
  425 + Log.i(TAG, "连接中。。");
  426 + break;
  427 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:
  428 + Log.i(TAG, "连接失败。。");
  429 + break;
  430 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:
  431 + Log.i(TAG, "连接成功。。");
  432 +
  433 + //TODO
  434 + break;
  435 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
  436 + Log.i(TAG, "连接断开。。");
  437 + break;
  438 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
  439 + Log.i(TAG, "关闭。。");
  440 + break;
  441 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
  442 + Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
  443 + break;
  444 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
  445 + Log.i(TAG, "收不到媒体数据,可能是url错误。。");
  446 + }
  447 +
  448 + }
  449 + }
  450 + class PersonDialog extends Dialog {
  451 + public PersonDialog(Context context) {
  452 + this(context, false);
  453 +
  454 + }
  455 +
  456 + public PersonDialog(Context context, boolean showPwd) {
  457 + this(context, R.style.bottom_dialog, showPwd);
  458 + }
  459 +
  460 + public PersonDialog(Context context, int themeResId, boolean showPwd) {
  461 + super(context, themeResId);
  462 + init(context, showPwd);
  463 + }
  464 +
  465 + public void init(Context context, boolean showPwd) {
  466 + View view = View.inflate(context, R.layout.dialog_item, null);
  467 + setContentView(view);
  468 + initView(view,showPwd);
  469 + setCanceledOnTouchOutside(false);
  470 + Window window = getWindow();
  471 + WindowManager.LayoutParams params = window.getAttributes();
  472 + params.width = WindowManager.LayoutParams.MATCH_PARENT;
  473 + params.height = dp2px(context, 220);
  474 + window.setAttributes(params);
  475 + window.setGravity(Gravity.CENTER);
  476 + }
  477 +
  478 + public int dp2px(Context context, float dp) {
  479 + return (int) Math.ceil(context.getResources().getDisplayMetrics().density * dp);
  480 + }
  481 + public void initView(View view, final boolean showPwd){
  482 + final EditText edt_uername= (EditText) view.findViewById(R.id.dialog_edt_username);
  483 + final EditText edt_userpwd= (EditText) view.findViewById(R.id.dialog_edt_userpwd);
  484 + if(showPwd){
  485 + edt_userpwd.setVisibility(View.VISIBLE);
  486 + }else{
  487 + edt_userpwd.setVisibility(View.GONE);
  488 + }
  489 + Button btn_enter= (Button) view.findViewById(R.id.dialog_btn_enter);
  490 + btn_enter.setOnClickListener(new View.OnClickListener() {
  491 + @Override
  492 + public void onClick(View v) {
  493 + username=edt_uername.getText().toString();
  494 + userpwd=edt_userpwd.getText().toString();
  495 + if(TextUtils.isEmpty(username)){
  496 + ToastUtil.showToastshort("用户名不能为空",VideoPublisherActivity.this);
  497 + return;
  498 + }
  499 + if(showPwd&&TextUtils.isEmpty(userpwd)){
  500 + ToastUtil.showToastshort("密码不能为空",VideoPublisherActivity.this);
  501 + return;
  502 + }
  503 + dismiss();
  504 + Message message=Message.obtain();
  505 + message.what=-2;
  506 + message.obj=showPwd;
  507 + handler.sendMessage(message);
  508 + }
  509 + });
  510 + }
  511 + }
  512 +}
  1 +package com.mang.xdy.demo.adapter;
  2 +
  3 +/**
  4 + * Created by huang on 2017/4/9.
  5 + */
  6 +
  7 +import android.content.Context;
  8 +import android.support.v4.app.Fragment;
  9 +import android.support.v4.app.FragmentManager;
  10 +import android.support.v4.app.FragmentPagerAdapter;
  11 +
  12 +import com.mang.xdy.demo.fragment.PageFragment;
  13 +
  14 +public class SimpleFragmentPagerAdapter extends FragmentPagerAdapter {
  15 +
  16 + final int PAGE_COUNT = 3;
  17 + private String tabTitles[] = new String[]{"tab1","tab2","tab3"};
  18 + private Context context;
  19 +
  20 + public SimpleFragmentPagerAdapter(FragmentManager fm,Context context) {
  21 + super(fm);
  22 + this.context = context;
  23 + }
  24 +
  25 + @Override
  26 + public Fragment getItem(int position) {
  27 + return PageFragment.newInstance(position + 1);
  28 + }
  29 +
  30 + @Override
  31 + public int getCount() {
  32 + return PAGE_COUNT;
  33 + }
  34 +
  35 + @Override
  36 + public CharSequence getPageTitle(int position) {
  37 + return tabTitles[position];
  38 + }
  39 +}
  1 +package com.mang.xdy.demo.application;
  2 +
  3 +import android.app.Activity;
  4 +import android.app.Application;
  5 +import android.content.Context;
  6 +
  7 +import com.mang.xdy.core.XdySdk;
  8 +
  9 +/**
  10 + * Created by abao on 2017/3/30.
  11 + */
  12 +
  13 +public class XdyApplicaiton extends Application {
  14 + private static Activity activityList;
  15 + private static Context context;
  16 + @Override
  17 + public void onCreate() {
  18 + super.onCreate();
  19 + context=this;
  20 + XdySdk.init(this);
  21 + }
  22 + public static Activity getActivity(){
  23 + return activityList;
  24 +
  25 + }
  26 +
  27 + public static void setActivity(Activity activity){
  28 + activityList=activity;
  29 + }
  30 + public static Context getInstance(){
  31 + return context;
  32 + }
  33 +
  34 +}
  1 +package com.mang.xdy.demo.bean;
  2 +
  3 +/**
  4 + * Created by huang on 2017/4/9.
  5 + */
  6 +
  7 +public class AudioPlayBean {
  8 +
  9 + /**
  10 + * mediaId : 983041
  11 + * fromNodeId : 253252
  12 + * seek : 0
  13 + * rtmpUrl : rtmp://127.0.0.1:6000/live/h5dev_403074980_0_983041_1488258462
  14 + * m3u8Url : http://127.0.0.1:6001/live/h5dev_403074980_0_983041_1488258462/index.m3u8
  15 + * replay : http://127.0.0.1:6001/live/h5dev_403074980_0_983041_1488258462/total.m3u8
  16 + */
  17 +
  18 + private int mediaId;
  19 + private int fromNodeId;
  20 + private int seek;
  21 + private String rtmpUrl;
  22 + private String m3u8Url;
  23 + private String replay;
  24 +
  25 + public int getMediaId() {
  26 + return mediaId;
  27 + }
  28 +
  29 + public void setMediaId(int mediaId) {
  30 + this.mediaId = mediaId;
  31 + }
  32 +
  33 + public int getFromNodeId() {
  34 + return fromNodeId;
  35 + }
  36 +
  37 + public void setFromNodeId(int fromNodeId) {
  38 + this.fromNodeId = fromNodeId;
  39 + }
  40 +
  41 + public int getSeek() {
  42 + return seek;
  43 + }
  44 +
  45 + public void setSeek(int seek) {
  46 + this.seek = seek;
  47 + }
  48 +
  49 + public String getRtmpUrl() {
  50 + return rtmpUrl;
  51 + }
  52 +
  53 + public void setRtmpUrl(String rtmpUrl) {
  54 + this.rtmpUrl = rtmpUrl;
  55 + }
  56 +
  57 + public String getM3u8Url() {
  58 + return m3u8Url;
  59 + }
  60 +
  61 + public void setM3u8Url(String m3u8Url) {
  62 + this.m3u8Url = m3u8Url;
  63 + }
  64 +
  65 + public String getReplay() {
  66 + return replay;
  67 + }
  68 +
  69 + public void setReplay(String replay) {
  70 + this.replay = replay;
  71 + }
  72 +}
  1 +package com.mang.xdy.demo.bean;
  2 +
  3 +/**
  4 + * Created by huang on 2017/4/9.
  5 + */
  6 +
  7 +public class ChatBean {
  8 +
  9 + /**
  10 + * fromNodeId : 1484207995
  11 + * toNodeId : 0
  12 + * message : Hello world!
  13 + * fromName : MyName
  14 + * fromRole : normal
  15 + */
  16 +
  17 + private int fromNodeId;
  18 + private int toNodeId;
  19 + private String message;
  20 + private String fromName;
  21 + private String fromRole;
  22 +
  23 + public int getFromNodeId() {
  24 + return fromNodeId;
  25 + }
  26 +
  27 + public void setFromNodeId(int fromNodeId) {
  28 + this.fromNodeId = fromNodeId;
  29 + }
  30 +
  31 + public int getToNodeId() {
  32 + return toNodeId;
  33 + }
  34 +
  35 + public void setToNodeId(int toNodeId) {
  36 + this.toNodeId = toNodeId;
  37 + }
  38 +
  39 + public String getMessage() {
  40 + return message;
  41 + }
  42 +
  43 + public void setMessage(String message) {
  44 + this.message = message;
  45 + }
  46 +
  47 + public String getFromName() {
  48 + return fromName;
  49 + }
  50 +
  51 + public void setFromName(String fromName) {
  52 + this.fromName = fromName;
  53 + }
  54 +
  55 + public String getFromRole() {
  56 + return fromRole;
  57 + }
  58 +
  59 + public void setFromRole(String fromRole) {
  60 + this.fromRole = fromRole;
  61 + }
  62 +}
  1 +package com.mang.xdy.demo.bean;
  2 +
  3 +/**
  4 + * Created by huang on 2017/4/9.
  5 + */
  6 +
  7 +public class DocEntity {
  8 +
  9 + /**
  10 + * itemIdx : 749428394
  11 + * owner : 747132023
  12 + * from : 747132023
  13 + * curPageNo : 1
  14 + * pageNum : 1
  15 + * fileType : jpg
  16 + * creatUserId : 0
  17 + * relativeUrl : /DocSharing/data/1087553281/20170409-204600041/d32594763768243bddc64934be5088a0.jpg
  18 + * url :
  19 + * curV : 0
  20 + * curH : 0
  21 + * scale : 100
  22 + * visible : true
  23 + * action : 1
  24 + * docId : 8ab3b0ed5b4fb08d015b52bf009e0b7e
  25 + * fileName : 19462408_171130083000_2.jpg
  26 + * dynamicTS : 0
  27 + * md5 :
  28 + * showType : 0
  29 + */
  30 +
  31 + private int itemIdx;
  32 + private int owner;
  33 + private int from;
  34 + private int curPageNo;
  35 + private int pageNum;
  36 + private String fileType;
  37 + private String creatUserId;
  38 + private String relativeUrl;
  39 + private String url;
  40 + private int curV;
  41 + private int curH;
  42 + private int scale;
  43 + private boolean visible;
  44 + private int action;
  45 + private String docId;
  46 + private String fileName;
  47 + private String dynamicTS;
  48 + private String md5;
  49 + private int showType;
  50 +
  51 + public int getItemIdx() {
  52 + return itemIdx;
  53 + }
  54 +
  55 + public void setItemIdx(int itemIdx) {
  56 + this.itemIdx = itemIdx;
  57 + }
  58 +
  59 + public int getOwner() {
  60 + return owner;
  61 + }
  62 +
  63 + public void setOwner(int owner) {
  64 + this.owner = owner;
  65 + }
  66 +
  67 + public int getFrom() {
  68 + return from;
  69 + }
  70 +
  71 + public void setFrom(int from) {
  72 + this.from = from;
  73 + }
  74 +
  75 + public int getCurPageNo() {
  76 + return curPageNo;
  77 + }
  78 +
  79 + public void setCurPageNo(int curPageNo) {
  80 + this.curPageNo = curPageNo;
  81 + }
  82 +
  83 + public int getPageNum() {
  84 + return pageNum;
  85 + }
  86 +
  87 + public void setPageNum(int pageNum) {
  88 + this.pageNum = pageNum;
  89 + }
  90 +
  91 + public String getFileType() {
  92 + return fileType;
  93 + }
  94 +
  95 + public void setFileType(String fileType) {
  96 + this.fileType = fileType;
  97 + }
  98 +
  99 + public String getCreatUserId() {
  100 + return creatUserId;
  101 + }
  102 +
  103 + public void setCreatUserId(String creatUserId) {
  104 + this.creatUserId = creatUserId;
  105 + }
  106 +
  107 + public String getRelativeUrl() {
  108 + return relativeUrl;
  109 + }
  110 +
  111 + public void setRelativeUrl(String relativeUrl) {
  112 + this.relativeUrl = relativeUrl;
  113 + }
  114 +
  115 + public String getUrl() {
  116 + return url;
  117 + }
  118 +
  119 + public void setUrl(String url) {
  120 + this.url = url;
  121 + }
  122 +
  123 + public int getCurV() {
  124 + return curV;
  125 + }
  126 +
  127 + public void setCurV(int curV) {
  128 + this.curV = curV;
  129 + }
  130 +
  131 + public int getCurH() {
  132 + return curH;
  133 + }
  134 +
  135 + public void setCurH(int curH) {
  136 + this.curH = curH;
  137 + }
  138 +
  139 + public int getScale() {
  140 + return scale;
  141 + }
  142 +
  143 + public void setScale(int scale) {
  144 + this.scale = scale;
  145 + }
  146 +
  147 + public boolean isVisible() {
  148 + return visible;
  149 + }
  150 +
  151 + public void setVisible(boolean visible) {
  152 + this.visible = visible;
  153 + }
  154 +
  155 + public int getAction() {
  156 + return action;
  157 + }
  158 +
  159 + public void setAction(int action) {
  160 + this.action = action;
  161 + }
  162 +
  163 + public String getDocId() {
  164 + return docId;
  165 + }
  166 +
  167 + public void setDocId(String docId) {
  168 + this.docId = docId;
  169 + }
  170 +
  171 + public String getFileName() {
  172 + return fileName;
  173 + }
  174 +
  175 + public void setFileName(String fileName) {
  176 + this.fileName = fileName;
  177 + }
  178 +
  179 + public String getDynamicTS() {
  180 + return dynamicTS;
  181 + }
  182 +
  183 + public void setDynamicTS(String dynamicTS) {
  184 + this.dynamicTS = dynamicTS;
  185 + }
  186 +
  187 + public String getMd5() {
  188 + return md5;
  189 + }
  190 +
  191 + public void setMd5(String md5) {
  192 + this.md5 = md5;
  193 + }
  194 +
  195 + public int getShowType() {
  196 + return showType;
  197 + }
  198 +
  199 + public void setShowType(int showType) {
  200 + this.showType = showType;
  201 + }
  202 +}
  1 +package com.mang.xdy.demo.bean;
  2 +
  3 +/**
  4 + * Created by abao on 2017/4/10.
  5 + */
  6 +
  7 +public class InitClassSuccessEntity {
  8 +
  9 + /**
  10 + * siteId : h5test
  11 + * passwordRequired : true
  12 + * userRole : normal
  13 + * classId : 222333
  14 + * userId : 0
  15 + * userName :
  16 + * classType : 1
  17 + */
  18 +
  19 + private String siteId;
  20 + private boolean passwordRequired;
  21 + private String userRole;
  22 + private int classId;
  23 + private String userId;
  24 + private String userName;
  25 + private int classType;
  26 +
  27 + public String getSiteId() {
  28 + return siteId;
  29 + }
  30 +
  31 + public void setSiteId(String siteId) {
  32 + this.siteId = siteId;
  33 + }
  34 +
  35 + public boolean isPasswordRequired() {
  36 + return passwordRequired;
  37 + }
  38 +
  39 + public void setPasswordRequired(boolean passwordRequired) {
  40 + this.passwordRequired = passwordRequired;
  41 + }
  42 +
  43 + public String getUserRole() {
  44 + return userRole;
  45 + }
  46 +
  47 + public void setUserRole(String userRole) {
  48 + this.userRole = userRole;
  49 + }
  50 +
  51 + public int getClassId() {
  52 + return classId;
  53 + }
  54 +
  55 + public void setClassId(int classId) {
  56 + this.classId = classId;
  57 + }
  58 +
  59 + public String getUserId() {
  60 + return userId;
  61 + }
  62 +
  63 + public void setUserId(String userId) {
  64 + this.userId = userId;
  65 + }
  66 +
  67 + public String getUserName() {
  68 + return userName;
  69 + }
  70 +
  71 + public void setUserName(String userName) {
  72 + this.userName = userName;
  73 + }
  74 +
  75 + public int getClassType() {
  76 + return classType;
  77 + }
  78 +
  79 + public void setClassType(int classType) {
  80 + this.classType = classType;
  81 + }
  82 +}
  1 +package com.mang.xdy.demo.bean;
  2 +
  3 +/**
  4 + * Created by abao on 2017/4/10. 加入课堂
  5 + */
  6 +
  7 +public class JoinClass {
  8 +
  9 + /**
  10 + * userName : 小明
  11 + * password : 123321
  12 + * hasCamera : false
  13 + * hasMicrophone : false
  14 + */
  15 +
  16 + private String userName;
  17 + private String password;
  18 + private boolean hasCamera;
  19 + private boolean hasMicrophone;
  20 +
  21 + public String getUserName() {
  22 + return userName;
  23 + }
  24 +
  25 + public void setUserName(String userName) {
  26 + this.userName = userName;
  27 + }
  28 +
  29 + public String getPassword() {
  30 + return password;
  31 + }
  32 +
  33 + public void setPassword(String password) {
  34 + this.password = password;
  35 + }
  36 +
  37 + public boolean isHasCamera() {
  38 + return hasCamera;
  39 + }
  40 +
  41 + public void setHasCamera(boolean hasCamera) {
  42 + this.hasCamera = hasCamera;
  43 + }
  44 +
  45 + public boolean isHasMicrophone() {
  46 + return hasMicrophone;
  47 + }
  48 +
  49 + public void setHasMicrophone(boolean hasMicrophone) {
  50 + this.hasMicrophone = hasMicrophone;
  51 + }
  52 +}
  1 +package com.mang.xdy.demo.bean;
  2 +
  3 +/**
  4 + * Created by huang on 2017/4/9.
  5 + */
  6 +
  7 +public class JoinClassBean {
  8 +
  9 + /**
  10 + * classId : 123456
  11 + * portal : 127.0.0.1:80
  12 + * userRole : normal
  13 + * userName :
  14 + * userId : 0
  15 + */
  16 +
  17 + private int classId;
  18 + private String portal;
  19 + private String userRole;
  20 + private String userName;
  21 + private int userId;
  22 +
  23 + public int getClassId() {
  24 + return classId;
  25 + }
  26 +
  27 + public void setClassId(int classId) {
  28 + this.classId = classId;
  29 + }
  30 +
  31 + public String getPortal() {
  32 + return portal;
  33 + }
  34 +
  35 + public void setPortal(String portal) {
  36 + this.portal = portal;
  37 + }
  38 +
  39 + public String getUserRole() {
  40 + return userRole;
  41 + }
  42 +
  43 + public void setUserRole(String userRole) {
  44 + this.userRole = userRole;
  45 + }
  46 +
  47 + public String getUserName() {
  48 + return userName;
  49 + }
  50 +
  51 + public void setUserName(String userName) {
  52 + this.userName = userName;
  53 + }
  54 +
  55 + public int getUserId() {
  56 + return userId;
  57 + }
  58 +
  59 + public void setUserId(int userId) {
  60 + this.userId = userId;
  61 + }
  62 +}
  1 +package com.mang.xdy.demo.bean;
  2 +
  3 +/**
  4 + * Created by abao on 2017/4/10.
  5 + */
  6 +
  7 +public class JoinClassSuccessEntity {
  8 +
  9 + /**
  10 + * docServer : 101.200.150.192:80
  11 + * classId : 526661904
  12 + * h5Module : 0
  13 + * isHost : false
  14 + * maxAudioChannels : 1
  15 + * maxVideoChannels : 1
  16 + * maxMediaChannels : 2
  17 + * mcuDelay : 3000
  18 + * msType : 1
  19 + * nodeId : 613317321
  20 + * password : 222222
  21 + * passwordRequired : true
  22 + * role : 1
  23 + * siteId : h5test
  24 + * topNodeID : 101
  25 + * userId : 0
  26 + * userName : mcuTest1486613317
  27 + * userRole : normal
  28 + * classType : 1
  29 + * classTimestamp : 10
  30 + * recordPlaybackMaxTime : 0
  31 + */
  32 +
  33 + private String docServer;
  34 + private int classId;
  35 + private int h5Module;
  36 + private boolean isHost;
  37 + private int maxAudioChannels;
  38 + private int maxVideoChannels;
  39 + private int maxMediaChannels;
  40 + private int mcuDelay;
  41 + private int msType;
  42 + private int nodeId;
  43 + private String password;
  44 + private boolean passwordRequired;
  45 + private int role;
  46 + private String siteId;
  47 + private int topNodeID;
  48 + private String userId;
  49 + private String userName;
  50 + private String userRole;
  51 + private int classType;
  52 + private int classTimestamp;
  53 + private int recordPlaybackMaxTime;
  54 +
  55 + public String getDocServer() {
  56 + return docServer;
  57 + }
  58 +
  59 + public void setDocServer(String docServer) {
  60 + this.docServer = docServer;
  61 + }
  62 +
  63 + public int getClassId() {
  64 + return classId;
  65 + }
  66 +
  67 + public void setClassId(int classId) {
  68 + this.classId = classId;
  69 + }
  70 +
  71 + public int getH5Module() {
  72 + return h5Module;
  73 + }
  74 +
  75 + public void setH5Module(int h5Module) {
  76 + this.h5Module = h5Module;
  77 + }
  78 +
  79 + public boolean isIsHost() {
  80 + return isHost;
  81 + }
  82 +
  83 + public void setIsHost(boolean isHost) {
  84 + this.isHost = isHost;
  85 + }
  86 +
  87 + public int getMaxAudioChannels() {
  88 + return maxAudioChannels;
  89 + }
  90 +
  91 + public void setMaxAudioChannels(int maxAudioChannels) {
  92 + this.maxAudioChannels = maxAudioChannels;
  93 + }
  94 +
  95 + public int getMaxVideoChannels() {
  96 + return maxVideoChannels;
  97 + }
  98 +
  99 + public void setMaxVideoChannels(int maxVideoChannels) {
  100 + this.maxVideoChannels = maxVideoChannels;
  101 + }
  102 +
  103 + public int getMaxMediaChannels() {
  104 + return maxMediaChannels;
  105 + }
  106 +
  107 + public void setMaxMediaChannels(int maxMediaChannels) {
  108 + this.maxMediaChannels = maxMediaChannels;
  109 + }
  110 +
  111 + public int getMcuDelay() {
  112 + return mcuDelay;
  113 + }
  114 +
  115 + public void setMcuDelay(int mcuDelay) {
  116 + this.mcuDelay = mcuDelay;
  117 + }
  118 +
  119 + public int getMsType() {
  120 + return msType;
  121 + }
  122 +
  123 + public void setMsType(int msType) {
  124 + this.msType = msType;
  125 + }
  126 +
  127 + public int getNodeId() {
  128 + return nodeId;
  129 + }
  130 +
  131 + public void setNodeId(int nodeId) {
  132 + this.nodeId = nodeId;
  133 + }
  134 +
  135 + public String getPassword() {
  136 + return password;
  137 + }
  138 +
  139 + public void setPassword(String password) {
  140 + this.password = password;
  141 + }
  142 +
  143 + public boolean isPasswordRequired() {
  144 + return passwordRequired;
  145 + }
  146 +
  147 + public void setPasswordRequired(boolean passwordRequired) {
  148 + this.passwordRequired = passwordRequired;
  149 + }
  150 +
  151 + public int getRole() {
  152 + return role;
  153 + }
  154 +
  155 + public void setRole(int role) {
  156 + this.role = role;
  157 + }
  158 +
  159 + public String getSiteId() {
  160 + return siteId;
  161 + }
  162 +
  163 + public void setSiteId(String siteId) {
  164 + this.siteId = siteId;
  165 + }
  166 +
  167 + public int getTopNodeID() {
  168 + return topNodeID;
  169 + }
  170 +
  171 + public void setTopNodeID(int topNodeID) {
  172 + this.topNodeID = topNodeID;
  173 + }
  174 +
  175 + public String getUserId() {
  176 + return userId;
  177 + }
  178 +
  179 + public void setUserId(String userId) {
  180 + this.userId = userId;
  181 + }
  182 +
  183 + public String getUserName() {
  184 + return userName;
  185 + }
  186 +
  187 + public void setUserName(String userName) {
  188 + this.userName = userName;
  189 + }
  190 +
  191 + public String getUserRole() {
  192 + return userRole;
  193 + }
  194 +
  195 + public void setUserRole(String userRole) {
  196 + this.userRole = userRole;
  197 + }
  198 +
  199 + public int getClassType() {
  200 + return classType;
  201 + }
  202 +
  203 + public void setClassType(int classType) {
  204 + this.classType = classType;
  205 + }
  206 +
  207 + public int getClassTimestamp() {
  208 + return classTimestamp;
  209 + }
  210 +
  211 + public void setClassTimestamp(int classTimestamp) {
  212 + this.classTimestamp = classTimestamp;
  213 + }
  214 +
  215 + public int getRecordPlaybackMaxTime() {
  216 + return recordPlaybackMaxTime;
  217 + }
  218 +
  219 + public void setRecordPlaybackMaxTime(int recordPlaybackMaxTime) {
  220 + this.recordPlaybackMaxTime = recordPlaybackMaxTime;
  221 + }
  222 +}
  1 +package com.mang.xdy.demo.bean;
  2 +
  3 +/**
  4 + * Created by abao on 2017/4/7.
  5 + */
  6 +
  7 +public class LiveBean {
  8 +
  9 + /**
  10 + * code : 0
  11 + * data :
  12 + * publishUrl : rtmp: 123.56.205.116: 6000/live/h5dev_1184939098_0_983041_1491555151
  13 + */
  14 +
  15 + private int code;
  16 + private String data;
  17 + private String publishUrl;
  18 +
  19 + public int getCode() {
  20 + return code;
  21 + }
  22 +
  23 + public void setCode(int code) {
  24 + this.code = code;
  25 + }
  26 +
  27 + public String getData() {
  28 + return data;
  29 + }
  30 +
  31 + public void setData(String data) {
  32 + this.data = data;
  33 + }
  34 +
  35 + public String getPublishUrl() {
  36 + return publishUrl;
  37 + }
  38 +
  39 + public void setPublishUrl(String publishUrl) {
  40 + this.publishUrl = publishUrl;
  41 + }
  42 +}
  1 +package com.mang.xdy.demo.bean;
  2 +
  3 +/**
  4 + * Created by abao on 2017/4/10.
  5 + */
  6 +
  7 +public class PublisherEntity {
  8 +
  9 + /**
  10 + * publishUrl :
  11 + */
  12 +
  13 + private String publishUrl;
  14 +
  15 + public String getPublishUrl() {
  16 + return publishUrl;
  17 + }
  18 +
  19 + public void setPublishUrl(String publishUrl) {
  20 + this.publishUrl = publishUrl;
  21 + }
  22 +}
  1 +package com.mang.xdy.demo.bean;
  2 +
  3 +// FIXME generate failure method set and get MediaId
  4 +// FIXME generate failure field _$Replay151
  5 +// FIXME generate failure field _$RtmpUrl165
  6 +// FIXME generate failure field _$M3u8Url177
  7 +// FIXME generate failure field _$UserName168
  8 +/**
  9 + * Created by huang on 2017/4/9.
  10 + */
  11 +
  12 +public class VideoPlayBean {
  13 +
  14 +
  15 + /**
  16 + * mediaId : 983041
  17 + * fromNodeId : 735605646
  18 + * userName : base
  19 + * m3u8Url : http://123.56.73.119:6001/live/h5dev_1184939098_980_983041_1491735653/index.m3u8
  20 + * rtmpUrl : rtmp://123.56.205.116:6000/live/h5dev_1184939098_980_983041_1491735653
  21 + * replay : http://123.56.73.119:6001/live/h5dev_1184939098_980_983041_1491735653/total.m3u8
  22 + * seek : 0
  23 + */
  24 +
  25 + private int mediaId;
  26 + private int fromNodeId;
  27 + private String userName;
  28 + private String m3u8Url;
  29 + private String rtmpUrl;
  30 + private String replay;
  31 + private int seek;
  32 +
  33 + public int getMediaId() {
  34 + return mediaId;
  35 + }
  36 +
  37 + public void setMediaId(int mediaId) {
  38 + this.mediaId = mediaId;
  39 + }
  40 +
  41 + public int getFromNodeId() {
  42 + return fromNodeId;
  43 + }
  44 +
  45 + public void setFromNodeId(int fromNodeId) {
  46 + this.fromNodeId = fromNodeId;
  47 + }
  48 +
  49 + public String getUserName() {
  50 + return userName;
  51 + }
  52 +
  53 + public void setUserName(String userName) {
  54 + this.userName = userName;
  55 + }
  56 +
  57 + public String getM3u8Url() {
  58 + return m3u8Url;
  59 + }
  60 +
  61 + public void setM3u8Url(String m3u8Url) {
  62 + this.m3u8Url = m3u8Url;
  63 + }
  64 +
  65 + public String getRtmpUrl() {
  66 + return rtmpUrl;
  67 + }
  68 +
  69 + public void setRtmpUrl(String rtmpUrl) {
  70 + this.rtmpUrl = rtmpUrl;
  71 + }
  72 +
  73 + public String getReplay() {
  74 + return replay;
  75 + }
  76 +
  77 + public void setReplay(String replay) {
  78 + this.replay = replay;
  79 + }
  80 +
  81 + public int getSeek() {
  82 + return seek;
  83 + }
  84 +
  85 + public void setSeek(int seek) {
  86 + this.seek = seek;
  87 + }
  88 +}
  1 +package com.mang.xdy.demo.fragment;
  2 +
  3 +
  4 +import android.os.Bundle;
  5 +import android.support.annotation.Nullable;
  6 +import android.support.v4.app.Fragment;
  7 +import android.view.LayoutInflater;
  8 +import android.view.View;
  9 +import android.view.ViewGroup;
  10 +import android.widget.TextView;
  11 +
  12 +import com.mang.xdy.demo.R;
  13 +
  14 +
  15 +/**
  16 + * Created by huang on 2017/4/9.
  17 + */
  18 +
  19 +
  20 +public class PageFragment extends Fragment {
  21 +
  22 + public static final String ARG_PAGE = "ARG_PAGE";
  23 + private int mPage;
  24 +
  25 + public static PageFragment newInstance(int page) {
  26 + Bundle args = new Bundle();
  27 + args.putInt(ARG_PAGE, page);
  28 + PageFragment pageFragment = new PageFragment();
  29 + pageFragment.setArguments(args);
  30 + return pageFragment;
  31 + }
  32 +
  33 + @Override
  34 + public void onCreate(Bundle savedInstanceState) {
  35 + super.onCreate(savedInstanceState);
  36 + mPage = getArguments().getInt(ARG_PAGE);
  37 + }
  38 +
  39 + @Nullable
  40 + @Override
  41 + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  42 + View view = inflater.inflate(R.layout.fragment_page, container, false);
  43 + TextView textView = (TextView) view;
  44 + textView.setText("Fragment #" + mPage);
  45 + return view;
  46 + }
  47 +
  48 +}
  1 +package com.mang.xdy.demo.utils;
  2 +
  3 +import android.text.TextUtils;
  4 +import android.util.Log;
  5 +
  6 +import com.google.gson.Gson;
  7 +import com.google.gson.reflect.TypeToken;
  8 +
  9 +import org.json.JSONException;
  10 +import org.json.JSONObject;
  11 +
  12 +import java.lang.reflect.Type;
  13 +import java.util.HashMap;
  14 +import java.util.List;
  15 +import java.util.Map;
  16 +
  17 +/**
  18 + * 封装的是使用Gson解析json的方法
  19 + *
  20 + * @author Administrator
  21 + */
  22 +public class JsonUtil {
  23 +
  24 + private static final String TAG = JsonUtil.class.getSimpleName();
  25 +
  26 + /**
  27 + * 把一个map变成json字符串
  28 + *
  29 + * @param map
  30 + * @return
  31 + */
  32 + public static String parseMapToJson(Map<?, ?> map) {
  33 + try {
  34 + Gson gson = new Gson();
  35 + return gson.toJson(map);
  36 + } catch (Exception e) {
  37 + }
  38 + return null;
  39 + }
  40 +
  41 + public static String parseListToJson(List<?> list) {
  42 + try {
  43 + Gson gson = new Gson();
  44 + return gson.toJson(list);
  45 + } catch (Exception e) {
  46 + }
  47 + return null;
  48 + }
  49 +
  50 + /**
  51 + * 把一个json字符串变成对象
  52 + *
  53 + * @param json
  54 + * @param cls
  55 + * @return
  56 + */
  57 + public static <T> T parseJsonToBean(String json, Class<T> cls) {
  58 + Gson gson = new Gson();
  59 + T t = null;
  60 + try {
  61 + t = gson.fromJson(json, cls);
  62 + } catch (Exception e) {
  63 + Log.e(TAG,e.getMessage());
  64 + e.printStackTrace();
  65 + }
  66 + return t;
  67 + }
  68 +
  69 + /**
  70 + * 把json字符串变成map
  71 + *
  72 + * @param json
  73 + * @return
  74 + */
  75 + public static HashMap<String, Object> parseJsonToMap(String json) {
  76 + Gson gson = new Gson();
  77 + Type type = new TypeToken<HashMap<String, Object>>() {
  78 + }.getType();
  79 + HashMap<String, Object> map = null;
  80 + try {
  81 + map = gson.fromJson(json, type);
  82 + } catch (Exception e) {
  83 + }
  84 + return map;
  85 + }
  86 +
  87 + /**
  88 + * 把json字符串变成集合
  89 + * params: new TypeToken<List<yourbean>>(){}.getType(),
  90 + *
  91 + * @param json
  92 + * @param type new TypeToken<List<yourbean>>(){}.getType()
  93 + * @return
  94 + */
  95 + public static List<?> parseJsonToList(String json, Type type) {
  96 + Gson gson = new Gson();
  97 + List<?> list = gson.fromJson(json, type);
  98 + return list;
  99 + }
  100 +
  101 + /**
  102 + * 获取json串中某个字段的值,注意,只能获取同一层级的value
  103 + *
  104 + * @param json
  105 + * @param key
  106 + * @return
  107 + */
  108 + public static String getFieldValue(String json, String key) {
  109 + if (TextUtils.isEmpty(json))
  110 + return null;
  111 + if (!json.contains(key))
  112 + return "";
  113 + JSONObject jsonObject = null;
  114 + String value = null;
  115 + try {
  116 + jsonObject = new JSONObject(json);
  117 + value = jsonObject.getString(key);
  118 + } catch (JSONException e) {
  119 + e.printStackTrace();
  120 + }
  121 + return value;
  122 + }
  123 +
  124 +}
  1 +package com.mang.xdy.demo.utils;
  2 +
  3 +import android.content.Context;
  4 +import android.widget.Toast;
  5 +
  6 +public class ToastUtil {
  7 + private static Toast toast;
  8 +
  9 + /**
  10 + * 没有延迟的吐司,可连点
  11 + *
  12 + * @param text
  13 + */
  14 + public static void showToast(String text, Context context) {
  15 +
  16 + if (toast == null) {
  17 + toast = Toast.makeText(context, text, Toast.LENGTH_LONG);
  18 + } else {
  19 +// LinearLayout linearLayout = (LinearLayout) toast.getView();
  20 +// TextView messageTextView = (TextView) linearLayout.getChildAt(0);
  21 +// messageTextView.setTextSize(15);
  22 + toast.setText(text);//如果不为空,则直接改变当前toast的文本
  23 + }
  24 + toast.show();
  25 + }
  26 +
  27 + /**
  28 + * 短吐司
  29 + *
  30 + * @param text
  31 + * @param context
  32 + */
  33 + public static void showToastshort(String text, Context context) {
  34 + try {
  35 +
  36 +
  37 + if (toast == null) {
  38 + toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
  39 + } else {
  40 + toast.setText(text);//如果不为空,则直接改变当前toast的文本
  41 + }
  42 + toast.show();
  43 + }catch (Exception e){
  44 +
  45 + }
  46 + }
  47 +
  48 +}
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<!--
  3 +/*
  4 +** Copyright 2010, The Android Open Source Project
  5 +**
  6 +** Licensed under the Apache License, Version 2.0 (the "License");
  7 +** you may not use this file except in compliance with the License.
  8 +** You may obtain a copy of the License at
  9 +**
  10 +** http://www.apache.org/licenses/LICENSE-2.0
  11 +**
  12 +** Unless required by applicable law or agreed to in writing, software
  13 +** distributed under the License is distributed on an "AS IS" BASIS,
  14 +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 +** See the License for the specific language governing permissions and
  16 +** limitations under the License.
  17 +*/
  18 +-->
  19 +
  20 +<accelerateInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
  21 + android:factor="1.5" />
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<!--
  3 +/*
  4 +** Copyright 2010, The Android Open Source Project
  5 +**
  6 +** Licensed under the Apache License, Version 2.0 (the "License");
  7 +** you may not use this file except in compliance with the License.
  8 +** You may obtain a copy of the License at
  9 +**
  10 +** http://www.apache.org/licenses/LICENSE-2.0
  11 +**
  12 +** Unless required by applicable law or agreed to in writing, software
  13 +** distributed under the License is distributed on an "AS IS" BASIS,
  14 +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 +** See the License for the specific language governing permissions and
  16 +** limitations under the License.
  17 +*/
  18 +-->
  19 +
  20 +<accelerateInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
  21 + android:factor="2.5" />
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<!--
  3 +/*
  4 +** Copyright 2010, The Android Open Source Project
  5 +**
  6 +** Licensed under the Apache License, Version 2.0 (the "License");
  7 +** you may not use this file except in compliance with the License.
  8 +** You may obtain a copy of the License at
  9 +**
  10 +** http://www.apache.org/licenses/LICENSE-2.0
  11 +**
  12 +** Unless required by applicable law or agreed to in writing, software
  13 +** distributed under the License is distributed on an "AS IS" BASIS,
  14 +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 +** See the License for the specific language governing permissions and
  16 +** limitations under the License.
  17 +*/
  18 +-->
  19 +
  20 +<decelerateInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
  21 + android:factor="1.5" />
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<!--
  3 +/*
  4 +** Copyright 2010, The Android Open Source Project
  5 +**
  6 +** Licensed under the Apache License, Version 2.0 (the "License");
  7 +** you may not use this file except in compliance with the License.
  8 +** You may obtain a copy of the License at
  9 +**
  10 +** http://www.apache.org/licenses/LICENSE-2.0
  11 +**
  12 +** Unless required by applicable law or agreed to in writing, software
  13 +** distributed under the License is distributed on an "AS IS" BASIS,
  14 +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 +** See the License for the specific language governing permissions and
  16 +** limitations under the License.
  17 +*/
  18 +-->
  19 +
  20 +<decelerateInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
  21 + android:factor="2.5" />
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<!--
  3 +/* //device/apps/common/res/anim/fade_in.xml
  4 +**
  5 +** Copyright 2007, The Android Open Source Project
  6 +**
  7 +** Licensed under the Apache License, Version 2.0 (the "License");
  8 +** you may not use this file except in compliance with the License.
  9 +** You may obtain a copy of the License at
  10 +**
  11 +** http://www.apache.org/licenses/LICENSE-2.0
  12 +**
  13 +** Unless required by applicable law or agreed to in writing, software
  14 +** distributed under the License is distributed on an "AS IS" BASIS,
  15 +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16 +** See the License for the specific language governing permissions and
  17 +** limitations under the License.
  18 +*/
  19 +-->
  20 +
  21 +<set xmlns:android="http://schemas.android.com/apk/res/android"
  22 + android:shareInterpolator="false">
  23 + <translate android:fromYDelta="10%" android:toYDelta="0"
  24 + android:interpolator="@anim/decelerate_quint"
  25 + android:duration="@android:integer/config_shortAnimTime"/>
  26 + <alpha android:fromAlpha="0.5" android:toAlpha="1.0"
  27 + android:interpolator="@anim/decelerate_cubic"
  28 + android:duration="@android:integer/config_shortAnimTime" />
  29 +</set>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<!--
  3 +/* //device/apps/common/res/anim/fade_out.xml
  4 +**
  5 +** Copyright 2007, The Android Open Source Project
  6 +**
  7 +** Licensed under the Apache License, Version 2.0 (the "License");
  8 +** you may not use this file except in compliance with the License.
  9 +** You may obtain a copy of the License at
  10 +**
  11 +** http://www.apache.org/licenses/LICENSE-2.0
  12 +**
  13 +** Unless required by applicable law or agreed to in writing, software
  14 +** distributed under the License is distributed on an "AS IS" BASIS,
  15 +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16 +** See the License for the specific language governing permissions and
  17 +** limitations under the License.
  18 +*/
  19 +-->
  20 +
  21 +<set
  22 + android:shareInterpolator="false"
  23 + xmlns:android="http://schemas.android.com/apk/res/android">
  24 + <translate android:fromYDelta="0" android:toYDelta="10%"
  25 + android:interpolator="@anim/accelerate_quint"
  26 + android:duration="@android:integer/config_shortAnimTime"/>
  27 + <alpha android:fromAlpha="1.0" android:toAlpha="0.0"
  28 + android:interpolator="@anim/accelerate_cubic"
  29 + android:duration="@android:integer/config_shortAnimTime"/>
  30 +</set>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:tools="http://schemas.android.com/tools"
  4 + android:id="@+id/activity_main"
  5 + android:layout_width="match_parent"
  6 + android:layout_height="match_parent"
  7 + android:orientation="vertical"
  8 + tools:context="com.mang.xdy.demo.MainActivity">
  9 + <TextView
  10 + android:layout_width="match_parent"
  11 + android:layout_height="wrap_content"
  12 + android:text="课堂Id"
  13 + />
  14 + <EditText
  15 + android:id="@+id/edt_home_classId"
  16 + android:layout_width="match_parent"
  17 + android:layout_height="wrap_content"
  18 + android:text="1184939098"/>
  19 + <TextView
  20 + android:layout_width="match_parent"
  21 + android:layout_height="wrap_content"
  22 + android:text="角色"/>
  23 + <EditText
  24 + android:id="@+id/edt_home_role"
  25 + android:layout_width="match_parent"
  26 + android:layout_height="wrap_content"
  27 + android:text="normal"
  28 + />
  29 + <TextView
  30 +
  31 + android:layout_width="match_parent"
  32 + android:layout_height="wrap_content"
  33 + android:text="服务器地址"
  34 + />
  35 + <EditText
  36 + android:id="@+id/edt_home_serviceIp"
  37 + android:layout_width="match_parent"
  38 + android:layout_height="wrap_content"
  39 + android:text="112.126.80.182:90"
  40 + />
  41 + <TextView
  42 + android:layout_width="match_parent"
  43 + android:layout_height="wrap_content"
  44 + android:text="用户id"
  45 + />
  46 + <EditText
  47 + android:id="@+id/edt_home_userId"
  48 + android:layout_width="match_parent"
  49 + android:layout_height="wrap_content"
  50 + android:text="0"
  51 + />
  52 + <Button
  53 + android:id="@+id/btn_home_enter_class"
  54 + android:layout_width="match_parent"
  55 + android:layout_height="wrap_content"
  56 + android:text="进入课堂"
  57 +
  58 + />
  59 + <Button
  60 + android:id="@+id/btn_home_enter_publisher"
  61 + android:layout_width="match_parent"
  62 + android:layout_height="wrap_content"
  63 + android:text="推流服务"
  64 +
  65 + />
  66 +</LinearLayout>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:tools="http://schemas.android.com/tools"
  4 + android:id="@+id/activity_video_play"
  5 + android:layout_width="match_parent"
  6 + android:layout_height="match_parent"
  7 + android:orientation="vertical"
  8 + tools:context="com.mang.xdy.demo.activity.VideoPlayActivity">
  9 + <RelativeLayout
  10 + android:layout_width="wrap_content"
  11 + android:layout_height="wrap_content">
  12 + <SurfaceView
  13 + android:id="@+id/surfaceview_playVideo"
  14 + android:layout_width="match_parent"
  15 + android:layout_height="300dp" />
  16 + <ImageView
  17 + android:id="@+id/img_playVideo_novideo"
  18 + android:layout_width="match_parent"
  19 + android:layout_height="200dp"
  20 + android:background="@mipmap/novideo"
  21 + />
  22 + </RelativeLayout>
  23 + <SurfaceView
  24 + android:id="@+id/surfaceview_pubisherVideo"
  25 + android:layout_width="match_parent"
  26 + android:layout_height="120dp"
  27 + android:visibility="gone"/>
  28 + <android.support.design.widget.TabLayout
  29 + android:id="@+id/sliding_tabs"
  30 + android:layout_width="match_parent"
  31 + android:layout_height="wrap_content"
  32 + />
  33 +
  34 + <android.support.v4.view.ViewPager
  35 + android:id="@+id/viewpager"
  36 + android:layout_width="match_parent"
  37 + android:layout_height="0px"
  38 + android:layout_weight="1"
  39 + android:background="@android:color/white" />
  40 + <TextView
  41 + android:id="@+id/tv_videoPlay_url"
  42 + android:layout_width="wrap_content"
  43 + android:layout_height="wrap_content"
  44 + />
  45 + <LinearLayout
  46 + android:layout_width="match_parent"
  47 + android:layout_height="wrap_content"
  48 + android:orientation="horizontal">
  49 + <Button
  50 + android:id="@+id/btn_videoPlay_chat"
  51 + android:layout_width="wrap_content"
  52 + android:layout_height="wrap_content"
  53 + android:text="发送hello"
  54 + />
  55 + <Button
  56 + android:id="@+id/btn_videoPlay_pubsherVideo"
  57 + android:layout_width="wrap_content"
  58 + android:layout_height="wrap_content"
  59 + android:visibility="gone"
  60 + android:text="获取推流地址"
  61 + />
  62 + </LinearLayout>
  63 +</LinearLayout>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:tools="http://schemas.android.com/tools"
  4 + android:id="@+id/activity_video_play"
  5 + android:layout_width="match_parent"
  6 + android:layout_height="match_parent"
  7 + android:orientation="vertical"
  8 + tools:context="com.mang.xdy.demo.activity.VideoPlayActivity">
  9 + <RelativeLayout
  10 + android:layout_width="wrap_content"
  11 + android:layout_height="wrap_content"
  12 + android:visibility="gone"
  13 + >
  14 + <SurfaceView
  15 + android:id="@+id/surfaceview_playVideo"
  16 + android:layout_width="match_parent"
  17 + android:layout_height="200dp"
  18 + android:visibility="gone"/>
  19 + <ImageView
  20 + android:id="@+id/img_playVideo_novideo"
  21 + android:layout_width="match_parent"
  22 + android:layout_height="200dp"
  23 + android:background="@mipmap/novideo"
  24 + />
  25 + </RelativeLayout>
  26 + <SurfaceView
  27 + android:id="@+id/surfaceview_pubisherVideo"
  28 + android:layout_width="match_parent"
  29 + android:layout_height="300dp" />
  30 + <android.support.design.widget.TabLayout
  31 + android:id="@+id/sliding_tabs"
  32 + android:layout_width="match_parent"
  33 + android:layout_height="wrap_content"
  34 + />
  35 +
  36 + <android.support.v4.view.ViewPager
  37 + android:id="@+id/viewpager"
  38 + android:layout_width="match_parent"
  39 + android:layout_height="0px"
  40 + android:layout_weight="1"
  41 + android:background="@android:color/white" />
  42 + <TextView
  43 + android:id="@+id/tv_videoPlay_url"
  44 + android:layout_width="wrap_content"
  45 + android:layout_height="wrap_content"
  46 + />
  47 + <LinearLayout
  48 + android:layout_width="match_parent"
  49 + android:layout_height="wrap_content"
  50 + android:orientation="horizontal">
  51 + <Button
  52 + android:id="@+id/btn_videoPlay_chat"
  53 + android:layout_width="wrap_content"
  54 + android:layout_height="wrap_content"
  55 + android:text="发送hello"
  56 + android:visibility="gone"
  57 + />
  58 + <Button
  59 + android:id="@+id/btn_videoPlay_pubsherVideo"
  60 + android:layout_width="wrap_content"
  61 + android:layout_height="wrap_content"
  62 + android:text="获取推流地址"
  63 + />
  64 + </LinearLayout>
  65 +</LinearLayout>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:orientation="vertical" android:layout_width="wrap_content"
  4 + android:gravity="center"
  5 + android:background="#ffffff"
  6 + android:layout_height="wrap_content">
  7 +<EditText
  8 + android:id="@+id/dialog_edt_username"
  9 + android:layout_width="100dp"
  10 + android:layout_height="wrap_content"
  11 + android:hint="用户名"/>
  12 + <EditText
  13 + android:id="@+id/dialog_edt_userpwd"
  14 + android:layout_width="100dp"
  15 + android:layout_height="wrap_content"
  16 + android:hint="密码"/>
  17 + <Button
  18 + android:id="@+id/dialog_btn_enter"
  19 + android:layout_width="100dp"
  20 + android:layout_height="wrap_content"
  21 + android:text="登录"
  22 + />
  23 +</LinearLayout>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<TextView xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="match_parent"
  5 + android:gravity="center" />
  1 +<resources>
  2 + <!-- Example customization of dimensions originally defined in res/values/dimens.xml
  3 + (such as screen margins) for screens with more than 820dp of available width. This
  4 + would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
  5 + <dimen name="activity_horizontal_margin">64dp</dimen>
  6 +</resources>
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<resources>
  3 + <color name="colorPrimary">#3F51B5</color>
  4 + <color name="colorPrimaryDark">#303F9F</color>
  5 + <color name="colorAccent">#FF4081</color>
  6 +</resources>
  1 +<resources>
  2 + <!-- Default screen margins, per the Android Design guidelines. -->
  3 + <dimen name="activity_horizontal_margin">16dp</dimen>
  4 + <dimen name="activity_vertical_margin">16dp</dimen>
  5 +</resources>
  1 +<resources>
  2 + <string name="app_name">学点云</string>
  3 +</resources>
  1 +<resources>
  2 +
  3 + <!-- Base application theme. -->
  4 + <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
  5 + <!-- Customize your theme here. -->
  6 + <item name="colorPrimary">@color/colorPrimary</item>
  7 + <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
  8 + <item name="colorAccent">@color/colorAccent</item>
  9 + </style>
  10 + <style name="bottom_dialog" parent="android:style/Theme.Dialog">
  11 + <item name="android:windowFrame">@null</item>
  12 + <item name="android:windowNoTitle">true</item>
  13 + <item name="android:windowIsFloating">true</item>
  14 + <item name="android:windowIsTranslucent">true</item>
  15 + <item name="android:windowBackground">@android:color/transparent</item>
  16 + <item name="android:windowAnimationStyle">@style/Animation_Bottom_Dialog</item>
  17 + </style>
  18 +
  19 + <style name="Animation_Bottom_Dialog">
  20 + <item name="android:windowEnterAnimation">@anim/input_method_enter</item>
  21 + <item name="android:windowExitAnimation">@anim/input_method_exit</item>
  22 + </style>
  23 +</resources>
  1 +package com.mang.xdy.demo;
  2 +
  3 +import org.junit.Test;
  4 +
  5 +import static org.junit.Assert.*;
  6 +
  7 +/**
  8 + * Example local unit test, which will execute on the development machine (host).
  9 + *
  10 + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
  11 + */
  12 +public class ExampleUnitTest {
  13 + @Test
  14 + public void addition_isCorrect() throws Exception {
  15 + assertEquals(4, 2 + 2);
  16 + }
  17 +}
  1 +apply plugin: 'com.android.application'
  2 +
  3 +android {
  4 + compileSdkVersion 25
  5 + buildToolsVersion "25.0.2"
  6 + defaultConfig {
  7 + applicationId "xdycom.abao.myapplication"
  8 + minSdkVersion 15
  9 + targetSdkVersion 25
  10 + versionCode 1
  11 + versionName "1.0"
  12 + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  13 +// ndk {
  14 +// // 设置支持的SO库架构
  15 +// abiFilters 'arm64-v8a' //, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
  16 +// }
  17 + }
  18 + buildTypes {
  19 + release {
  20 + minifyEnabled false
  21 + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  22 + }
  23 + }
  24 + repositories {
  25 + flatDir {
  26 + dirs 'libs'
  27 + }
  28 + }
  29 +}
  30 +
  31 +dependencies {
  32 + compile fileTree(include: ['*.jar'], dir: 'libs')
  33 + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
  34 + exclude group: 'com.android.support', module: 'support-annotations'
  35 + })
  36 + compile 'com.android.support:appcompat-v7:25.3.0'
  37 + testCompile 'junit:junit:4.12'
  38 + compile project(':xdy')
  39 + compile 'com.tencent.bugly:crashreport:2.5.0'
  40 + compile 'com.google.code.gson:gson:2.7'
  41 + compile'com.android.support:design:22.2.0'
  42 +}
  1 +# Add project specific ProGuard rules here.
  2 +# By default, the flags in this file are appended to flags specified
  3 +# in C:\Users\admin\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
  4 +# You can edit the include path and order by changing the proguardFiles
  5 +# directive in build.gradle.
  6 +#
  7 +# For more details, see
  8 +# http://developer.android.com/guide/developing/tools/proguard.html
  9 +
  10 +# Add any project specific keep options here:
  11 +
  12 +# If your project uses WebView with JS, uncomment the following
  13 +# and specify the fully qualified class name to the JavaScript interface
  14 +# class:
  15 +#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
  16 +# public *;
  17 +#}
  1 +package xdycom.abao.myapplication;
  2 +
  3 +import android.content.Context;
  4 +import android.support.test.InstrumentationRegistry;
  5 +import android.support.test.runner.AndroidJUnit4;
  6 +
  7 +import org.junit.Test;
  8 +import org.junit.runner.RunWith;
  9 +
  10 +import static org.junit.Assert.*;
  11 +
  12 +/**
  13 + * Instrumentation test, which will execute on an Android device.
  14 + *
  15 + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
  16 + */
  17 +@RunWith(AndroidJUnit4.class)
  18 +public class ExampleInstrumentedTest {
  19 + @Test
  20 + public void useAppContext() throws Exception {
  21 + // Context of the app under test.
  22 + Context appContext = InstrumentationRegistry.getTargetContext();
  23 +
  24 + assertEquals("xdycom.abao.myapplication", appContext.getPackageName());
  25 + }
  26 +}
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3 + package="xdycom.abao.myapplication">
  4 +
  5 + <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  6 + <uses-permission android:name="android.permission.INTERNET" />
  7 + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  8 + <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  9 + <uses-permission android:name="android.permission.READ_LOGS" />
  10 + <uses-permission android:name="android.permission.CAMERA"/>
  11 + <uses-permission android:name="android.permission.RECORD_AUDIO"/>
  12 + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  13 +
  14 + <uses-feature android:name="android.hardware.camera" />
  15 + <uses-feature android:name="android.hardware.camera.autofocus" />
  16 + <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
  17 + <uses-permission android:name="android.permission.INTERNET" />
  18 + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  19 + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  20 + <uses-permission android:name="android.permission.RECORD_AUDIO" />
  21 + <uses-permission android:name="android.permission.WAKE_LOCK" />
  22 + <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  23 + <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
  24 + <uses-permission android:name="android.permission.CAMERA" />
  25 + <uses-permission android:name="android.permission.VIBRATE" />
  26 +
  27 + <application
  28 + android:name=".application.MyApplicaiton"
  29 + android:allowBackup="true"
  30 + android:icon="@mipmap/ic_launcher"
  31 + android:label="@string/app_name"
  32 + android:supportsRtl="true"
  33 + android:theme="@style/AppTheme">
  34 + <activity android:name=".Threeivity">
  35 + <intent-filter>
  36 + <action android:name="android.intent.action.MAIN" />
  37 +
  38 + <category android:name="android.intent.category.LAUNCHER" />
  39 + </intent-filter>
  40 + </activity>
  41 +
  42 + <service
  43 + android:name=".MyService"
  44 + android:enabled="true"
  45 + android:exported="true" />
  46 +
  47 + <activity android:name=".SecondActivity" />
  48 + <activity android:name=".MainActivity" />
  49 + <activity android:name=".LunchActivity" />
  50 + <activity android:name="com.daniulive.smartplayer.SmartPlayer" />
  51 + <activity android:name=".WebviewActivity"></activity>
  52 + </application>
  53 +
  54 +</manifest>
  1 +package xdycom.abao.myapplication;
  2 +
  3 +import android.os.Build;
  4 +import android.support.v7.app.AppCompatActivity;
  5 +import android.os.Bundle;
  6 +import android.util.Log;
  7 +import android.view.LayoutInflater;
  8 +import android.view.View;
  9 +import android.webkit.JavascriptInterface;
  10 +import android.webkit.ValueCallback;
  11 +import android.webkit.WebChromeClient;
  12 +import android.webkit.WebResourceError;
  13 +import android.webkit.WebResourceRequest;
  14 +import android.webkit.WebView;
  15 +import android.webkit.WebViewClient;
  16 +import android.widget.Button;
  17 +import android.widget.Toast;
  18 +
  19 +import xdycom.abao.myapplication.application.MyApplicaiton;
  20 +import xdycom.abao.myapplication.utisl.StringUtils;
  21 +import xdycom.abao.myapplication.utisl.XdyWebView;
  22 +
  23 +public class LunchActivity extends AppCompatActivity implements View.OnClickListener{
  24 + private Button bt_start;
  25 + private MyWebView myWebView;
  26 + WebView webView;
  27 + private final static String URL="http://h5.test.3mang.com/web/";
  28 + @Override
  29 + protected void onCreate(Bundle savedInstanceState) {
  30 + super.onCreate(savedInstanceState);
  31 + setContentView(R.layout.activity_lunch);
  32 + bt_start= (Button) this.findViewById(R.id.bt_start);
  33 + bt_start.setOnClickListener(this);
  34 + init();
  35 +// initData();
  36 + }
  37 + public void init (){
  38 + bt_start= (Button) this.findViewById(R.id.bt_start);
  39 + bt_start.setOnClickListener(this);
  40 +// myWebView= (MyWebView) this.findViewById(R.id.mywebview);
  41 +
  42 + }
  43 +
  44 + public void initData(){
  45 + myWebView=new MyWebView(this);
  46 + myWebView.setWebChromeClient(new WebChromeClient(){
  47 + });
  48 + myWebView.setWebViewClient(new WebViewClient(){
  49 + @Override
  50 + public void onPageFinished(WebView view, String url) {
  51 + super.onPageFinished(view, url);
  52 + myWebView.loadUrl(URL);
  53 + }
  54 +
  55 + @Override
  56 + public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
  57 + super.onReceivedError(view, errorCode, description, failingUrl);
  58 + Log.e("webview","errorCode"+errorCode);
  59 + }
  60 + });
  61 + }
  62 +
  63 + @Override
  64 + public void onClick(View v) {
  65 + switch (v.getId()){
  66 + case R.id.bt_start:
  67 +// initClass();
  68 +// initClass();
  69 + inidwebView();
  70 + break;
  71 +
  72 + }
  73 + }
  74 +
  75 + /**
  76 + * 初始化课堂
  77 + */
  78 + public void initClass(){
  79 + View view= LayoutInflater.from(this).inflate(R.layout.activity_main,null);
  80 + webView= (WebView) view.findViewById(R.id.webview);
  81 + webView.setWebViewClient(new WebViewClient(){
  82 + @Override
  83 + public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
  84 + super.onReceivedError(view, request, error);
  85 + }
  86 +
  87 + });
  88 + webView.setWebChromeClient(new WebChromeClient(){
  89 + @Override
  90 + public void onConsoleMessage(String message, int lineNumber, String sourceID) {
  91 + super.onConsoleMessage(message, lineNumber, sourceID);
  92 + Log.e(null,"Message:"+message+" lineNumber:");
  93 + }
  94 + });
  95 + webView.getSettings().setJavaScriptEnabled(true);
  96 + webView.addJavascriptInterface(new MyJs(),"xdyAndroid" );
  97 + webView.loadUrl(URL);
  98 + String id="init";
  99 + String jsonParmps="{\n" +
  100 + " \"classId\": 527720984,\n" +
  101 + " \"portal\": \"112.126.80.182:90\",\n" +
  102 + " \"userRole\": \"normal\",\n" +
  103 + " \"userName\": \"\",\n" +
  104 + " \"userId\": 0\n" +
  105 + "}";
  106 + String jsonParmp= StringUtils.stringToJson(jsonParmps,true);
  107 + _native2js(id,jsonParmp);
  108 + }
  109 +
  110 + class MyJs {
  111 + @JavascriptInterface
  112 + public String _js2native(String id,String parmp){
  113 + /* _native2js("接口名称","参数为JOSN字符串")*/
  114 + Log.e("js2native","id:"+id+" parmp:"+parmp);
  115 + return parmp;
  116 + }
  117 +
  118 + @JavascriptInterface
  119 + public String _js2native(String parmp){
  120 + /* _native2js("接口名称","参数为JOSN字符串")*/
  121 + Log.e("js2native", " parmp:"+parmp);
  122 + return parmp;
  123 + }
  124 + }
  125 +
  126 + public String _native2js( String id, String parmp) {
  127 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  128 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  129 + webView.evaluateJavascript("javascript:_native2js('" + id + "','" + parmp + "')", new ValueCallback<String>() {
  130 + @Override
  131 + public void onReceiveValue(String value) {
  132 + Log.e("显示:界面","啊哈");
  133 + }
  134 + });
  135 + } else {
  136 +
  137 +// mWebView.loadUrl("javascript:imageVal('init')");
  138 + }
  139 +
  140 + }
  141 + return "";
  142 + }
  143 +
  144 +
  145 + public void inidwebView(){
  146 + WebView xdyWebView=new WebView(this);
  147 + xdyWebView.setWebViewClient(new WebViewClient(){
  148 + @Override
  149 + public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
  150 + return super.shouldOverrideUrlLoading(view, request);
  151 + }
  152 + });
  153 + xdyWebView.getSettings().setJavaScriptEnabled(true);//支持Html5标签
  154 + xdyWebView.getSettings().setDomStorageEnabled(true);//支持Html5标签
  155 + xdyWebView.addJavascriptInterface(new MyJs(),"xdyAndroid");
  156 + xdyWebView.loadUrl(URL);
  157 + String id="init";
  158 + String jsonParmps="{\n" +
  159 + " \"classId\": 527720984,\n" +
  160 + " \"portal\": \"112.126.80.182:90\",\n" +
  161 + " \"userRole\": \"normal\",\n" +
  162 + " \"userName\": \"\",\n" +
  163 + " \"userId\": 0\n" +
  164 + "}";
  165 + String jsonParmp= StringUtils.stringToJson(jsonParmps,true);
  166 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  167 + xdyWebView.evaluateJavascript("javascript:_native2js('" + id + "','" + jsonParmp + "')", new ValueCallback<String>() {
  168 + @Override
  169 + public void onReceiveValue(String value) {
  170 + Log.e("显示:界面","啊哈");
  171 + }
  172 + });
  173 + } else {
  174 +
  175 + xdyWebView.loadUrl("javascript:imageVal('init')");
  176 + }
  177 +
  178 + }
  179 +}
  1 +package xdycom.abao.myapplication;
  2 +
  3 +import android.app.Application;
  4 +import android.os.Build;
  5 +import android.os.Bundle;
  6 +import android.support.v7.app.AppCompatActivity;
  7 +import android.text.TextUtils;
  8 +import android.util.Log;
  9 +import android.view.View;
  10 +import android.webkit.ConsoleMessage;
  11 +import android.webkit.JavascriptInterface;
  12 +import android.webkit.ValueCallback;
  13 +import android.webkit.WebChromeClient;
  14 +import android.webkit.WebSettings;
  15 +import android.webkit.WebView;
  16 +import android.webkit.WebViewClient;
  17 +import android.widget.Button;
  18 +import android.widget.EditText;
  19 +import android.widget.Switch;
  20 +import android.widget.Toast;
  21 +
  22 +import xdycom.abao.myapplication.application.MyApplicaiton;
  23 +import xdycom.abao.myapplication.sdk.GetRtmp;
  24 +import xdycom.abao.myapplication.sdk.MessageType;
  25 +
  26 +import static xdycom.abao.myapplication.sdk.MessageType.CLASS_INIT_SUCCESS;
  27 +
  28 +/**
  29 + * 3.28 目前获取能初始化成功,注意需要对传入进来的jso需要n进行护处理,
  30 + * 遗漏:获取js返回值的时候接受方法有问题。。。
  31 + * 现在坑爹的需要布局的情况得到了解决,下步开始封装了
  32 + */
  33 +public class MainActivity extends AppCompatActivity {
  34 + private WebView mWebView;
  35 + private Button bt_getScorce,bt_initClass,bt_class,bt_text;
  36 + private final static String URL="http://h5.test.3mang.com/web/";
  37 + private boolean isFirst=false;
  38 + private EditText et_text;
  39 +
  40 +
  41 + @Override
  42 + protected void onCreate(Bundle savedInstanceState) {
  43 + super.onCreate(savedInstanceState);
  44 + setContentView(R.layout.activity_main);
  45 + mWebView= (WebView) this.findViewById(R.id.webview);
  46 + bt_getScorce= (Button) this.findViewById(R.id.bt_getScorce);
  47 + bt_initClass= (Button) this.findViewById(R.id.bt_initClass);
  48 + et_text= (EditText) this.findViewById(R.id.et_text);
  49 + bt_class= (Button) this.findViewById(R.id.bt_class);
  50 + bt_text= (Button) this.findViewById(R.id.bt_text);
  51 + init();
  52 + }
  53 + public void init(){
  54 + WebSettings webSettings=mWebView.getSettings();
  55 + webSettings.setJavaScriptEnabled(true);
  56 + mWebView.addJavascriptInterface(new MyJs(),"xdyAndroid");
  57 + mWebView.loadUrl(URL);
  58 + mWebView.setWebChromeClient(new WebChromeClient() {
  59 + @Override
  60 + public void onConsoleMessage(String message, int lineNumber, String sourceID) {
  61 + Log.e("webview", message + " -- From line " + lineNumber + " of " + sourceID);
  62 + String id="";
  63 + String jsonParmp="";
  64 + //需要解析
  65 +// switch(message){
  66 +// case "class_init_success":
  67 + if(!isFirst) {
  68 +// id = "joinClass";
  69 +// String temp = "{\n" +
  70 +// " \"userName\": \"\",\n" +
  71 +// " \"password\": \"\",\n" +
  72 +// " \"hasCamera\": true,\n" +
  73 +// " \"hasMicrophone\": true\n" +
  74 +// "}";
  75 +// jsonParmp = stringToJson(temp, true);
  76 +// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  77 +// mWebView.evaluateJavascript("javascript:_native2js('" + id + "','" + jsonParmp + "')", new ValueCallback<String>() {
  78 +// @Override
  79 +// public void onReceiveValue(String value) {
  80 +// Toast.makeText(MainActivity.this, "回调调用js" +
  81 +// "" + value, Toast.LENGTH_SHORT).show();
  82 +// }
  83 +// });
  84 +// } else {
  85 +//
  86 +// mWebView.loadUrl("javascript:imageVal('init')");
  87 +// }
  88 +// break;
  89 +// }
  90 + isFirst=true;
  91 + }
  92 +
  93 + }
  94 +
  95 + @Override
  96 + public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
  97 + return super.onConsoleMessage(consoleMessage);
  98 + }
  99 + });
  100 + bt_getScorce.setOnClickListener(new View.OnClickListener() {
  101 + @Override
  102 + public void onClick(View v) {
  103 +
  104 +//// (1).ios/android调用: _native2js("接口名称","参数为JOSN字符串")
  105 +//// (2).sdk发送消息给ios/android: _js2native("事件消息名称","参数为JOSN字符串")
  106 +// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  107 +// mWebView.evaluateJavascript("javascript:_native2js('" + interfaceName + ",'" + content + "')", new ValueCallback<String>() {
  108 +// @Override
  109 +// public void onReceiveValue(String value) {
  110 +// Toast.makeText(MainActivity.this,"回调调用js" +
  111 +// ""+value, Toast.LENGTH_SHORT).show();
  112 +//
  113 +// }
  114 +// });
  115 +// } else {
  116 +// mWebView.loadUrl("javascript:_native2js('" + interfaceName + ",'" + content + "')");
  117 +// }
  118 +
  119 + GetRtmp getRtmp=new GetRtmp(MainActivity.this);
  120 +// String jsonParmp="{\n" +
  121 +// " \"classId\": 527720984,\n" +
  122 +// " \"portal\": \"127.0.0.1:80\",\n" +
  123 +// " \"userRole\": \"normal\",\n" +
  124 +// " \"userName\": \"\",\n" +
  125 +// " \"userId\": 0\n" +
  126 +// "}"
  127 +// ;
  128 +// String rtmpString=getRtmp._native2js("init",jsonParmp);
  129 +// Log.e("rtmpString:",jsonParmp);
  130 +// Toast.makeText(MainActivity.this,rtmpString+"",Toast.LENGTH_LONG).show();
  131 +
  132 +
  133 + String joinClass="{\n" +
  134 + " \"userName\": \"base\",\n" +
  135 + " \"password\": \"123456\",\n" +
  136 + " \"hasCamera\": false,\n" +
  137 + " \"hasMicrophone\": false\n" +
  138 + "}";
  139 +
  140 +// String rtmpString_joinClass=getRtmp._native2js("class_init_success","");
  141 +// Log.e("rtmpString_joinClass:",joinClass);
  142 +// Toast.makeText(MainActivity.this,rtmpString_joinClass+"",Toast.LENGTH_SHORT).show();
  143 +
  144 + String id="init";
  145 + String jsonParmps="{\n" +
  146 + " \"classId\": 527720984,\n" +
  147 + " \"portal\": \"112.126.80.182:90\",\n" +
  148 + " \"userRole\": \"normal\",\n" +
  149 + " \"userName\": \"\",\n" +
  150 + " \"userId\": 0\n" +
  151 + "}";
  152 + String jsonParmp=stringToJson(jsonParmps,true);
  153 + Log.e("转化后的json:",""+jsonParmp);
  154 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  155 + mWebView.evaluateJavascript("javascript:_native2js('" + id + "','"+jsonParmp+"')", new ValueCallback<String>() {
  156 + @Override
  157 + public void onReceiveValue(String value) {
  158 + Toast.makeText(MainActivity.this, "回调调用js" +
  159 + "" + value, Toast.LENGTH_SHORT).show();
  160 + }
  161 + });
  162 + }else{
  163 +
  164 + mWebView.loadUrl("javascript:imageVal('init')");
  165 + }
  166 + }
  167 + });
  168 +
  169 + bt_initClass.setOnClickListener(new View.OnClickListener() {
  170 + @Override
  171 + public void onClick(View v) {
  172 + String id="";
  173 + String jsonParmp="";
  174 + id = "joinClass";
  175 + String temp = "{\n" +
  176 + " \"userName\":\"base\",\n" +
  177 + " \"password\":\"123321\",\n" +
  178 + " \"hasCamera\":false,\n" +
  179 + " \"hasMicrophone\":false}";
  180 +
  181 +// id = "chat_receive_message";
  182 +// String temp = "{\"fromNodeId\": 772410521,\n" +
  183 +// " \"toNodeId\": 0,\n" +
  184 +// " \"message\": \"Hello world!\",\n" +
  185 +// " \"fromName\": \"MyName\",\n" +
  186 +// " \"fromRole\": \"normal\"\n" +
  187 +// "}";
  188 + jsonParmp = stringToJson(temp, true);
  189 +
  190 + GetRtmp getRtmp=new GetRtmp(MainActivity.this);
  191 + getRtmp._native2js(id,jsonParmp);
  192 + _native2js(id,jsonParmp);
  193 +// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  194 +// mWebView.evaluateJavascript("javascript:_native2js('" + id + "','" + jsonParmp + "')", new ValueCallback<String>() {
  195 +// @Override
  196 +// public void onReceiveValue(String value) {
  197 +// Toast.makeText(MainActivity.this, "回调调用js" +
  198 +// "" + value, Toast.LENGTH_SHORT).show();
  199 +// }
  200 +// });
  201 +// } else {
  202 +//
  203 +// mWebView.loadUrl("javascript:imageVal('init')");
  204 +// }
  205 + }
  206 + });
  207 + bt_class.setOnClickListener(new View.OnClickListener() {
  208 + @Override
  209 + public void onClick(View v) {
  210 + String id= et_text.getText().toString();
  211 +// String id= "sendStartClass";
  212 + if(TextUtils.isEmpty(id)){
  213 + id="video_play";
  214 + }
  215 + id="video_play";
  216 + _native2js(id);
  217 + _native2js(id,"");
  218 +// String id;
  219 +// id = "chat_receive_message";
  220 +//// id = "sendChatMsg";
  221 +//
  222 +// String temp = "{\"fromNodeId\": 772410521,\n" +
  223 +// " \"toNodeId\": 0,\n" +
  224 +// " \"message\": \"Helloss world!\",\n" +
  225 +// " \"fromName\": \"base\",\n" +
  226 +// " \"fromRole\": \"normal\"\n" +
  227 +// "}";
  228 +//// String temp = "{ \"message\":\"Helloss world!\",\n" +
  229 +//// " \"to\":772410521}";
  230 +// String jsonParmp;
  231 +// jsonParmp = stringToJson(temp, true);
  232 +// _native2js(id,jsonParmp);
  233 + }
  234 + });
  235 +
  236 + bt_text.setOnClickListener(new View.OnClickListener() {
  237 + @Override
  238 + public void onClick(View v) {
  239 + String id="init";
  240 + String jsonParmps="{\n" +
  241 + " \"classId\": 527720984,\n" +
  242 + " \"portal\": \"112.126.80.182:90\",\n" +
  243 + " \"userRole\": \"normal\",\n" +
  244 + " \"userName\": \"\",\n" +
  245 + " \"userId\": 0\n" +
  246 + "}";
  247 + String jsonParmp=stringToJson(jsonParmps,true);
  248 + GetRtmp getRtmp=new GetRtmp(MainActivity.this);
  249 + getRtmp._native2js(id,jsonParmp);
  250 + }
  251 + });
  252 + }
  253 +
  254 + class MyJs {
  255 + @JavascriptInterface
  256 + public String _js2native(String id,String parmp){
  257 + /* _native2js("接口名称","参数为JOSN字符串")*/
  258 + Log.e("js2native","id:"+id+" parmp:"+parmp);
  259 + return parmp;
  260 + }
  261 +
  262 + @JavascriptInterface
  263 + public String _js2native(String parmp){
  264 + /* _native2js("接口名称","参数为JOSN字符串")*/
  265 + Log.e("js2native", " parmp:"+parmp);
  266 + return parmp;
  267 + }
  268 + }
  269 +
  270 + public static String stringToJson(String s,boolean isJSjson){
  271 + StringBuffer sb = new StringBuffer();
  272 + for(int i=0; i<s.length(); i++){
  273 + char c =s.charAt(i);
  274 + switch(c){
  275 + case'\'': if(isJSjson) {sb.append("\\\'");}else{sb.append("\'");} break;
  276 + case'\"': if(!isJSjson) {sb.append("\\\"");}else{sb.append("\"");} break;
  277 + case'\\':sb.append("\\\\"); break; //如果不处理单引号,可以释放此段代码,若结合StringDanYinToJSON()处理单引号就必须注释掉该段代码
  278 + case'/': sb.append("\\/");break;
  279 + case'\b':sb.append("\\b");break;//退格
  280 + case'\f':sb.append("\\f");break;//走纸换页
  281 + case'\n':sb.append("\\n");break;//换行
  282 + case'\r':sb.append("\\r");break;//回车
  283 + case'\t':sb.append("\\t");break;//横向跳格
  284 + default: sb.append(c);
  285 + }}
  286 + return sb.toString();
  287 + }
  288 +
  289 +
  290 +
  291 + /**
  292 + * 获取推流地址
  293 + * @return
  294 + */
  295 + public String _native2js( String id, String parmp) {
  296 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  297 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  298 + mWebView.evaluateJavascript("javascript:_native2js('" + id + "','" + parmp + "')", new ValueCallback<String>() {
  299 + @Override
  300 + public void onReceiveValue(String value) {
  301 + Toast.makeText(MainActivity.this, "回调调用js" +
  302 + "" + value, Toast.LENGTH_SHORT).show();
  303 + }
  304 + });
  305 + } else {
  306 +
  307 +// mWebView.loadUrl("javascript:imageVal('init')");
  308 + }
  309 +
  310 + }
  311 + return "";
  312 + }
  313 +
  314 + /**
  315 + * 获取推流地址 一个参数
  316 + * @return
  317 + */
  318 + public String _native2js( String id) {
  319 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  320 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  321 + mWebView.evaluateJavascript("javascript:_native2js('" + id + "')", new ValueCallback<String>() {
  322 + @Override
  323 + public void onReceiveValue(String value) {
  324 + Toast.makeText(MainActivity.this, "回调调用js" +
  325 + "" + value, Toast.LENGTH_SHORT).show();
  326 + }
  327 + });
  328 + } else {
  329 +
  330 +// mWebView.loadUrl("javascript:imageVal('init')");
  331 + }
  332 +
  333 + }
  334 + return "";
  335 + }
  336 +}
  1 +package xdycom.abao.myapplication;
  2 +
  3 +import android.app.Service;
  4 +import android.content.Intent;
  5 +import android.os.IBinder;
  6 +
  7 +public class MyService extends Service {
  8 + public MyService() {
  9 + }
  10 + private static MainActivity INSTANCE;
  11 + public static MainActivity getINSTANCE(){
  12 +
  13 + return INSTANCE;
  14 + }
  15 + @Override
  16 + public IBinder onBind(Intent intent) {
  17 + // TODO: Return the communication channel to the service.
  18 + throw new UnsupportedOperationException("Not yet implemented");
  19 + }
  20 +
  21 + @Override
  22 + public int onStartCommand(Intent intent, int flags, int startId) {
  23 + return super.onStartCommand(intent, flags, startId);
  24 + }
  25 +
  26 + @Override
  27 + public void onDestroy() {
  28 + super.onDestroy();
  29 + }
  30 +}
  1 +package xdycom.abao.myapplication;
  2 +
  3 +import android.content.Context;
  4 +import android.os.Build;
  5 +import android.util.AttributeSet;
  6 +import android.util.Log;
  7 +import android.webkit.JavascriptInterface;
  8 +import android.webkit.ValueCallback;
  9 +import android.webkit.WebSettings;
  10 +import android.webkit.WebView;
  11 +import android.widget.Toast;
  12 +
  13 +/**
  14 + * Created by abao on 2017/3/30.
  15 + */
  16 +
  17 +public class MyWebView extends WebView {
  18 + private final static String URL="http://h5.test.3mang.com/web/";
  19 + public MyWebView(Context context) {
  20 + super(context);
  21 +// myWebView=new MyWebView(context);
  22 +// WebSettings webSettings=myWebView.getSettings();
  23 +// webSettings.setJavaScriptEnabled(true);
  24 +// myWebView.addJavascriptInterface(new MyJs(),"xdyAndroid");
  25 +//
  26 +// myWebView.loadUrl(URL);
  27 + }
  28 +
  29 + public MyWebView(Context context, AttributeSet attrs) {
  30 + super(context, attrs);
  31 + }
  32 +
  33 + class MyJs {
  34 + @JavascriptInterface
  35 + public String _js2native(String id,String parmp){
  36 + /* _native2js("接口名称","参数为JOSN字符串")*/
  37 + Log.e("js2native","id:"+id+" parmp:"+parmp);
  38 + return parmp;
  39 + }
  40 +
  41 + @JavascriptInterface
  42 + public String _js2native(String parmp){
  43 + /* _native2js("接口名称","参数为JOSN字符串")*/
  44 + Log.e("js2native", " parmp:"+parmp);
  45 + return parmp;
  46 + }
  47 + }
  48 +
  49 + /**
  50 + * 获取推流地址
  51 + * @return
  52 + */
  53 + public String _native2js( String id, String parmp) {
  54 +// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  55 +// myWebView.evaluateJavascript("javascript:_native2js('" + id + "','" + parmp + "')", new ValueCallback<String>() {
  56 +// @Override
  57 +// public void onReceiveValue(String value) {
  58 +// Log.e("MSG_evaluate","_native2js"+value);
  59 +// }
  60 +// });
  61 +// } else {
  62 +//
  63 +//// mWebView.loadUrl("javascript:imageVal('init')");
  64 +// }
  65 + return "";
  66 + }
  67 +}
  1 +package xdycom.abao.myapplication;
  2 +
  3 +import android.os.Build;
  4 +import android.support.v7.app.AppCompatActivity;
  5 +import android.os.Bundle;
  6 +import android.util.Log;
  7 +import android.view.View;
  8 +import android.webkit.JavascriptInterface;
  9 +import android.webkit.ValueCallback;
  10 +import android.webkit.WebResourceRequest;
  11 +import android.webkit.WebSettings;
  12 +import android.webkit.WebView;
  13 +import android.webkit.WebViewClient;
  14 +import android.widget.Button;
  15 +import android.widget.Toast;
  16 +
  17 +import xdycom.abao.myapplication.application.MyApplicaiton;
  18 +import xdycom.abao.myapplication.utisl.StringUtils;
  19 +import xdycom.abao.myapplication.view.WebViewBase;
  20 +
  21 +public class SecondActivity extends AppCompatActivity {
  22 + WebView webViewBase;
  23 + private final static String URL="http://h5.test.3mang.com/web/";
  24 + private Button bt_class;
  25 + @Override
  26 + protected void onCreate(Bundle savedInstanceState) {
  27 + super.onCreate(savedInstanceState);
  28 + setContentView(R.layout.activity_second);
  29 + bt_class= (Button) this.findViewById(R.id.bt_class);
  30 + bt_class.setOnClickListener(new View.OnClickListener() {
  31 + @Override
  32 + public void onClick(View v) {
  33 + String id="init";
  34 + String jsonParmps="{\n" +
  35 + " \"classId\": 527720984,\n" +
  36 + " \"portal\": \"112.126.80.182:90\",\n" +
  37 + " \"userRole\": \"normal\",\n" +
  38 + " \"userName\": \"\",\n" +
  39 + " \"userId\": 0\n" +
  40 + "}";
  41 + String jsonParmp= StringUtils.stringToJson(jsonParmps,true);
  42 + Log.e("转化后的json:",""+jsonParmp);
  43 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  44 + webViewBase.evaluateJavascript("javascript:_native2js('" + id + "','"+jsonParmp+"')", new ValueCallback<String>() {
  45 + @Override
  46 + public void onReceiveValue(String value) {
  47 + Toast.makeText(SecondActivity.this, "回调调用js" +
  48 + "" + value, Toast.LENGTH_SHORT).show();
  49 + }
  50 + });
  51 + }else{
  52 +
  53 + webViewBase.loadUrl("javascript:imageVal('init')");
  54 + }
  55 + }
  56 + });
  57 +
  58 +
  59 + init();
  60 + }
  61 + public void init(){
  62 + webViewBase=new WebView(MyApplicaiton.getInstance());
  63 + WebSettings webSettings=webViewBase.getSettings();
  64 + webSettings.setJavaScriptEnabled(true);
  65 +// webViewBase.setWebViewClient(new WebViewClient(){
  66 +// @Override
  67 +// public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
  68 +// return super.shouldOverrideUrlLoading(view, request);
  69 +// }
  70 +// });
  71 + webViewBase.addJavascriptInterface(new MyJs(),"xdyAndroid");
  72 + webViewBase.loadUrl(URL);
  73 + }
  74 +
  75 +
  76 + class MyJs {
  77 + @JavascriptInterface
  78 + public String _js2native(String id,String parmp){
  79 + /* _native2js("接口名称","参数为JOSN字符串")*/
  80 + Log.e("s3sjs2native","id:"+id+" parmp:"+parmp);
  81 + return parmp;
  82 + }
  83 +
  84 + @JavascriptInterface
  85 + public String _js2native(String parmp){
  86 + /* _native2js("接口名称","参数为JOSN字符串")*/
  87 + Log.e("js2native", " parmp:"+parmp);
  88 + return parmp;
  89 + }
  90 + }
  91 +}
  1 +package xdycom.abao.myapplication;
  2 +
  3 +import android.content.Intent;
  4 +import android.net.Uri;
  5 +import android.os.Bundle;
  6 +import android.support.v7.app.AppCompatActivity;
  7 +import android.util.Log;
  8 +import android.view.SurfaceView;
  9 +import android.view.View;
  10 +import android.webkit.JavascriptInterface;
  11 +import android.webkit.WebSettings;
  12 +import android.webkit.WebView;
  13 +import android.widget.Button;
  14 +
  15 +import com.eventhandle.SmartEventCallback;
  16 +import com.google.gson.Gson;
  17 +import com.mang.xdy.core.XdySdk;
  18 +import com.mang.xdy.utils.XdyLogUtil;
  19 +import com.mang.xdy.utils.XdyStringUtils;
  20 +
  21 +import xdycom.abao.myapplication.entity.LiveBean;
  22 +import xdycom.abao.myapplication.utisl.StringUtils;
  23 +
  24 +import static xdycom.abao.myapplication.MainActivity.stringToJson;
  25 +
  26 +public class Threeivity extends AppCompatActivity implements View.OnClickListener{
  27 + private Button bt_three,bt_video
  28 + ,bt_paudio,bt_stopaudiopub,bt_back,bt_stopReco;
  29 + private WebView webView;
  30 + private final static String URL="http://h5.test.3mang.com/web/";
  31 + private SurfaceView surface;
  32 + private Button bt_stop;
  33 + @Override
  34 + protected void onCreate(Bundle savedInstanceState) {
  35 + super.onCreate(savedInstanceState);
  36 + setContentView(R.layout.activity_threeivity);
  37 + bt_three= (Button) findViewById(R.id.bt_three);
  38 + bt_video= (Button) findViewById(R.id.bt_video);
  39 + surface= (SurfaceView) findViewById(R.id.surface);
  40 + bt_stop= (Button) findViewById(R.id.bt_stop);
  41 + bt_paudio= (Button) findViewById(R.id.bt_paudio);
  42 + bt_paudio.setOnClickListener(this);
  43 + bt_stopaudiopub= (Button) findViewById(R.id.bt_stopaudiopub);
  44 + bt_back= (Button) findViewById(R.id.bt_back);
  45 + bt_back.setOnClickListener(this);
  46 + bt_stopaudiopub.setOnClickListener(this);
  47 + bt_stopReco= (Button) findViewById(R.id.bt_stopReco);
  48 + bt_stopReco.setOnClickListener(this);
  49 + bt_three.setOnClickListener(new View.OnClickListener() {
  50 + @Override
  51 + public void onClick(View v) {
  52 + String id="init";
  53 + String jsonParmps="{\n" +
  54 + " \"classId\": 1184939098,\n" +
  55 + " \"portal\": \"112.126.80.182:90\",\n" +
  56 + " \"userRole\": \"normal\",\n" +
  57 + " \"userName\": \"\",\n" +
  58 + " \"userId\": 0\n" +
  59 + "}";
  60 + String jsonParmp= StringUtils.stringToJson(jsonParmps,true);
  61 + getSdySdk(id,jsonParmp);
  62 + }
  63 + });
  64 +
  65 +
  66 + bt_video.setOnClickListener(new View.OnClickListener() {
  67 + @Override
  68 + public void onClick(View v) {
  69 + String id = "joinClass";
  70 + String temp = "{\n" +
  71 + " \"userName\":\"base\",\n" +
  72 + " \"password\":\"123321\",\n" +
  73 + " \"hasCamera\":false,\n" +
  74 + " \"hasMicrophone\":false}";
  75 +
  76 +// "}";
  77 + String jsonParmp = stringToJson(temp, true);
  78 + getSdySdk(id,jsonParmp);
  79 +// SmartPlayerNoLayout smartPlayerNoLayout=new SmartPlayerNoLayout(surface, Threeivity.this);
  80 +// startActivity(new Intent(Threeivity.this,SmartPlayer.class));
  81 + String url= "rtmp://123.56.205.116:6000/live/h5dev_1999957388_980_983041_1491813919";;
  82 +//// XdyPlayerCore xdyPlayer=new XdyPlayerCore(url,surface,Threeivity.this);
  83 +//// xdyPlayer.playVideo(url,surface);
  84 +// XdySdk.setAsyncApi("playAudio",url,null,Threeivity.this);
  85 +// XdySdk.setAsyncApi("playVideo",url,surface,Threeivity.this,new EventHande());
  86 + XdySdk.setAsyncApi("publishVideo",url,surface,Threeivity.this,new EventHande());
  87 +// xdyPlayer.playVideo("",surface);
  88 +
  89 +// XdyPublisherCore xdyPublisherCore=new XdyPublisherCore(Threeivity.this);
  90 +// xdyPublisherCore.publish("",surface);
  91 + }
  92 + });
  93 +
  94 + bt_stop.setOnClickListener(new View.OnClickListener() {
  95 + @Override
  96 + public void onClick(View v) {
  97 + XdySdk.onPlayStop();
  98 +// XdySdk.onPublisherStop();;
  99 + }
  100 + });
  101 + init();
  102 + }
  103 + public void init(){
  104 + webView=new WebView(this);
  105 + WebSettings settings=webView.getSettings();
  106 + settings.setJavaScriptEnabled(true);
  107 + webView.addJavascriptInterface(new MyJsH(),"xdyAndroid");
  108 + webView.loadUrl(URL);
  109 +
  110 + }
  111 +
  112 + @Override
  113 + public void onClick(View v) {
  114 + switch (v.getId()){
  115 + case R.id.bt_paudio:
  116 + //开始推送音频
  117 + String url= "rtmp://player.daniulive.com:1935/hls/stream";;
  118 + XdySdk.setAsyncApi("publishAudio",url,surface,Threeivity.this);
  119 + break;
  120 + case R.id.bt_stopaudiopub:
  121 + //停止
  122 +// XdySdk.setAsyncApi("unPublishAudio","");
  123 + String id="initRecordPlayback";
  124 +// String id="startRecordPlayback";
  125 + String param="{\n" +
  126 + " \"classId\": 479270427 ,\n" +
  127 + " \"portal\": \"112.126.80.182:90\",\n" +
  128 + " \"userRole\": \"normal\",\n" +
  129 + " \"userName\": \"\",\n" +
  130 + " \"userId\": 0\n" +
  131 + "}";
  132 + String ss=StringUtils.stringToJson(param,true);
  133 + XdySdk.setAsyncApi(id,ss);
  134 + break;
  135 + case R.id.bt_back:
  136 +// String id="initRecordPlayback";
  137 + String ids="startRecordPlayback";
  138 +// String param="{\n" +
  139 +// " \"classId\": 1184939098,\n" +
  140 +// " \"portal\": \"112.126.80.182:90\",\n" +
  141 +// " \"userRole\": \"normal\",\n" +
  142 +// " \"userName\": \"\",\n" +
  143 +// " \"userId\": 0\n" +
  144 +// "}";
  145 +// String ss=StringUtils.stringToJson(param,true);
  146 + XdySdk.setAsyncApi(ids,"");
  147 + break;
  148 + case R.id.bt_stopReco:
  149 +// String isd="stopRecordPlayback";
  150 +// XdySdk.setAsyncApi(isd,"");
  151 +// String ids_new="seekRecordPlayback";
  152 +// String tem="{\n" +
  153 +// " \"time\": 50\n" +
  154 +// "}";
  155 +// String s= StringUtils.stringToJson(tem,true);
  156 +// XdySdk.setAsyncApi(ids_new,s);
  157 +
  158 + String ids_new="getVideoPublishPath";
  159 + String tem="{ \"type\": \"live\"}";
  160 + String s= StringUtils.stringToJson(tem,true);
  161 + XdySdk.setAsyncApi(ids_new,s);
  162 +
  163 +
  164 + break;
  165 + }
  166 + }
  167 +
  168 + class MyJsH{
  169 + @JavascriptInterface
  170 + public String _js2native(String id,String parmp){
  171 + /* _native2js("接口名称","参数为JOSN字符串")*/
  172 + Log.e("s3sjs2native","id:"+id+" parmp:"+parmp);
  173 + return parmp;
  174 + }
  175 +
  176 + }
  177 +
  178 + public void getSdySdk(String id,String parameter){
  179 +// XdyCore core=XdyCore.getInstance(MyApplicaiton.getInstance());
  180 +// core.native2js(id,parameter);
  181 +// core.setXdyAsyncMessageListener(new XdyCore.XdyAsyncMessageListener() {
  182 +// @Override
  183 +// public void getSdyAsyncMessageListener(String s, String s1) {
  184 +// LogUtil.e("java_native",s+":"+s1);
  185 +// }
  186 +// });
  187 + XdySdk.setAsyncApi(id,parameter);
  188 +// XdySdk.getXdyInstance().setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
  189 +// @Override
  190 +// public void onXdyAsyncMessageReceiver(String type, String response) {
  191 +// XdyLogUtil.e("学点云",type+":"+response);
  192 +// }
  193 +// });
  194 +
  195 + XdySdk.setOnXdyAsyncMessageLitener(new XdySdk.OnXdyAsyncMessageLitener() {
  196 + @Override
  197 + public void onXdyAsyncMessageReceiver(String type, String response) {
  198 + XdyLogUtil.e("学点云static", type + ":" + response);
  199 +// if ("video_play".equals(type)) {
  200 +// MessageBean messageBean = new Gson().fromJson(response, MessageBean.class);
  201 +// if (messageBean != null) {
  202 +//// Intent intent = new Intent(Threeivity.this, SmartPlayer.class);
  203 +//// intent.putExtra("url", messageBean.getRtmpUrl() + "");
  204 +//// startActivity(intent);
  205 +// Toast.makeText(Threeivity.this, messageBean.getRtmpUrl(), Toast.LENGTH_SHORT).show();
  206 +//// SmartPlayerNoLayout smartPlayerNoLayout=new SmartPlayerNoLayout(surface,Threeivity.this);
  207 +// }
  208 +// }
  209 + if("live".equals(type)){
  210 +// String urls= "rtmp://player.daniulive.com:1935/hls/stream";;
  211 + String url = XdyStringUtils.stringToJson(response);
  212 + XdyLogUtil.e("调用任务了播视频了url:",""+url);
  213 + String us=response.substring(1,response.length()-1);
  214 + XdyLogUtil.e("调用任务了播视频了ursfdfl:",""+us);
  215 + try {
  216 +
  217 + LiveBean liveBean = new Gson().fromJson(url, LiveBean.class);
  218 +
  219 + if (liveBean != null) {
  220 + XdySdk.setAsyncApi("publishVideo", liveBean.getPublishUrl(), surface, Threeivity.this);
  221 + XdyLogUtil.e("调用任务了播视频了","哈哈哈哈");
  222 + }
  223 + }catch (Exception e){
  224 + XdyLogUtil.e("调用任务了播视频了e",""+e.getMessage());
  225 + XdyLogUtil.e("调用任务了播视频了url:",""+url);
  226 + }
  227 + }
  228 + }
  229 + });
  230 + }
  231 + public void playMedia(){
  232 + Intent intent = new Intent(Intent.ACTION_VIEW);
  233 + String bpath = "http://123.56.73.119:6001/live/h5dev_1184939098_980_983041_1491533378/total.m3u8";
  234 + intent.setDataAndType(Uri.parse(bpath), "video/*");
  235 + startActivity(intent);
  236 + }
  237 +
  238 +
  239 +}
  240 +
  241 +class EventHande implements SmartEventCallback {
  242 + private static String TAG="THREURL";
  243 +
  244 + @Override
  245 + public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5) {
  246 + switch (code) {
  247 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:
  248 + Log.i(TAG, "开始。。");
  249 + break;
  250 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:
  251 + Log.i(TAG, "连接中。。");
  252 + break;
  253 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:
  254 + Log.i(TAG, "连接失败。。");
  255 + break;
  256 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:
  257 + Log.i(TAG, "连接成功。。");
  258 + //TODO
  259 + break;
  260 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
  261 + Log.i(TAG, "连接断开。。");
  262 + break;
  263 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
  264 + Log.i(TAG, "关闭。。");
  265 + break;
  266 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
  267 + Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
  268 + break;
  269 + case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
  270 + Log.i(TAG, "收不到媒体数据,可能是url错误。。");
  271 + }
  272 +
  273 + }
  274 +}
  1 +package xdycom.abao.myapplication;
  2 +
  3 +import android.support.v7.app.AppCompatActivity;
  4 +import android.os.Bundle;
  5 +import android.util.Log;
  6 +import android.webkit.WebChromeClient;
  7 +import android.webkit.WebResourceRequest;
  8 +import android.webkit.WebSettings;
  9 +import android.webkit.WebView;
  10 +import android.webkit.WebViewClient;
  11 +import android.widget.Button;
  12 +
  13 +public class WebviewActivity extends AppCompatActivity {
  14 + private WebView mWebView;
  15 + @Override
  16 + protected void onCreate(Bundle savedInstanceState) {
  17 + super.onCreate(savedInstanceState);
  18 + setContentView(R.layout.activity_webview);
  19 + mWebView= (WebView) this.findViewById(R.id.webview);
  20 + WebSettings webSettings=mWebView.getSettings();
  21 + webSettings.setJavaScriptEnabled(true);
  22 +// mWebView.addJavascriptInterface(new XdyJavaScript(), APIContants.NATIVE_JS_LINK);
  23 + mWebView.setWebChromeClient(new WebChromeClient(){
  24 + @Override
  25 + public void onConsoleMessage(String message, int lineNumber, String sourceID) {
  26 + super.onConsoleMessage(message, lineNumber, sourceID);
  27 + Log.e("浏览器message",message+"linumber"+lineNumber+"sourceId"+sourceID);
  28 +
  29 + }
  30 + });
  31 + mWebView.setWebViewClient(new WebViewClient(){
  32 + @Override
  33 + public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
  34 + return super.shouldOverrideUrlLoading(view, request);
  35 + }
  36 + });
  37 +
  38 + 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");
  39 +
  40 + }
  41 +}
  1 +package xdycom.abao.myapplication;
  2 +
  3 +/**
  4 + * Created by abao on 2017/3/30.
  5 + */
  6 +
  7 +import android.content.Context;
  8 +import android.os.Build;
  9 +import android.util.Log;
  10 +import android.webkit.JavascriptInterface;
  11 +import android.webkit.ValueCallback;
  12 +import android.webkit.WebChromeClient;
  13 +import android.webkit.WebSettings;
  14 +import android.webkit.WebView;
  15 +
  16 +import com.mang.xdy.core.APIContants;
  17 +import com.mang.xdy.utils.XdyLogUtil;
  18 +
  19 +/**
  20 + * 需要提供两个参数的接口,一个参数的接口,同时给出回调(或者广播的方式)
  21 + * 数据的异常检测都放在最外层(便于给用户提示),这层默认数据都是完整
  22 + * 核心WebView 处理和调用的js
  23 + */
  24 +public class XdyCore {
  25 + private WebView mWebView;
  26 + private static XdyCore mXdyCore;
  27 +
  28 + /**
  29 + * 异步对外回调接口,所有回调都在此完成
  30 + */
  31 + protected interface OnXdyAsyncMessageListener {
  32 + void getSdyAsyncMessageListener(String id, String parameter);
  33 + };
  34 + private OnXdyAsyncMessageListener mOnXdyAsyncMessageListener;
  35 + /**
  36 + * 设置Async监听
  37 + * @param onXdyAsyncMessageListener
  38 + */
  39 + protected void setXdyAsyncMessageListener(OnXdyAsyncMessageListener onXdyAsyncMessageListener){
  40 + mOnXdyAsyncMessageListener = onXdyAsyncMessageListener;
  41 + }
  42 + private XdyCore(Context context) {
  43 + if(context==null){
  44 + return;
  45 + }
  46 + init(context);
  47 + }
  48 +
  49 + /**
  50 + * 初始化
  51 + * @param context
  52 + */
  53 + protected void init(Context context){
  54 + mWebView=new WebView(context);
  55 + WebSettings webSettings=mWebView.getSettings();
  56 + webSettings.setJavaScriptEnabled(true);
  57 +// mWebView.addJavascriptInterface(new XdyJavaScript(), APIContants.NATIVE_JS_LINK);
  58 + mWebView.setWebChromeClient(new WebChromeClient(){
  59 + @Override
  60 + public void onConsoleMessage(String message, int lineNumber, String sourceID) {
  61 + super.onConsoleMessage(message, lineNumber, sourceID);
  62 + Log.e("浏览器message",message+"linumber"+lineNumber+"sourceId"+sourceID);
  63 + }
  64 + });
  65 + 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");
  66 + }
  67 +
  68 + /**
  69 + * 获取XdyCore实例
  70 + * @param context
  71 + * @return
  72 + */
  73 + protected final static XdyCore getInstance(Context context){
  74 + if(mXdyCore==null){
  75 + synchronized(XdyCore.class){
  76 + if(mXdyCore==null){
  77 + mXdyCore=new XdyCore(context);
  78 + }
  79 + }
  80 + }
  81 + return mXdyCore;
  82 + }
  83 + /**
  84 + * 异步Js2Native
  85 + */
  86 + protected class XdyJavaScript{
  87 + @JavascriptInterface
  88 + public void _js2native(String id,String parmp){
  89 + /* _native2js("接口名称","参数为JOSN字符串")*/
  90 + XdyLogUtil.e("s3sjs2native","id:"+id+" parmp:"+parmp);
  91 + if(mOnXdyAsyncMessageListener !=null){
  92 + mOnXdyAsyncMessageListener.getSdyAsyncMessageListener(id,parmp);
  93 + }
  94 + }
  95 + }
  96 +
  97 + /**
  98 + * native调用js
  99 + * @param id
  100 + * @param parameter
  101 + */
  102 + protected void native2js(String id,String parameter){
  103 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  104 + mWebView.evaluateJavascript("javascript:_native2js('" + id + "','"+parameter+"')", new ValueCallback<String>() {
  105 + @Override
  106 + public void onReceiveValue(String value) {
  107 + }
  108 + });
  109 + }else{
  110 +
  111 + mWebView.loadUrl("javascript:_native2js('" + id + "','"+parameter+"')");
  112 + }
  113 + }
  114 +}
  1 +package xdycom.abao.myapplication.application;
  2 +
  3 +import android.app.Activity;
  4 +import android.app.Application;
  5 +import android.content.Context;
  6 +
  7 +import com.mang.xdy.core.XdySdk;
  8 +import com.tencent.bugly.crashreport.CrashReport;
  9 +
  10 +/**
  11 + * Created by abao on 2017/3/30.
  12 + */
  13 +
  14 +public class MyApplicaiton extends Application {
  15 + private static Activity activityList;
  16 + private static Context context;
  17 + @Override
  18 + public void onCreate() {
  19 + super.onCreate();
  20 + context=this;
  21 + XdySdk.init(this);
  22 + CrashReport.initCrashReport(getApplicationContext(), "注册时申请的APPID", false);
  23 + }
  24 + public static Activity getActivity(){
  25 + return activityList;
  26 +
  27 + }
  28 +
  29 + public static void setActivity(Activity activity){
  30 + activityList=activity;
  31 + }
  32 + public static Context getInstance(){
  33 + return context;
  34 + }
  35 +
  36 +}
  1 +package xdycom.abao.myapplication.entity;
  2 +
  3 +/**
  4 + * Created by abao on 2017/4/7.
  5 + */
  6 +
  7 +public class LiveBean {
  8 +
  9 + /**
  10 + * code : 0
  11 + * data :
  12 + * publishUrl : rtmp: 123.56.205.116: 6000/live/h5dev_1184939098_0_983041_1491555151
  13 + */
  14 +
  15 + private int code;
  16 + private String data;
  17 + private String publishUrl;
  18 +
  19 + public int getCode() {
  20 + return code;
  21 + }
  22 +
  23 + public void setCode(int code) {
  24 + this.code = code;
  25 + }
  26 +
  27 + public String getData() {
  28 + return data;
  29 + }
  30 +
  31 + public void setData(String data) {
  32 + this.data = data;
  33 + }
  34 +
  35 + public String getPublishUrl() {
  36 + return publishUrl;
  37 + }
  38 +
  39 + public void setPublishUrl(String publishUrl) {
  40 + this.publishUrl = publishUrl;
  41 + }
  42 +}
  1 +package xdycom.abao.myapplication.entity;
  2 +
  3 +/**
  4 + * Created by admin on 2017/3/28.
  5 + */
  6 +
  7 +public class MessageBean {
  8 +
  9 + /**
  10 + * mediaId : 983041
  11 + * fromNodeId : 952527798
  12 + * userName : base
  13 + * m3u8Url : http://123.56.73.119:6001/live/h5dev_1184939098_980_983041_1490952529/index.m3u8
  14 + * rtmpUrl : rtmp://123.56.69.230:6000/live/h5dev_1184939098_980_983041_1490952529
  15 + * replay : http://123.56.73.119:6001/live/h5dev_1184939098_980_983041_1490952529/total.m3u8
  16 + * seek : 0
  17 + */
  18 +
  19 + private int mediaId;
  20 + private int fromNodeId;
  21 + private String userName;
  22 + private String m3u8Url;
  23 + private String rtmpUrl;
  24 + private String replay;
  25 + private int seek;
  26 +
  27 + public int getMediaId() {
  28 + return mediaId;
  29 + }
  30 +
  31 + public void setMediaId(int mediaId) {
  32 + this.mediaId = mediaId;
  33 + }
  34 +
  35 + public int getFromNodeId() {
  36 + return fromNodeId;
  37 + }
  38 +
  39 + public void setFromNodeId(int fromNodeId) {
  40 + this.fromNodeId = fromNodeId;
  41 + }
  42 +
  43 + public String getUserName() {
  44 + return userName;
  45 + }
  46 +
  47 + public void setUserName(String userName) {
  48 + this.userName = userName;
  49 + }
  50 +
  51 + public String getM3u8Url() {
  52 + return m3u8Url;
  53 + }
  54 +
  55 + public void setM3u8Url(String m3u8Url) {
  56 + this.m3u8Url = m3u8Url;
  57 + }
  58 +
  59 + public String getRtmpUrl() {
  60 + return rtmpUrl;
  61 + }
  62 +
  63 + public void setRtmpUrl(String rtmpUrl) {
  64 + this.rtmpUrl = rtmpUrl;
  65 + }
  66 +
  67 + public String getReplay() {
  68 + return replay;
  69 + }
  70 +
  71 + public void setReplay(String replay) {
  72 + this.replay = replay;
  73 + }
  74 +
  75 + public int getSeek() {
  76 + return seek;
  77 + }
  78 +
  79 + public void setSeek(int seek) {
  80 + this.seek = seek;
  81 + }
  82 +}