pangweixin 5 vuotta sitten
vanhempi
commit
27a700769b

+ 0 - 1
.idea/gradle.xml

@@ -12,7 +12,6 @@
           <set>
             <option value="$PROJECT_DIR$" />
             <option value="$PROJECT_DIR$/app" />
-            <option value="$PROJECT_DIR$/libWSLive" />
           </set>
         </option>
         <option name="resolveModulePerSourceSet" value="false" />

+ 1 - 1
.idea/misc.xml

@@ -10,7 +10,7 @@
         <entry key="app/src/main/res/drawable/toast_background.xml" value="0.2212962962962963" />
         <entry key="app/src/main/res/layout/activity_cam.xml" value="0.18297101449275363" />
         <entry key="app/src/main/res/layout/activity_live.xml" value="0.18931159420289856" />
-        <entry key="app/src/main/res/layout/activity_main.xml" value="0.1" />
+        <entry key="app/src/main/res/layout/activity_main.xml" value="0.165" />
         <entry key="app/src/main/res/layout/activity_scanner.xml" value="0.18297101449275363" />
         <entry key="app/src/main/res/layout/activity_web.xml" value="0.2028985507246377" />
         <entry key="app/src/main/res/layout/layout_download_dialog.xml" value="0.1" />

+ 0 - 1
app/build.gradle

@@ -39,7 +39,6 @@ dependencies {
     annotationProcessor 'com.yanzhenjie.andserver:processor:2.1.9'
     implementation 'com.just.agentweb:agentweb:4.1.4'
     implementation 'com.yanzhenjie.apache:httpcore:4.4.14.1'
-    implementation project(':libWSLive')
 
     // eventbus
     implementation 'org.greenrobot:eventbus:3.2.0'

+ 1 - 1
app/src/main/AndroidManifest.xml

@@ -6,6 +6,7 @@
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.CAMERA" />
     <uses-permission android:name="android.permission.VIBRATE" />
 
     <application
@@ -18,7 +19,6 @@
         android:roundIcon="@mipmap/ic_launcher_round"
         android:supportsRtl="true"
         android:theme="@style/Theme.HomeCareSAS">
-        <activity android:name=".activity.LiveActivity" />
         <activity android:name=".weiview.WebViewActivity" />
         <activity
             android:name=".activity.MainActivity"

+ 5 - 0
app/src/main/java/com/qingdaofushan/home/activity/CamActivity.java

@@ -11,6 +11,7 @@ import android.os.Build;
 import android.os.Bundle;
 import android.os.Environment;
 import android.provider.MediaStore;
+import android.util.Base64;
 import android.util.Log;
 import android.view.View;
 import android.widget.ImageView;
@@ -25,10 +26,14 @@ import androidx.core.content.FileProvider;
 import androidx.core.os.EnvironmentCompat;
 
 import com.qingdaofushan.home.R;
+import com.qingdaofushan.home.utils.ToastUtil;
 import com.qingdaofushan.home.utils.Uri2PathUtil;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.Date;
 import java.util.List;
 import java.util.Locale;

+ 0 - 118
app/src/main/java/com/qingdaofushan/home/activity/LiveActivity.java

@@ -1,118 +0,0 @@
-package com.qingdaofushan.home.activity;
-
-import androidx.appcompat.app.AppCompatActivity;
-
-import android.Manifest;
-import android.os.Bundle;
-import android.text.TextUtils;
-import android.view.View;
-import android.widget.RelativeLayout;
-
-import com.qingdaofushan.home.event.EventData;
-import com.qingdaofushan.home.R;
-import com.qingdaofushan.home.utils.ToastUtil;
-
-import org.greenrobot.eventbus.EventBus;
-
-import io.reactivex.Observable;
-import me.lake.librestreaming.core.listener.RESConnectionListener;
-import me.lake.librestreaming.ws.StreamAVOption;
-import me.lake.librestreaming.ws.StreamLiveCameraView;
-
-public class LiveActivity extends AppCompatActivity implements View.OnClickListener {
-
-    private StreamLiveCameraView mLiveCameraView;
-    private StreamAVOption streamAVOption;
-    private String rtmpUrl = "rtmp://blsspush.qingdaofushan.com/fushan/888888";
-    private RelativeLayout rl_suspend;
-    private RelativeLayout rl_stop;
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.activity_live);
-        initView();
-        rtmpUrl = getIntent().getStringExtra("url");
-        if (TextUtils.isEmpty(rtmpUrl)) {
-            ToastUtil.showToast("推流地址有误");
-            finish();
-            return;
-        }
-        initLiveConfig();
-        if (!mLiveCameraView.isStreaming()) {
-            mLiveCameraView.startStreaming(rtmpUrl);
-        }
-        findViewById(R.id.tv_stop).setOnClickListener(view -> {
-
-        });
-
-    }
-
-    private void initView() {
-        rl_suspend = findViewById(R.id.rl_suspend);
-        rl_stop = findViewById(R.id.rl_stop);
-        rl_suspend.setOnClickListener(this);
-        rl_stop.setOnClickListener(this);
-    }
-
-    @Override
-    public void onClick(View v) {
-        if (R.id.rl_suspend == v.getId()) {
-            //暂停
-            if (mLiveCameraView.isStreaming()) {
-                mLiveCameraView.stopStreaming();
-            }
-            EventBus.getDefault().post(new EventData(2));
-            finish();
-        } else if (R.id.rl_stop == v.getId()) {
-            //停止
-            if (mLiveCameraView.isStreaming()) {
-                mLiveCameraView.stopStreaming();
-            }
-            EventBus.getDefault().post(new EventData(1));
-            finish();
-        }
-    }
-
-    /**
-     * 设置推流参数
-     */
-    public void initLiveConfig() {
-        mLiveCameraView = findViewById(R.id.stream_previewView);
-
-        //参数配置 start
-        streamAVOption = new StreamAVOption();
-        streamAVOption.streamUrl = rtmpUrl;
-        //参数配置 end
-
-        mLiveCameraView.init(this, streamAVOption);
-        mLiveCameraView.addStreamStateListener(resConnectionListener);
-    }
-
-    RESConnectionListener resConnectionListener = new RESConnectionListener() {
-        @Override
-        public void onOpenConnectionResult(int result) {
-            //result 0成功  1 失败
-            ToastUtil.showToast("打开推流连接 状态:" + result + " 推流地址:" + rtmpUrl);
-        }
-
-        @Override
-        public void onWriteError(int errno) {
-            ToastUtil.showToast("推流出错,请尝试重连");
-        }
-
-        @Override
-        public void onCloseConnectionResult(int result) {
-            ToastUtil.showToast("关闭推流连接 状态:" + result);
-            //result 0成功  1 失败
-        }
-    };
-
-    @Override
-    protected void onDestroy() {
-        super.onDestroy();
-        mLiveCameraView.destroy();
-    }
-
-
-}

+ 5 - 13
app/src/main/java/com/qingdaofushan/home/activity/MainActivity.java

@@ -45,9 +45,6 @@ import java.util.LinkedList;
 import java.util.List;
 
 import io.reactivex.Observable;
-import me.lake.librestreaming.core.listener.RESConnectionListener;
-import me.lake.librestreaming.ws.StreamAVOption;
-import me.lake.librestreaming.ws.StreamLiveCameraView;
 
 public class MainActivity extends AppCompatActivity {
 
@@ -64,25 +61,22 @@ public class MainActivity extends AppCompatActivity {
         findViewById(R.id.start).setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
-//                initApp("https://pwxmax.cn/homeLifemini.zip", 1);
+                initApp("https://pwxmax.cn/homeLifemini.zip", 1);
 //                mServerManager.startServer();
-                Intent intent = new Intent(MainActivity.this, WebViewActivity.class);
+//                Intent intent = new Intent(MainActivity.this, WebViewActivity.class);
 //                intent.putExtra("url", editText.getText().toString());
-                intent.putExtra("url", "http://127.0.0.1:8080");
-                startActivity(intent);
+//                intent.putExtra("url", "http://127.0.0.1:8080");
+//                startActivity(intent);
             }
         });
     }
 
     private void initPermission() {
         XXPermissions.with(this)
-                .permission(Permission.NOTIFICATION_SERVICE)
                 .permission(Permission.WRITE_EXTERNAL_STORAGE)
                 .permission(Permission.READ_EXTERNAL_STORAGE)
                 .permission(Permission.CAMERA)
-                .permission(Permission.RECORD_AUDIO)
                 .request(new OnPermissionCallback() {
-
                     @Override
                     public void onGranted(List<String> permissions, boolean all) {
                         if (all) {
@@ -264,10 +258,8 @@ public class MainActivity extends AppCompatActivity {
     protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
         super.onActivityResult(requestCode, resultCode, data);
         if (requestCode == XXPermissions.REQUEST_CODE) {
-            if (XXPermissions.isGranted(this, Permission.NOTIFICATION_SERVICE)
-                    && XXPermissions.isGranted(this, Permission.WRITE_EXTERNAL_STORAGE)
+            if (XXPermissions.isGranted(this, Permission.WRITE_EXTERNAL_STORAGE)
                     && XXPermissions.isGranted(this, Permission.READ_EXTERNAL_STORAGE)
-                    && XXPermissions.isGranted(this, Permission.RECORD_AUDIO)
                     && XXPermissions.isGranted(this, Permission.CAMERA)) {
 
             } else {

+ 2 - 2
app/src/main/java/com/qingdaofushan/home/component/App.java

@@ -75,7 +75,7 @@ public class App extends Application {
         } else {
             mRootDir = context.getFilesDir();
         }
-        mRootDir = new File(mRootDir, "HomeCareSAS");
+        mRootDir = new File(mRootDir, "Home");
         IOUtils.createFolder(mRootDir);
     }
     /**
@@ -92,7 +92,7 @@ public class App extends Application {
      */
     private void initOkGo() {
         OkHttpClient.Builder builder = new OkHttpClient.Builder();
-        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor("HomeCareSAS");
+        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor("Home");
         //Log的打印级别决定了log显示的详细程度
         loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY);
         //log颜色级别,决定了log在控制台现实的颜色

+ 1 - 1
app/src/main/java/com/qingdaofushan/home/component/AppConfig.java

@@ -19,7 +19,7 @@ public class AppConfig implements WebConfig {
 
     @Override
     public void onConfig(Context context, Delegate delegate) {
-        delegate.addWebsite(new StorageWebsite(Environment.getExternalStorageDirectory().getAbsolutePath() + "/homeLife/homeLifemini/"));
+        delegate.addWebsite(new StorageWebsite(Environment.getExternalStorageDirectory().getAbsolutePath() + "/BedsideCare/BedsideCare/"));
 
         delegate.setMultipart(Multipart.newBuilder()
             .allFileMaxSize(1024 * 1024 * 20) // 20M

+ 17 - 20
app/src/main/java/com/qingdaofushan/home/weiview/AndroidInterface.java

@@ -1,7 +1,5 @@
 package com.qingdaofushan.home.weiview;
 
-import static com.just.agentweb.ActionActivity.REQUEST_CODE;
-
 import android.app.Activity;
 import android.content.Intent;
 import android.os.Handler;
@@ -9,7 +7,6 @@ import android.os.Looper;
 import android.webkit.JavascriptInterface;
 
 import com.just.agentweb.AgentWeb;
-import com.qingdaofushan.home.activity.LiveActivity;
 import com.qingdaofushan.home.event.EventData;
 import com.qingdaofushan.home.utils.SharedPreferenceUtil;
 import com.qingdaofushan.home.utils.ToastUtil;
@@ -74,23 +71,23 @@ public class AndroidInterface {
         });
     }
 
-    @JavascriptInterface
-    public void StartService(String json) {
-        deliver.post(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    JSONObject jsonObject = new JSONObject(json);
-                    String url = jsonObject.getString("url");
-                    Intent intent = new Intent(activity, LiveActivity.class);
-                    intent.putExtra("url", url);
-                    activity.startActivity(intent);
-                } catch (JSONException e) {
-                    ToastUtil.showToast("读取参数报错");
-                }
-            }
-        });
-    }
+//    @JavascriptInterface
+//    public void StartService(String json) {
+//        deliver.post(new Runnable() {
+//            @Override
+//            public void run() {
+//                try {
+//                    JSONObject jsonObject = new JSONObject(json);
+//                    String url = jsonObject.getString("url");
+//                    Intent intent = new Intent(activity, LiveActivity.class);
+//                    intent.putExtra("url", url);
+//                    activity.startActivity(intent);
+//                } catch (JSONException e) {
+//                    ToastUtil.showToast("读取参数报错");
+//                }
+//            }
+//        });
+//    }
 
     @JavascriptInterface
     public void Camera(String a) {

+ 38 - 2
app/src/main/java/com/qingdaofushan/home/weiview/WebViewActivity.java

@@ -12,6 +12,7 @@ import android.os.Build;
 import android.os.Bundle;
 import android.os.Environment;
 import android.provider.MediaStore;
+import android.util.Base64;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.webkit.WebSettings;
@@ -35,6 +36,7 @@ import com.just.agentweb.WebViewClient;
 import com.qingdaofushan.home.activity.CamActivity;
 import com.qingdaofushan.home.event.EventData;
 import com.qingdaofushan.home.R;
+import com.qingdaofushan.home.utils.ToastUtil;
 import com.qingdaofushan.home.utils.Uri2PathUtil;
 import com.qingdaofushan.home.zxing.view.Constant;
 
@@ -43,7 +45,10 @@ import org.greenrobot.eventbus.Subscribe;
 import org.greenrobot.eventbus.ThreadMode;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.Date;
 import java.util.List;
 import java.util.Locale;
@@ -183,7 +188,7 @@ public class WebViewActivity extends AppCompatActivity {
                     break;
                 case CAMERA_REQUEST_CODE:
                     String uploadpath = Uri2PathUtil.getRealPathFromUri(this, mCameraUri);
-                    mAgentWeb.getJsAccessEntrace().quickCallJs("Camera", uploadpath);
+                    mAgentWeb.getJsAccessEntrace().quickCallJs("Camera", fileToBase64(new File(uploadpath)));
                     break;
             }
         }
@@ -334,7 +339,38 @@ public class WebViewActivity extends AppCompatActivity {
         }
         return tempFile;
     }
-
+    /**
+     * 文件转base64字符串
+     *
+     * @param file
+     * @return
+     */
+    public String fileToBase64(File file) {
+        String base64 = null;
+        InputStream in = null;
+        try {
+            in = new FileInputStream(file);
+            byte[] bytes = new byte[in.available()];
+            int length = in.read(bytes);
+            base64 = Base64.encodeToString(bytes, 0, length, Base64.DEFAULT);
+        } catch (FileNotFoundException e) {
+            // TODO Auto-generated catch block
+            ToastUtil.showToast("文件读取异常");
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            ToastUtil.showToast("IO读取异常");
+        } finally {
+            try {
+                if (in != null) {
+                    in.close();
+                }
+            } catch (IOException e) {
+                // TODO Auto-generated catch block
+                ToastUtil.showToast("IO关闭异常");
+            }
+        }
+        return base64;
+    }
     @Override
     protected void onResume() {
         mAgentWeb.getWebLifeCycle().onResume();

+ 0 - 57
app/src/main/res/layout/activity_live.xml

@@ -1,57 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    xmlns:tools="http://schemas.android.com/tools"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    tools:context=".activity.LiveActivity">
-
-    <me.lake.librestreaming.ws.StreamLiveCameraView
-        android:id="@+id/stream_previewView"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent" />
-
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:layout_alignParentBottom="true">
-
-        <RelativeLayout
-            android:id="@+id/rl_suspend"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_weight="1">
-
-            <ImageView
-                android:layout_width="@dimen/dp_50"
-                android:layout_height="@dimen/dp_50"
-                android:layout_centerInParent="true"
-                android:src="@mipmap/icon_zanting" />
-        </RelativeLayout>
-
-        <RelativeLayout
-            android:id="@+id/rl_stop"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_weight="1">
-
-            <ImageView
-                android:layout_width="@dimen/dp_50"
-                android:layout_height="@dimen/dp_50"
-                android:layout_centerInParent="true"
-                android:src="@mipmap/btn_end_call" />
-        </RelativeLayout>
-    </LinearLayout>
-
-
-    <TextView
-        android:id="@+id/tv_stop"
-        android:layout_width="match_parent"
-        android:layout_height="@dimen/dp_40"
-        android:layout_alignParentBottom="true"
-        android:background="#dddddd"
-        android:gravity="center"
-        android:text="结束服务"
-        android:textSize="@dimen/sp_20"
-        android:visibility="gone" />
-</RelativeLayout>

+ 3 - 1
app/src/main/res/layout/activity_main.xml

@@ -17,6 +17,8 @@
         android:id="@+id/start"
         android:layout_width="@dimen/dp_200"
         android:layout_height="@dimen/dp_200"
+        android:layout_below="@id/ed_text"
+        android:layout_centerHorizontal="true"
         android:gravity="center"
-        android:text="开始推流" />
+        android:text="开" />
 </RelativeLayout>

+ 0 - 1
libWSLive/build.gradle

@@ -15,7 +15,6 @@ android {
         checkReleaseBuilds false
     }
 
-
     buildTypes {
         release {
             minifyEnabled false

+ 1 - 1
settings.gradle

@@ -14,4 +14,4 @@ dependencyResolutionManagement {
     }
 }
 rootProject.name = "HomeCareSAS"
-include ':app',':libWSLive'
+include ':app'