关于播放器中的功能(歌词同步),急求VB.NET代码?。?/h2>按照vb.net歌词同步你vb.net歌词同步的说法vb.net歌词同步 , 应该要用到Ajax,对网页中播放器插件进行帧听,然后再对歌词部分进行处理,百度vb.net歌词同步的Mp3就是这样做的 。
下面就简单的说一下吧
材料:歌曲、歌曲对应的歌词(可以是XML,当然也可以是歌词专用格式lrc,随便啦,什么文件都可以)、几条简单的JS语句
处理:
1、JSP生成网页的时候,将音乐播放器插件的ID命名为WMA,当然,你可以随便命名,只是这里便于说明 。
2、读取XML或LRC内容,利用Ajax加载到id为lrc的div中 。
并将XML或LRC的每行的歌词存到数组testmp3中(此数组当然是二维数组 , 数据组分别播放时间与歌词内容)
好了,到此,准备工作就做好了,下面就是重点---歌词同步 。
3、相关语句:
一、定义函数getWMAtime
二、利用Interval=setInterval("getWMAtime()",900),意思就是每隔900毫秒调用getWMAtime这个函数,并将其放入Interval中 。
如果要用到“上一曲”“下一曲”,可以将其做为了一个函数,
将音乐的地址赋给WMA.URL,用WMA.controls.play();播放,用WMA.controls.stop();停止播放,用WMA.controls.pause();暂停播放 。改变了音乐地址后,记得用Ajax载入新的歌词vb.net歌词同步!
另:
getWMAtime函数的内容为读取当前词曲的播放时间
当前的播放时间:WMA.controls.currentPosition;
歌曲总时间:WMA.currentMedia.duration;
读取当前的时候后,与数组中时间项进行对比 , 相同(由于其它原因,可能会出现不相同的情况,因此则用“=”)则用Ajax对id为lrc的div进行更改,具体怎么改那就随便你咯,一般就是改变一下指定行的颜色 。
如果前当播放时间==歌曲总时间,那么就用clearInterval(Interval),停止Interval继续调用 。
好了,一个简单的JS的歌词同步播放器就完工啦
vb同步歌词这几天刚好研究了一下这个vb.net歌词同步,写了个可以同步显示不过不太好看 。
把.lrc当文本文件读 , 其中前面vb.net歌词同步的标签不是时间标签,不用管它,如:
[ti:不想让vb.net歌词同步你哭]
[ar:王强]
[al:]
[by:酷vb.net歌词同步我 ]
[offset:500]‘这个是整体调整歌词用vb.net歌词同步的,毫秒,可以是负值,
主要的时间标签 ,
[02:23.01]我不想让你哭
[02:24.84]我也不想认输
[02:27.12]只想用我的爱再次把你留住
[03:10.04][02:31.48]谁的眼泪随风飘向了远处
[03:14.16][02:35.65]那也是我在为你祝福
一行歌词中可能有多个时间标签,因为有些歌词要唱几遍的 。
用一个结构体数组保存时间和对应的歌词 。
思路:
1)文本方式打开.lrc,判断是不是时间标签 , 不是就不用管它 。
2)是时间标签,循环处理,把一行里的时间和歌词分离,把时间统一转化成秒(如:[02:23.01]我不想让你哭 , 时间转化成143.01),放在机构体的时间成员里 , 歌词放在对应的歌词成员里 。
3)循环直到.lrc文件尾 。这样时间和对应的歌词都存在结构体数组里面了 。
4)播放的时候,根据播放控件的时间?。?遍历数组找到时间,把对应的歌词显示出来就ok了 。
如果要象千千静听那样,显示多行歌词的话,对结构体数组按时间排个序,顺序就对了
^_^,,,楼主可以试试
VB.NET 怎么同步显示lrc歌词??可以稍微改下,预读两句歌词的时间范围,时间大于第一句的起始点,小于第二句的起始点,那么显示第一句 ,
使用VB.NET制作带歌词显示的mp3播放器Public Class Form1
Dim soundname As String()
Dim i As Integer
Dim j, l As Boolean
Dim k As Integer
Dim filename As String '取歌曲vb.net歌词同步的名字
Dim path As String()
Dim s, m As Integer
Dim luj As String
Dim count As Integer '用来声明选择歌曲的数目
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
selectsound()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim g As Graphics
g = Graphics.FromHwnd(Me.Handle)
Dim mfont As New Font("宋体", 20)
Dim mstringformat As New StringFormat
mstringformat.Alignment = StringAlignment.Center
mstringformat.LineAlignment = StringAlignment.Center
g.DrawString("X071616", mfont, Brushes.Black, 75, 328, mstringformat)
If ListBox1.Items.Count = 0 Then selectsound() : Exit Sub
playsound()
End Sub
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
Me.AxWindowsMediaPlayer1.settings.volume = TrackBar1.Value
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Timer1.Enabled = False Then
Timer1.Enabled = True
Else
Timer1.Enabled = False
End If
If i = 0 Then
Me.AxWindowsMediaPlayer1.Ctlcontrols.pause()
i = 1
Button3.Text = "继续"
Exit Sub
End If
If i = 1 Then
Me.AxWindowsMediaPlayer1.Ctlcontrols.play()
Button3.Text = "暂停"
i = 0
Exit Sub
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
j = True
playsound()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.AxWindowsMediaPlayer1.Ctlcontrols.stop()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim string1, ss, sss As String
string1 = ListBox1.SelectedItem.ToString.Substring(ListBox1.SelectedItem.ToString.LastIndexOf("\")1)
filename = string1.Substring(0, string1.LastIndexOf("."))
luj = ListBox1.SelectedItem.ToString.Substring(0, ListBox1.SelectedItem.ToString.LastIndexOf("."))".lrc"
Me.HScrollBar1.Value = https://www.04ip.com/post/Me.AxWindowsMediaPlayer1.Ctlcontrols.currentPosition / (Me.AxWindowsMediaPlayer1.currentMedia.duration0.001) * 1000
ss = Me.AxWindowsMediaPlayer1.Ctlcontrols.currentPositionString
Me.Label1.Text = ss
If Dir(luj)Nothing Then
Dim fr As System.IO.StreamReader = New System.IO.StreamReader(luj, System.Text.Encoding.Default)
sss = fr.ReadLine 'vb.net歌词同步我们读取的第一行歌词
While (sss"")
If (sss.LastIndexOf(ss)-1) Then '时间匹配vb.net歌词同步了歌词中的时间
Me.TextBox1.Text = sss.Substring(sss.LastIndexOf("]")1)
Form2.TextBox1.Text = Me.TextBox1.Text
End If
sss = fr.ReadLine
End While
Else
TextBox1.Text = "Not Find! 请从网上下载歌词!"
Form2.TextBox1.Text = "Not Find! 请从网上下载歌词!"
End If
Label1.Text = "当前进度:"Me.AxWindowsMediaPlayer1.Ctlcontrols.currentPositionString
End Sub
Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
Me.AxWindowsMediaPlayer1.Ctlcontrols.currentPosition = Me.HScrollBar1.Value / 1000 * Me.AxWindowsMediaPlayer1.currentMedia.duration
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Me.AxWindowsMediaPlayer1.Ctlcontrols.fastForward()
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Me.AxWindowsMediaPlayer1.Ctlcontrols.fastReverse()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
i = 0
j = False
l = False
Label2.Text = "歌曲名vb.net歌词同步: "
Label3.Text = "歌曲演唱者vb.net歌词同步: "
Label4.Text = "歌曲描述: "
Label5.Text = "歌曲类型: "
Label6.Text = "歌曲大?。?"
Button8.Enabled = False
End Sub
Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
Me.AxWindowsMediaPlayer1.URL = ListBox1.Items(ListBox1.SelectedIndex)
Me.AxWindowsMediaPlayer1.Ctlcontrols.play()
Label2.Text = "歌曲名: "Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Title")
Label3.Text = "歌曲演唱者: "Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Author")
Label4.Text = "歌曲描述: "Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Description")
Label5.Text = "歌曲类型: "Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileType")
Label6.Text = "歌曲大?。?"Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileSize")
Timer1.Start()
End Sub
Private Sub playsound()
Timer1.Stop()
TrackBar1.Value = https://www.04ip.com/post/Me.AxWindowsMediaPlayer1.settings.volume
If j = False Then
Me.AxWindowsMediaPlayer1.URL = ListBox1.Items(ListBox1.SelectedIndex)
ElseIf j = True Then
k = (ListBox1.SelectedIndex1) Mod soundname.Length
Me.AxWindowsMediaPlayer1.URL = ListBox1.Items(k)
j = False
End If
ListBox1.SelectedIndex = k
Me.AxWindowsMediaPlayer1.Ctlcontrols.play()
Label2.Text = "歌曲名: "Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Title")
Label3.Text = "歌曲演唱者: "Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Author")
Label4.Text = "歌曲描述: "Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Description")
Label5.Text = "歌曲类型: "Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileType")
Label6.Text = "歌曲大?。?"Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileSize")
Timer1.Start()
End Sub
Private Sub selectsound()
Dim open As New OpenFileDialog
Dim i As Integer
With open
.Filter = "所有mp3文件(*.mp3)|*.mp3|所有wma文件(*.wma)|*.wma"
.Multiselect = True
.Title = "请选择歌曲"
End With
If (open.ShowDialog = Windows.Forms.DialogResult.OK) Then
soundname = open.FileNames
For i = 0 To soundname.GetUpperBound(0)
ListBox1.Items.Add(soundname(i))
Next
ListBox1.SelectedIndex = 0
End If
End Sub
Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsMediaEnded Then
j = True
Timer2.Start()
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
playsound()
Timer2.Stop()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Timer1.Stop()
If ListBox1.SelectedIndex = 0 Then
Me.AxWindowsMediaPlayer1.URL = ListBox1.Items(soundname.Length - 1)
ListBox1.SelectedIndex = (soundname.Length - 1)
Else
Me.AxWindowsMediaPlayer1.URL = ListBox1.Items((ListBox1.SelectedIndex Mod soundname.Length) - 1)
ListBox1.SelectedIndex = (ListBox1.SelectedIndex Mod soundname.Length) - 1
End If
Me.AxWindowsMediaPlayer1.Ctlcontrols.play()
Label2.Text = "歌曲名: "Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Title")
Label3.Text = "歌曲演唱者: "Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Author")
Label4.Text = "歌曲描述: "Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Description")
Label5.Text = "歌曲类型: "Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileType")
Label6.Text = "歌曲大?。?"Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileSize")
Timer1.Start()
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
Form2.Show()
End Sub
End Class
【vb.net歌词同步的简单介绍】关于vb.net歌词同步和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。
推荐阅读
- linuxcorn命令,linux的nice命令
- jquery得到点击项的id,jquery 点击
- 接龙小程序怎么修改顺序图片,接龙小程序怎么修改顺序图片和名字
- 包含java中3次方代码的词条
- win远程unix安装oracle,linux远程安装oracle
- 酸奶应该如何创新营销,酸奶应该如何创新营销策划
- 小益智游戏,智力游戏
- mysql怎么关联表视图 mysql数据库关联查询
- 婆婆要给孩子看电视怎么办,婆婆带孩子让孩子自己玩,给看电视