-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathServer.cs
55 lines (44 loc) · 1.37 KB
/
Server.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace bad_apple_server
{
class Server
{
const string ImagePath = @"images";
const string VideoFile = @"tohou.mp4"; // Bad apple!! original video (03:39 length)
const int FPS = 30;
const string PortName = "COM3";
static void Main(string[] args)
{
var files = Directory.EnumerateFiles(ImagePath).ToList();
var images = files.Select(File.ReadAllBytes).ToArray();
WMPLib.WindowsMediaPlayer player = new WMPLib.WindowsMediaPlayer();
player.settings.autoStart = false;
player.settings.playCount = 1000;
player.URL = VideoFile;
Thread.Sleep(1000); // let wmp to finish all the loading shit
var com = new System.IO.Ports.SerialPort(PortName, 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
com.Open();
int currentImage = 0;
bool isPlaying = false;
while (currentImage < images.Length)
{
com.ReadByte();
if (!isPlaying)
{
player.controls.play();
isPlaying = true;
}
var currentPosition = player.controls.currentPosition;
currentImage = (int)(FPS * currentPosition);
com.Write(images[Math.Min(currentImage, images.Length - 1)], 0, 504);
}
com.Close();
}
}
}