开发类似千千静听或者KMplayer等音频视频播放器播放字幕或者歌词的技术

从两方面着手,一是时间轴,二是帧(对于视频)。

方法一的实现比较简单,只需要内置一个定时器,在媒体播放时开始计时,然后读指定的脚本即可。

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace MediaPlayer
{
public partial class Form6 : Form
{
private AxWMPLib.AxWindowsMediaPlayer axWindowsMediaPlayer2 = new AxWMPLib.AxWindowsMediaPlayer();
PictureBox pictureBox2 = new PictureBox();
private int t = 0;
private int count = 0;
private string filename;
private string[] info = new string[100];
public Form6(ref AxWMPLib.AxWindowsMediaPlayer axWindowsMediaPlayer1, ref PictureBox pictureBox1)
{
InitializeComponent();
this.Text = "视频分析";
timer1.Enabled = false;
axWindowsMediaPlayer2 = axWindowsMediaPlayer1;
pictureBox2 = pictureBox1;
}
private void timer1_Tick(object sender, EventArgs e)
{
t++;
label2.Text = t.ToString();
if (!info[count].Equals("end#"))
{
if (t == Int32.Parse(info[count].Substring(0, info[count].IndexOf(']'))))
{
richTextBox1.Text = info[count].Substring(info[count].IndexOf(']') + 1);
count++;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
filename = openFileDialog1.FileName;
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader(filename))
{
String line;
int i = 0;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
info[i] = line;
i++;
}
sr.Close();
}
}
catch (Exception a)
{
// Let the user know what went wrong.
MessageBox.Show("读取错误");
MessageBox.Show(a.Message);
}
}
private void openFileDialog2_FileOk(object sender, CancelEventArgs e)
{
axWindowsMediaPlayer2.URL = openFileDialog2.FileName;
pictureBox2.Visible = false;
timer1.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
openFileDialog2.ShowDialog();
}
}
}

方法二需要利用DirectX开发,或者flash播放的技术拆解成帧然后播放