Browse Source

zhao:添加直播,修改页面样式

ZhangXueYang
耀 3 years ago
parent
commit
0c8b9caf6a

+ 31
- 4
Common/system/FFMpeg.cs View File

@@ -54,7 +54,7 @@ namespace Common.system
54 54
         /// <param name="size">大小</param>
55 55
         /// <param name="ErrMessage">错误信息返回</param>
56 56
         /// <returns></returns>
57
-        public bool StartRecordingVideo(string RTMPPath, string NodeKey, Size size, out string ErrMessage)
57
+        public bool StartLiveRecordingVideo(string RTMPPath, string NodeKey, Size size, out string ErrMessage)
58 58
         {
59 59
             while (myProcess != null)
60 60
             {
@@ -126,9 +126,9 @@ namespace Common.system
126 126
 
127 127
             if (OutputVideoLog)
128 128
             {
129
-                LogHelper.WriteInfoLog("【录屏】:" + myProcess.StartInfo.Arguments);
129
+                LogHelper.WriteInfoLog("【直播】:" + myProcess.StartInfo.Arguments);
130 130
             }
131
-            FileToolsCommon.AppendText(LogPath, "【录屏】:" + myProcess.StartInfo.Arguments + "\r\n");
131
+            FileToolsCommon.AppendText(LogPath, "【直播】:" + myProcess.StartInfo.Arguments + "\r\n");
132 132
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
133 133
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
134 134
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
@@ -149,13 +149,40 @@ namespace Common.system
149 149
                 {
150 150
                     ErrMessage = ex.Message + " 请关闭杀毒软件或信任此软件后重试!";
151 151
                 }
152
-                LogHelper.WriteErrLog("【录音】(StartRecordingAudio)" + ErrMessage, ex);
152
+                LogHelper.WriteErrLog("【直播】(StartLiveRecordingVideo)" + ErrMessage, ex);
153 153
                 myProcess.Dispose();
154 154
                 myProcess = null;
155 155
                 return false;
156 156
             }
157 157
             return true;
158 158
         }
159
+        /// <summary>
160
+        /// 结束直播推流
161
+        /// </summary>
162
+        public bool StopLive()
163
+        {
164
+            if (myProcess != null)
165
+            {
166
+                myProcess.StandardInput.WriteLine("q");//在这个进程的控制台中模拟输入q,用于暂停录制
167
+                myProcess.Close();//关闭进程
168
+                myProcess.Dispose();//释放资源
169
+            }
170
+            #region 进程是否已经释放
171
+            bool IsRunning = true;
172
+            while (IsRunning)
173
+            {
174
+                IsRunning = false;
175
+                Process[] ProcessArray = Process.GetProcessesByName("ffmpeg");
176
+                foreach (Process KillProcess in ProcessArray)
177
+                {
178
+                    IsRunning = true;
179
+                    Thread.Sleep(100);
180
+                }
181
+            }
182
+            #endregion
183
+            myProcess = null;
184
+            return true;
185
+        }
159 186
         #endregion
160 187
         /// <summary>
161 188
         /// 录制屏幕

+ 2
- 1
XHZB.Desktop/App.cs View File

@@ -249,6 +249,7 @@ namespace XHZB.Desktop
249 249
             myloading = new LoadDialog();
250 250
             StopSameProcess();
251 251
             Killffmpeg();
252
+            UnZipFFmpeg();
252 253
             try
253 254
             {
254 255
                 if (args != null&&args.Length>1)
@@ -417,7 +418,7 @@ namespace XHZB.Desktop
417 418
         }
418 419
 
419 420
         #region 检测解压ffmpeg
420
-        public void UnZipFFmpeg()
421
+        public static void UnZipFFmpeg()
421 422
         {
422 423
             new Thread(o =>
423 424
             {

+ 2
- 2
XHZB.Desktop/AttendanceWindow.xaml View File

@@ -118,7 +118,7 @@
118 118
                 VerticalAlignment="Center"
119 119
                 FontSize="30"
120 120
                 Foreground="White"
121
-                Text="        考勤统计结果        "/>
121
+                Text="        在线学生        "/>
122 122
             </Grid>
123 123
 
124 124
             <StackPanel
@@ -127,7 +127,7 @@
127 127
                 HorizontalAlignment="Right"
128 128
                 VerticalAlignment="Center"
129 129
                 Orientation="Horizontal">
130
-                <TextBlock FontSize="26" Text="考勤人数:" />
130
+                <TextBlock FontSize="26" Text="在线人数:" />
131 131
                 <TextBlock
132 132
                     x:Name="txbOnlineUsers"
133 133
                     Margin="0,0,0,0"

+ 2
- 2
XHZB.Desktop/CameraWindow.xaml View File

@@ -6,10 +6,10 @@
6 6
         xmlns:local="clr-namespace:XHZB.Desktop" xmlns:wfi="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
7 7
 xmlns:aforge ="clr-namespace:AForge.Controls;assembly=AForge.Controls"
8 8
         mc:Ignorable="d"
9
-        Title="CameraWindow" Height="180" Width="220" ResizeMode="NoResize"
9
+        Title="摄像头" Height="200" Width="250" ResizeMode="NoResize"
10 10
     >
11 11
     <Grid>
12
-        <wfi:WindowsFormsHost Grid.Row="0" Grid.Column="1" x:Name="wfhCamera" Height="124" Width="172" HorizontalAlignment="Right" Margin="0,10,30.10,0" VerticalAlignment="Top">
12
+        <wfi:WindowsFormsHost Grid.Row="0" Grid.Column="1" x:Name="wfhCamera" Margin="0">
13 13
             <aforge:VideoSourcePlayer x:Name="player" Height="124" Width="172"  />
14 14
         </wfi:WindowsFormsHost>
15 15
     </Grid>

+ 4
- 3
XHZB.Desktop/LoginWindow.xaml View File

@@ -156,7 +156,7 @@
156 156
                     Margin="35,-20,0,0"
157 157
                     FontSize="13"
158 158
                     Foreground="White"
159
-                    Text="星火智慧校园" />
159
+                    Text="星火直播" />
160 160
                 <Button
161 161
                     x:Name="btnDown"
162 162
                     Width="30.8"
@@ -200,13 +200,14 @@
200 200
                     <RowDefinition Height="*" />
201 201
                 </Grid.RowDefinitions>
202 202
 
203
-                <Image
203
+                <!--<Image
204 204
                     Grid.Row="0"
205 205
                     Width="228"
206 206
                     Height="34.5"
207 207
                     Margin="0,66.2,0,0"
208 208
                     HorizontalAlignment="Center"
209
-                    Source=".\Images\Login\智慧校园@2x.png" />
209
+                    Source=".\Images\Login\智慧校园@2x.png" />-->
210
+                <Label Content="星 火 直 播" Grid.Row="0" Width="200"  Margin="0,66.2,0,0" Foreground="White" FontSize="35" FontWeight="Bold" HorizontalContentAlignment="Center" />
210 211
                 <Border
211 212
                     Grid.Row="2"
212 213
                     Width="272"

+ 1
- 1
XHZB.Desktop/RollCallWindow.xaml View File

@@ -135,7 +135,7 @@
135 135
                     VerticalAlignment="Center"
136 136
                     FontSize="30"
137 137
                     Foreground="White"
138
-                    Text="        课堂点名抢答        " />
138
+                    Text="        直播点名抢答        " />
139 139
             </Grid>
140 140
             <UniformGrid
141 141
                 Grid.Row="1"

+ 65
- 9
XHZB.Desktop/ToolbarWindow.xaml.cs View File

@@ -50,6 +50,12 @@ namespace XHZB.Desktop
50 50
         {
51 51
             InitializeComponent();
52 52
 
53
+            if (!APP.CheckScreenCapturerRecorder())
54
+            {
55
+                MessageWindow.Show("首次运行需安装环境,请在确定后依次点击“English-OK-Next>-Next>Install”完成安装!");
56
+                APP.InstallScreenCapturerRecorder();
57
+            }
58
+
53 59
             txbName.Text = APP.LoginUser.username;
54 60
 
55 61
             heiban_btn.Click += Heiban_btn_Click;
@@ -143,21 +149,30 @@ namespace XHZB.Desktop
143 149
                 if (pageData.tongping)
144 150
                 {
145 151
                     //tongpingBegin();
146
-                    pageData.menuList[1].Pic = "../Images/ToolBar/img_shared_1.gif";
147
-                    pageData.menuList[1].Name = "正在直播";
148
-
149
-                    if(APP.W_CameraWindow==null)
152
+                    if (StartLive(out string ErrMessage))
150 153
                     {
151
-                        APP.W_CameraWindow = new CameraWindow();
152
-                        APP.W_CameraWindow.Topmost = true;
153
-                        APP.W_CameraWindow.Left = pwidth - 300;
154
-                        APP.W_CameraWindow.Top = 0;
154
+                        pageData.menuList[1].Pic = "../Images/ToolBar/img_shared_1.gif";
155
+                        pageData.menuList[1].Name = "正在直播";
156
+
157
+                        if (APP.W_CameraWindow == null)
158
+                        {
159
+                            APP.W_CameraWindow = new CameraWindow();
160
+                            APP.W_CameraWindow.Topmost = true;
161
+                            APP.W_CameraWindow.Left = pwidth - 300;
162
+                            APP.W_CameraWindow.Top = 0;
163
+                        }
164
+                        APP.W_CameraWindow.Show();
165
+                    }
166
+                    else
167
+                    {
168
+                        pageData.tongping = !pageData.tongping;
169
+                        MessageWindow.Show(ErrMessage);
155 170
                     }
156
-                    APP.W_CameraWindow.Show();
157 171
                 }
158 172
                 else
159 173
                 {
160 174
                     //tongpingEnd();
175
+                    EndLive();
161 176
                     pageData.menuList[1].Pic = "../Images/ToolBar/直播@2x.png";
162 177
                     pageData.menuList[1].Name = "直播";
163 178
                     APP.W_CameraWindow.Hide();
@@ -792,6 +807,47 @@ namespace XHZB.Desktop
792 807
             }
793 808
         }
794 809
         #endregion
810
+
811
+        #region 直播
812
+        /// <summary>
813
+        /// 直播间节点和房号
814
+        /// </summary>
815
+        string NodeKey = "live/test";
816
+        /// <summary>
817
+        /// 开始直播
818
+        /// </summary>
819
+        public bool StartLive(out string ErrMessage)
820
+        {
821
+            try
822
+            {
823
+                //NodeKey=Node+Key;
824
+                System.Drawing.Size DesktopSize = PrimaryScreen.DESKTOP;
825
+                //开始直播
826
+                if(APP.FFmpeg.StartLiveRecordingVideo(APP.RTMPServerPath, NodeKey, DesktopSize,out ErrMessage))
827
+                {
828
+                    return true;
829
+                }
830
+                else
831
+                {
832
+                    return false;
833
+                }
834
+                 
835
+            }
836
+            catch (Exception ex)
837
+            {
838
+                ErrMessage = "无法开始直播:" + ex.Message;
839
+                LogHelper.WriteErrLog(ErrMessage, ex);
840
+                return false;
841
+            }
842
+        }
843
+        /// <summary>
844
+        /// 结束直播
845
+        /// </summary>
846
+        public void EndLive()
847
+        {
848
+            APP.FFmpeg.StopLive();
849
+        }
850
+        #endregion
795 851
     }
796 852
     /// <summary>
797 853
     /// 工具栏模型

Loading…
Cancel
Save