Explorar el Código

screen stream

x1ongzhu hace 6 años
padre
commit
91fe41142d

+ 30 - 10
android/app/src/main/java/com/izouma/mobilecybergames/ScreenStreamPlugin.java

@@ -5,6 +5,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.Intent;
 import android.media.projection.MediaProjectionManager;
 import android.media.projection.MediaProjectionManager;
 import android.text.TextUtils;
 import android.text.TextUtils;
+import android.util.Log;
 import android.view.View;
 import android.view.View;
 import android.widget.Toast;
 import android.widget.Toast;
 
 
@@ -23,7 +24,8 @@ import io.flutter.plugin.common.MethodChannel;
 import io.flutter.plugin.common.PluginRegistry;
 import io.flutter.plugin.common.PluginRegistry;
 
 
 public class ScreenStreamPlugin implements MethodChannel.MethodCallHandler, PluginRegistry.ActivityResultListener {
 public class ScreenStreamPlugin implements MethodChannel.MethodCallHandler, PluginRegistry.ActivityResultListener {
-    public static final int CAPTURE_PERMISSION_REQUEST_CODE = 0x1123;
+    private static final String TAG                             = "ScreenStreamPlugin";
+    public static final  int    CAPTURE_PERMISSION_REQUEST_CODE = 0x1123;
 
 
     private final PluginRegistry.Registrar registrar;
     private final PluginRegistry.Registrar registrar;
 
 
@@ -54,10 +56,11 @@ public class ScreenStreamPlugin implements MethodChannel.MethodCallHandler, Plug
 
 
     @Override
     @Override
     public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
     public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
+        this.result = result;
         if ("start".equals(methodCall.method)) {
         if ("start".equals(methodCall.method)) {
             url = methodCall.argument("url");
             url = methodCall.argument("url");
             if (!TextUtils.isEmpty(url)) {
             if (!TextUtils.isEmpty(url)) {
-                if (Pattern.matches("^(?i)rtmp:\\\\/\\\\/", url)) {
+                if (Pattern.matches("^(?i)rtmp://.*", url)) {
                     if (!start()) {
                     if (!start()) {
                         result.error("start fail", "need android 5.0", null);
                         result.error("start fail", "need android 5.0", null);
                     }
                     }
@@ -86,6 +89,9 @@ public class ScreenStreamPlugin implements MethodChannel.MethodCallHandler, Plug
     }
     }
 
 
     public boolean stop() {
     public boolean stop() {
+        if (mAlivcLivePusher != null && mAlivcLivePusher.isPushing()) {
+            mAlivcLivePusher.stopPush();
+        }
         return true;
         return true;
     }
     }
 
 
@@ -112,55 +118,69 @@ public class ScreenStreamPlugin implements MethodChannel.MethodCallHandler, Plug
 
 
             @Override
             @Override
             public void onPushStarted(AlivcLivePusher pusher) {
             public void onPushStarted(AlivcLivePusher pusher) {
+                Log.d(TAG, "onPushStarted");
                 started = true;
                 started = true;
+                registrar.activity().runOnUiThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        Toast.makeText(registrar.context(), "开始录屏", Toast.LENGTH_SHORT).show();
+                    }
+                });
             }
             }
 
 
             @Override
             @Override
             public void onFirstAVFramePushed(AlivcLivePusher alivcLivePusher) {
             public void onFirstAVFramePushed(AlivcLivePusher alivcLivePusher) {
-
+                Log.d(TAG, "onFirstAVFramePushed");
             }
             }
 
 
             @Override
             @Override
             public void onPushPauesed(AlivcLivePusher pusher) {
             public void onPushPauesed(AlivcLivePusher pusher) {
+                Log.d(TAG, "onPushPauesed");
 
 
             }
             }
 
 
             @Override
             @Override
             public void onPushResumed(AlivcLivePusher pusher) {
             public void onPushResumed(AlivcLivePusher pusher) {
-
+                Log.d(TAG, "onPushResumed");
             }
             }
 
 
             @Override
             @Override
             public void onPushStoped(AlivcLivePusher pusher) {
             public void onPushStoped(AlivcLivePusher pusher) {
+                Log.d(TAG, "onPushStopped");
                 started = false;
                 started = false;
                 mAlivcLivePusher = null;
                 mAlivcLivePusher = null;
+                registrar.activity().runOnUiThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        Toast.makeText(registrar.context(), "录屏结束", Toast.LENGTH_SHORT).show();
+                    }
+                });
             }
             }
 
 
             @Override
             @Override
             public void onPushRestarted(AlivcLivePusher pusher) {
             public void onPushRestarted(AlivcLivePusher pusher) {
-
+                Log.d(TAG, "onPushRestarted");
             }
             }
 
 
             @Override
             @Override
             public void onFirstFramePreviewed(AlivcLivePusher pusher) {
             public void onFirstFramePreviewed(AlivcLivePusher pusher) {
-
+                Log.d(TAG, "onFirstFramePreviewed");
             }
             }
 
 
             @Override
             @Override
             public void onDropFrame(AlivcLivePusher pusher, int countBef, int countAft) {
             public void onDropFrame(AlivcLivePusher pusher, int countBef, int countAft) {
-
+                Log.d(TAG, "onDropFrame");
             }
             }
 
 
             @Override
             @Override
             public void onAdjustBitRate(AlivcLivePusher pusher, int curBr, int targetBr) {
             public void onAdjustBitRate(AlivcLivePusher pusher, int curBr, int targetBr) {
-
+                Log.d(TAG, "onAdjustBitRate");
             }
             }
 
 
             @Override
             @Override
             public void onAdjustFps(AlivcLivePusher pusher, int curFps, int targetFps) {
             public void onAdjustFps(AlivcLivePusher pusher, int curFps, int targetFps) {
-
+                Log.d(TAG, "onAdjustFps");
             }
             }
-
         });
         });
 
 
         mAlivcLivePusher.startPreview(null);
         mAlivcLivePusher.startPreview(null);

+ 42 - 39
lib/pages/HomePage.dart

@@ -1,4 +1,5 @@
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
+import 'package:flutter_redux/flutter_redux.dart';
 import '../widgets/HomeDrawer.dart';
 import '../widgets/HomeDrawer.dart';
 import './Setting.dart';
 import './Setting.dart';
 import './CreateRoom.dart';
 import './CreateRoom.dart';
@@ -11,6 +12,9 @@ import '../styles/totast.dart';
 import '../net/HttpManager.dart';
 import '../net/HttpManager.dart';
 import '../net/Result.dart';
 import '../net/Result.dart';
 import 'TipList.dart';
 import 'TipList.dart';
+import '../plugins/ScreenStramPlugin.dart';
+import '../model/UserInfo.dart';
+import '../redux/AppState.dart';
 
 
 class HomePage extends StatefulWidget {
 class HomePage extends StatefulWidget {
   @override
   @override
@@ -54,18 +58,17 @@ class _HomePageState extends State<HomePage> {
         width: double.infinity,
         width: double.infinity,
         height: double.infinity,
         height: double.infinity,
         decoration: BoxDecoration(
         decoration: BoxDecoration(
-            gradient: LinearGradient(colors: [
-          Color.fromARGB(255, 177, 59, 56),
-          Color.fromARGB(255, 147, 64, 61)
-        ], begin: Alignment.topCenter, end: Alignment.bottomCenter)),
+            gradient: LinearGradient(
+                colors: [Color.fromARGB(255, 177, 59, 56), Color.fromARGB(255, 147, 64, 61)], begin: Alignment.topCenter, end: Alignment.bottomCenter)),
         child: SafeArea(
         child: SafeArea(
-          child: centerWidget(),
+          child: centerWidget(context),
         ),
         ),
       ),
       ),
     );
     );
   }
   }
 
 
-  Widget centerWidget() {
+  Widget centerWidget(BuildContext context) {
+    UserInfo userInfo = StoreProvider.of<AppState>(context).state.userInfo;
     return Column(
     return Column(
       children: <Widget>[
       children: <Widget>[
         Expanded(
         Expanded(
@@ -98,15 +101,12 @@ class _HomePageState extends State<HomePage> {
                                       Image.asset("images/home_icon_yuan.png"),
                                       Image.asset("images/home_icon_yuan.png"),
                                       Center(
                                       Center(
                                         child: Row(
                                         child: Row(
-                                          mainAxisAlignment:
-                                              MainAxisAlignment.center,
-                                          crossAxisAlignment:
-                                              CrossAxisAlignment.baseline,
+                                          mainAxisAlignment: MainAxisAlignment.center,
+                                          crossAxisAlignment: CrossAxisAlignment.baseline,
                                           textBaseline: TextBaseline.alphabetic,
                                           textBaseline: TextBaseline.alphabetic,
                                           children: <Widget>[
                                           children: <Widget>[
                                             Text(
                                             Text(
-                                              (seasonList[index].bonus / 1000)
-                                                  .toStringAsFixed(1),
+                                              (seasonList[index].bonus / 1000).toStringAsFixed(1),
                                               style: TextStyle(
                                               style: TextStyle(
                                                 color: Colors.white,
                                                 color: Colors.white,
                                                 fontSize: 68,
                                                 fontSize: 68,
@@ -178,10 +178,7 @@ class _HomePageState extends State<HomePage> {
                   color: Colors.transparent,
                   color: Colors.transparent,
                   child: InkWell(
                   child: InkWell(
                     onTap: () {
                     onTap: () {
-                      Navigator.push(
-                          context,
-                          new CupertinoPageRoute(
-                              builder: (context) => new Setting()));
+                      Navigator.push(context, new CupertinoPageRoute(builder: (context) => new Setting()));
                     },
                     },
                     child: Padding(
                     child: Padding(
                       padding: EdgeInsets.all(12),
                       padding: EdgeInsets.all(12),
@@ -203,13 +200,33 @@ class _HomePageState extends State<HomePage> {
                       style: TextStyle(color: Colors.white, fontSize: 14),
                       style: TextStyle(color: Colors.white, fontSize: 14),
                     ),
                     ),
                     Text(
                     Text(
-                      seasonList.length > 0
-                          ? seasonList[nowIndex].gameInfo.gameName
-                          : '',
+                      seasonList.length > 0 ? seasonList[nowIndex].gameInfo.gameName : '',
                       style: TextStyle(color: Colors.white, fontSize: 14),
                       style: TextStyle(color: Colors.white, fontSize: 14),
                     )
                     )
                   ],
                   ],
                 ),
                 ),
+              ),
+              Positioned(
+                bottom: 60,
+                left: 0,
+                child: FlatButton(
+                  child: Text("stream"),
+                  onPressed: () async {
+                    bool success = await ScreenStreamPlugin.start('rtmp://49.4.66.233:1935/myapp/' + userInfo.id.toString() + '?playerInfoId=' + '1234');
+                    print('stream screen:' + success.toString());
+                  },
+                ),
+              ),
+              Positioned(
+                bottom: 60,
+                right: 0,
+                child: FlatButton(
+                  child: Text("stop stream"),
+                  onPressed: () async {
+                    bool success = await ScreenStreamPlugin.stop();
+                    print('stop stream screen:' + success.toString());
+                  },
+                ),
               )
               )
             ],
             ],
           ),
           ),
@@ -227,13 +244,9 @@ class _HomePageState extends State<HomePage> {
                   Navigator.of(context).push(PageRouteBuilder(
                   Navigator.of(context).push(PageRouteBuilder(
                       opaque: false,
                       opaque: false,
                       transitionDuration: Duration(milliseconds: 300),
                       transitionDuration: Duration(milliseconds: 300),
-                      transitionsBuilder: (BuildContext context,
-                          Animation<double> animation,
-                          Animation<double> secondaryAnimation,
-                          Widget child) {
+                      transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
                         return FadeTransition(
                         return FadeTransition(
-                          opacity: CurvedAnimation(
-                              parent: animation, curve: Curves.linear),
+                          opacity: CurvedAnimation(parent: animation, curve: Curves.linear),
                           child: child,
                           child: child,
                         );
                         );
                       },
                       },
@@ -251,21 +264,14 @@ class _HomePageState extends State<HomePage> {
                 "images/home_icon_sousuo.png",
                 "images/home_icon_sousuo.png",
                 "搜索",
                 "搜索",
                 onTapHomeMenu: () {
                 onTapHomeMenu: () {
-                  Navigator.push(
-                      context,
-                      new CupertinoPageRoute(
-                          builder: (context) => new RoomList()));
+                  Navigator.push(context, new CupertinoPageRoute(builder: (context) => new RoomList()));
                 },
                 },
               ),
               ),
               HomeMenu(
               HomeMenu(
                 "images/home_icon_youjian.png",
                 "images/home_icon_youjian.png",
                 "邮件",
                 "邮件",
                 onTapHomeMenu: () {
                 onTapHomeMenu: () {
-                   Navigator.push(
-                      context,
-                      new CupertinoPageRoute(
-                          builder: (context) => new TipList()));
-                  
+                  Navigator.push(context, new CupertinoPageRoute(builder: (context) => new TipList()));
                 },
                 },
               ),
               ),
             ],
             ],
@@ -286,11 +292,8 @@ class HomeMenu extends StatelessWidget {
   @override
   @override
   Widget build(BuildContext context) {
   Widget build(BuildContext context) {
     return Container(
     return Container(
-      decoration: BoxDecoration(
-          gradient: LinearGradient(
-              begin: Alignment.topCenter,
-              end: Alignment.bottomCenter,
-              colors: [Color(0xFF626C85), Color(0xFF3D3E6C)])),
+      decoration:
+          BoxDecoration(gradient: LinearGradient(begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [Color(0xFF626C85), Color(0xFF3D3E6C)])),
       child: AspectRatio(
       child: AspectRatio(
         aspectRatio: 1,
         aspectRatio: 1,
         child: Container(
         child: Container(

+ 3 - 3
lib/plugins/ScreenStramPlugin.dart

@@ -1,18 +1,18 @@
 import 'package:flutter/services.dart';
 import 'package:flutter/services.dart';
 
 
 class ScreenStreamPlugin {
 class ScreenStreamPlugin {
-  static const _channel = MethodChannel("screen_stram");
+  static const _channel = MethodChannel("screen_stream");
 
 
   static Future<bool> start(String url) async {
   static Future<bool> start(String url) async {
     try {
     try {
-      await _channel.invokeMethod("start", [url]);
+      await _channel.invokeMethod("start", {"url": url});
       return true;
       return true;
     } catch (e) {
     } catch (e) {
       return false;
       return false;
     }
     }
   }
   }
 
 
-  static Future<bool> stop(String url) async {
+  static Future<bool> stop() async {
     try {
     try {
       await _channel.invokeMethod("stop", []);
       await _channel.invokeMethod("stop", []);
       return true;
       return true;