netsmu 发表于 2010-11-22 21:02:32

歌词LRC文件如何指定位置开始播放呢?

以下是afan高手的歌词播放代码,我想做个滚动条,拉动到指定时间,就能在哪里开始播放。或者双击list里面的某句歌词,就从那句歌词开始播放,不知道要怎么改呢? 求高手帮忙,万分感谢。
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <Misc.au3>
#Region ### START Koda GUI section ### Form=
Global $str
$Form1 = GUICreate("Form1", 523, 463)
$Button1 = GUICtrlCreateButton("Button1", 252, 416, 75, 25)
$ListView1 = GUICtrlCreateListView("时间|歌词", 8, 8, 400, 300)
GUISetState(@SW_SHOW)
$str = _
                '' & @CRLF & _
                '' & @CRLF & _
                '' & @CRLF & _
                '' & @CRLF & _
                '萧闳仁 - 连贝多芬都想告诉你' & @CRLF & _
                'www.51lrc.com ▓ 李泽昊' & @CRLF & _
                '歌词吾爱 带你心飞' & @CRLF & _
                '' & @CRLF & _
                '我的抽屉 沾满灰尘' & @CRLF & _
                '有多久没整理' & @CRLF & _
                '浓浓哀伤在叹息' & @CRLF & _
                '我拿起了笔 写了古典' & @CRLF & _
                '第一乐章 我想告诉你' & @CRLF & _
                '我快要听不清楚' & @CRLF & _
                '非得要像休止符' & @CRLF & _
                '黑不拉几要断断续续' & @CRLF & _
                '连贝多芬 也都爱上你' & @CRLF & _
                '你说分开最美丽' & @CRLF & _
                '好! 我还想乐章在继续' & @CRLF & _
                '爱来爱去 爱不过是病' & @CRLF & _
                '连贝多芬 都想告诉你' & @CRLF & _
                '耳聋了 更有意义' & @CRLF & _
                '也许你只是下雨下在我的青草地' & @CRLF & _
                '等放晴了 就自然蒸发' & @CRLF       
aaaa()
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        geci()

        EndSwitch
WEnd

Func aaaa()
        Local $sR = StringRegExp($str, '\[\d\d:\d\d\.\d\d\]', 3)
        _ArraySort($sR)
        Local $txt, $i, $_time
        $begin = TimerInit()       
       
        For $i = 0 To UBound($sR) - 1
                        $_time = StringRegExpReplace($sR[$i], '(\[|\])', '\\$1')
                        $txt = StringRegExpReplace($str, '(?s).+?' & $_time & '(?:\[[^\]]+\])*([^\r]*).+', '$1')
                        GUICtrlCreateListViewItem($_time&"|"&$txt, $ListView1)
        Next
EndFunc       

Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)

      Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
      Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
      If @error Then Return $GUI_RUNDEFMSG
      $IDFrom = DllStructGetData($tagNMHDR, 2)
      $Event = DllStructGetData($tagNMHDR, 3)
      $tagNMHDR = 0
      Switch $IDFrom
                Case $ListView1
                        Switch $Event
                              Case $NM_DBLCLK ; 双击
                                        $JHLIST1 = GUICtrlRead(GUICtrlRead($ListView1))
                                        If $JHLIST1 = "" Then Return
                                                                                MsgBox(0,0,"双击事件要执行的代码")
                                                EndSwitch
      EndSwitch

      Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
;以下是逐行显示的代码。
Func geci()
        Local $sR = StringRegExp($str, '\[\d\d:\d\d\.\d\d\]', 3)
        _ArraySort($sR)
        Local $txt, $i, $_time
        $begin = TimerInit()
        For $i = 0 To UBound($sR) - 1
                        $_time = StringRegExpReplace($sR[$i], '(\[|\])', '\\$1')
                        $txt = StringRegExpReplace($str, '(?s).+?' & $_time & '(?:\[[^\]]+\])*([^\r]*).+', '$1')
                        While 1
                                        Sleep(10)
                                        If _IsPressed('1B') Then ExitLoop 2
                                        If Round(TimerDiff($begin)) >= Execute(StringRegExpReplace($sR[$i], '\[(\d\d):(\d\d)\.(\d\d)\]', '$1*60*1000+$2*1000+$3*10')) Then
                                                        ToolTip($txt, 0, 0) ;这里的$txt即需要的文本变量,输出只需改动此行。
                                                        ExitLoop
                                        EndIf
                        WEnd
        Next
EndFunc               

netsmu 发表于 2010-11-23 22:13:11

有人知道吗? 能不能改成WM_TIMER 事件来处理歌词呢?

nbmpe 发表于 2010-11-24 13:37:48

找下千千静听里面应有DLL文件. 不然这个效果实现真起来有点困难.
页: [1]
查看完整版本: 歌词LRC文件如何指定位置开始播放呢?