国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

無外部控件制作多媒體播放器(四)

2024-07-21 02:25:42
字體:
供稿:網(wǎng)友



音樂文件列表也是個不容忽視的問題,自己定個格式當(dāng)然可以,但好在大家熟悉的m3u格式并不復(fù)雜,mediaplayer或winamp都支持它,通用性也好,比起wpl要簡易得多,所以我就來介紹一下m3u格式文件的制作與讀寫

m3u是文本文件,以#extm3u開頭,每個音樂條目占1-2行,當(dāng)存在擴展信息時,首行采用#extinf:開頭,第二行才是文件名;當(dāng)沒有擴展信息時,只是簡單的一行,就是文件名;文件名可包含路徑,也可不包含,不包含時音樂文件應(yīng)該是與m3u文件在同一目錄下。

整個格式就這么簡單,下面是讀取函數(shù),與保存函數(shù),讀取時返回的是一個m3u集合,每個集合項目為一首音樂信息的字符串,想獲取這個串的具體內(nèi)容, 可用getm3uinfo函數(shù)返回musicinfo結(jié)構(gòu)。

保存函數(shù)不太完善,需傳入一個m3u集合,因使用集合傳遞m3u字串信息,每個條目只能添加刪除,不能直接修改。若有興趣,可采取類封裝musicinfo結(jié)構(gòu),并提供修改功能。

private function loadm3ufile(strfilename as string) as collection
    dim a() as string, s1 as string, s as string, i as long, fileline() as string
    dim blnaddok as boolean, strfilepath as string, coltemp as collection, linenum as long
    on error goto fail
    set coltemp = new collection
    if dir(strfilename) = vbnullstring then goto fail
    strfilepath = left$(strfilename, instrrev(strfilename, "/"))
    open strfilename for binary as #1
        s = input(lof(1), 1)
    close
    if s = vbnullstring then goto fail
    i = instr(1, s, "#extm3u", vbtextcompare)
    if i = 0 then goto fail
    if i > 1 then s = mid$(s, i)
    s = trim$(replace$(s, vbcrlf & vbcrlf, vbcrlf))
    fileline = split(s, vbcrlf)
        do while linenum <= ubound(fileline)
            s = trim$(fileline(linenum))
            if s <> vbnullstring then
                blnaddok = false
                if ucase$(left$(s, 8)) <> "#extinf:" then
                    if instr(1, s, ":/") = 0 then
                        s = strfilepath & s
                        if dir(s, vbnormal or vbhidden or vbreadonly or vbsystem or vbarchive) <> vbnullstring then blnaddok = true
                    else
                        if dir(s, vbnormal or vbhidden or vbreadonly or vbsystem or vbarchive) <> vbnullstring then
                            blnaddok = true
                        else
                            s = strfilepath & mid$(s, instrrev(s, "/") + 1)
                            if dir(s, vbnormal or vbhidden or vbreadonly or vbsystem or vbarchive) <> vbnullstring then blnaddok = true
                        end if
                    end if
                    if blnaddok then
                        if getmcitype(s) > 0 then
                            coltemp.add s, s
                        end if
                    end if
                else
                    s = mid$(s, 9)
                    linenum = linenum + 1
                    s1 = trim$(fileline(linenum))
                    if s1 <> vbnullstring then
                        if instr(1, s1, ":/") = 0 then
                            s1 = strfilepath & s1
                            if dir(s1, vbnormal or vbhidden or vbreadonly or vbsystem or vbarchive) <> vbnullstring then blnaddok = true
                        else
                            if dir(s1, vbnormal or vbhidden or vbreadonly or vbsystem or vbarchive) <> vbnullstring then
                                blnaddok = true
                            else
                                s1 = strfilepath & mid$(s1, instrrev(s1, "/") + 1)
                                if dir(s1, vbnormal or vbhidden or vbreadonly or vbsystem or vbarchive) <> vbnullstring then blnaddok = true
                            end if
                        end if
                        if blnaddok then
                            if getmcitype(s1) > 0 then
                                coltemp.add s & vbcrlf & s1, s1
                            end if
                        end if
                    end if
                end if
            end if
            linenum = linenum + 1
        loop
fail:
    set loadm3ufile = coltemp
end function
private function savem3u(strfilename as string, colm3ulist as collection) as boolean
    dim freeno as long, i as long, a() as string
    on error goto fail
    if colm3uliste.count > 0 then
        freeno = freefile
        open strfilename for output as #freeno
        print #freeno, "#extm3u"
        for i = 1 to colm3uliste.count
        a = split(colm3uliste(i), vbcrlf)
        if ubound(a) > 0 then
            print #freeno, "#extinf:" & colm3uliste(i)
        else
            print #freeno, colm3uliste(i)
        end if
        next
        close #freeno
        savem3u = true
    end if
fail:
end function
private function getm3uinfo(m3uitem as string) as musicinfo
    dim a() as string, b() as string, tmpinfo as musicinfo
    dim i as long, j as long, k as long, s as string
    if trim(m3uitem) = vbnullstring then exit function
    a = split(m3uitem, vbcrlf)
    if ubound(a) > 0 then
        j = instr(1, a(0), ",")
        k = instr(1, a(0), "-")
        if j > 0 and k > 0 then
            b = split(a(0), ",")
            if val(b(0)) > 0 then tmpinfo.length = val(b(0))
            b = split(trim$(b(1)), "-")
            if b(0) <> vbnullstring then tmpinfo.artist = trim$(b(0))
            if b(1) <> vbnullstring then
                tmpinfo.title = trim$(b(1))
            else
                s = trim$(a(1))
                i = instrrev(s, "/")
                if i > 0 then
                    tmpinfo.title = mid$(s, i + 1)
                else
                    tmpinfo.title = s
                end if
            end if
        end if
        tmpinfo.filename = a(1)
    else
        tmpinfo.filename = a(0)
    end if
    getm3uinfo = tmpinfo
end function

private sub command1_click()
    dim tmp as collection, tmpinfo as musicinfo, s as string
    set tmp = loadm3ufile(text1.text)
    if tmp.count > 0 then
        tmpinfo = getm3uinfo(tmp(tmp.count))
        s = "文件:" & tmpinfo.filename
        s = s & vbcrlf & "歌名:" & tmpinfo.title
        s = s & vbcrlf & "歌手:" & tmpinfo.artist
        s = s & vbcrlf & "曲長:" & tmpinfo.length & "秒"
        msgbox s
    end if
end sub

這是一個與上篇相聯(lián)系的代碼,對于一些沒定義的函數(shù),可在前面的文章中找到
http://blog.csdn.net/homezj/archive/2005/04/15/349005.aspx
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 莎车县| 乌恰县| 临沭县| 鹿邑县| 克什克腾旗| 宜君县| 永兴县| 安塞县| 崇明县| 凤山县| 基隆市| 沈丘县| 汶上县| 阿拉尔市| 西平县| 上犹县| 七台河市| 都昌县| 辉县市| 大足县| 玉环县| 三门县| 韩城市| 闻喜县| 呼图壁县| 汕尾市| 通海县| 融水| 肇州县| 苍山县| 遵义市| 壤塘县| 盐边县| 荔波县| 新兴县| 通化县| 湖北省| 桃园市| 林西县| 登封市| 大竹县|