Browse Source

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

ZhangXueYang
耀 4 years ago
parent
commit
0c8b9caf6a

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

54
         /// <param name="size">大小</param>
54
         /// <param name="size">大小</param>
55
         /// <param name="ErrMessage">错误信息返回</param>
55
         /// <param name="ErrMessage">错误信息返回</param>
56
         /// <returns></returns>
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
             while (myProcess != null)
59
             while (myProcess != null)
60
             {
60
             {
126
 
126
 
127
             if (OutputVideoLog)
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
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
132
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
133
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
133
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
134
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
134
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
149
                 {
149
                 {
150
                     ErrMessage = ex.Message + " 请关闭杀毒软件或信任此软件后重试!";
150
                     ErrMessage = ex.Message + " 请关闭杀毒软件或信任此软件后重试!";
151
                 }
151
                 }
152
-                LogHelper.WriteErrLog("【录音】(StartRecordingAudio)" + ErrMessage, ex);
152
+                LogHelper.WriteErrLog("【直播】(StartLiveRecordingVideo)" + ErrMessage, ex);
153
                 myProcess.Dispose();
153
                 myProcess.Dispose();
154
                 myProcess = null;
154
                 myProcess = null;
155
                 return false;
155
                 return false;
156
             }
156
             }
157
             return true;
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
         #endregion
186
         #endregion
160
         /// <summary>
187
         /// <summary>
161
         /// 录制屏幕
188
         /// 录制屏幕

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

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

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

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

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

6
         xmlns:local="clr-namespace:XHZB.Desktop" xmlns:wfi="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
6
         xmlns:local="clr-namespace:XHZB.Desktop" xmlns:wfi="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
7
 xmlns:aforge ="clr-namespace:AForge.Controls;assembly=AForge.Controls"
7
 xmlns:aforge ="clr-namespace:AForge.Controls;assembly=AForge.Controls"
8
         mc:Ignorable="d"
8
         mc:Ignorable="d"
9
-        Title="CameraWindow" Height="180" Width="220" ResizeMode="NoResize"
9
+        Title="摄像头" Height="200" Width="250" ResizeMode="NoResize"
10
     >
10
     >
11
     <Grid>
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
             <aforge:VideoSourcePlayer x:Name="player" Height="124" Width="172"  />
13
             <aforge:VideoSourcePlayer x:Name="player" Height="124" Width="172"  />
14
         </wfi:WindowsFormsHost>
14
         </wfi:WindowsFormsHost>
15
     </Grid>
15
     </Grid>

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

156
                     Margin="35,-20,0,0"
156
                     Margin="35,-20,0,0"
157
                     FontSize="13"
157
                     FontSize="13"
158
                     Foreground="White"
158
                     Foreground="White"
159
-                    Text="星火智慧校园" />
159
+                    Text="星火直播" />
160
                 <Button
160
                 <Button
161
                     x:Name="btnDown"
161
                     x:Name="btnDown"
162
                     Width="30.8"
162
                     Width="30.8"
200
                     <RowDefinition Height="*" />
200
                     <RowDefinition Height="*" />
201
                 </Grid.RowDefinitions>
201
                 </Grid.RowDefinitions>
202
 
202
 
203
-                <Image
203
+                <!--<Image
204
                     Grid.Row="0"
204
                     Grid.Row="0"
205
                     Width="228"
205
                     Width="228"
206
                     Height="34.5"
206
                     Height="34.5"
207
                     Margin="0,66.2,0,0"
207
                     Margin="0,66.2,0,0"
208
                     HorizontalAlignment="Center"
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
                 <Border
211
                 <Border
211
                     Grid.Row="2"
212
                     Grid.Row="2"
212
                     Width="272"
213
                     Width="272"

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

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

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

50
         {
50
         {
51
             InitializeComponent();
51
             InitializeComponent();
52
 
52
 
53
+            if (!APP.CheckScreenCapturerRecorder())
54
+            {
55
+                MessageWindow.Show("首次运行需安装环境,请在确定后依次点击“English-OK-Next>-Next>Install”完成安装!");
56
+                APP.InstallScreenCapturerRecorder();
57
+            }
58
+
53
             txbName.Text = APP.LoginUser.username;
59
             txbName.Text = APP.LoginUser.username;
54
 
60
 
55
             heiban_btn.Click += Heiban_btn_Click;
61
             heiban_btn.Click += Heiban_btn_Click;
143
                 if (pageData.tongping)
149
                 if (pageData.tongping)
144
                 {
150
                 {
145
                     //tongpingBegin();
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
                 else
172
                 else
159
                 {
173
                 {
160
                     //tongpingEnd();
174
                     //tongpingEnd();
175
+                    EndLive();
161
                     pageData.menuList[1].Pic = "../Images/ToolBar/直播@2x.png";
176
                     pageData.menuList[1].Pic = "../Images/ToolBar/直播@2x.png";
162
                     pageData.menuList[1].Name = "直播";
177
                     pageData.menuList[1].Name = "直播";
163
                     APP.W_CameraWindow.Hide();
178
                     APP.W_CameraWindow.Hide();
792
             }
807
             }
793
         }
808
         }
794
         #endregion
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
     /// <summary>
852
     /// <summary>
797
     /// 工具栏模型
853
     /// 工具栏模型

Loading…
Cancel
Save