该怎么办?请高手老鸟帮忙

解决方案 »

  1.   

    我用其它的工具播放没有这个现象。代码如下:程序包括两个部分:form1和module1
    form1有6个按钮和一个timer控件,分别执行播放、暂停、取消播放、停止播放、重复播放和打开文件.
    timer时间为500ms,初始设置其Enabled 为false打开文件也用的是api函数module1.bas申明一个类
    form1:
    -------------------------------------------------------------------
    Option ExplicitPrivate Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long 'SHOWOPEN
    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
    Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As LongDim OFName As OPENFILENAME      '全局变量
    Dim MusicFileName As String
    Dim ShortPathName As String
    ---------------------------------------------------------------------------------
    Private Sub Command1_Click()'打开文件
    Call ShowOpen
    End Sub
    ---------------------------------
    Private Sub Command6_Click()'取消暂停
    mciSendString "Resume " & ShortPathName, 0&, 0, 0
    If Tmr.Enabled = False Then Tmr.Enabled = True
    End Sub
    -----------------------------------
    Private Sub Command2_Click()'播放
    Dim S As String
    If MusicFileName <> "" Then
        S = String(LenB(MusicFileName), Chr(0))    GetShortPathName MusicFileName, S, Len(S)    ShortPathName = Left(S, InStr(S, Chr(0)) - 1)
    End IfmciSendString "open MPEGVideo", 0&, 0, 0mciSendString "play " & ShortPathName, 0&, 0, 0End Sub
    --------------------------------------------
    Private Sub Command3_Click()'暂停
    mciSendString "pause " & ShortPathName, 0&, 0, 0
    Tmr.Enabled = FalseEnd Sub
    ----------------------------------------------
    Private Sub Command4_Click()'停止播放
    mciSendString "close all", 0&, 0, 0
    Tmr.Enabled = False
    End Sub
    --------------------------------------------
    Private Sub Command5_Click()'重复播放Tmr.Enabled = True
    End Sub
    ----------------------------
    Private Sub Form_Load()
    If App.PrevInstance = True Then End
    End Sub
    -----------------------------------
    Private Function ShowOpen() As String
    OFName.lStructSize = Len(OFName)
        'Set the parent window
        OFName.hwndOwner = Me.hWnd
        'Set the application's instance
        OFName.hInstance = App.hInstance
        'Select a filter
        OFName.lpstrFilter = "Mp3 Files (*.mp3)" + Chr$(0) + "*.mp3" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
        'create a buffer for the file
        OFName.lpstrFile = Space$(254)
        'set the maximum length of a returned file
        OFName.nMaxFile = 255
        'Create a buffer for the file title
        OFName.lpstrFileTitle = Space$(254)
        'Set the maximum length of a returned file title
        OFName.nMaxFileTitle = 255
        'Set the initial directory
        OFName.lpstrInitialDir = "C:\"
        'Set the title
        OFName.lpstrTitle = "打开文件"
        'No flags
        OFName.flags = 0    'Show the 'Open File'-dialog
        If GetOpenFileName(OFName) Then MusicFileName = OFName.lpstrFile
        
    End Function
    ----------------------------------
    Private Sub Form_Unload(Cancel As Integer)
    mciSendString "close all", 0&, 0, 0
    Tmr.Enabled = FalseEnd Sub
    ------------------------------------
    Private Sub Tmr_Timer()
    Dim S As String
    Call Command2_Click
        S = String(256, Chr(0))
        mciSendString "status " & ShortPathName & " mode", S, Len(S), 0    If Left(S, 7) = "stopped" Then        mciSendString "seek " & ShortPathName & " to start", vbNullString, 0, 0        mciSendString "play " & ShortPathName, vbNullString, 0, 0    End IfEnd Sub
    -------------------------------------module1.bas:---------------------------------------------------------------------------------
    Type OPENFILENAME    lStructSize As Long    hwndOwner As Long    hInstance As Long    lpstrFilter As String    lpstrCustomFilter As String    nMaxCustFilter As Long    nFilterIndex As Long    lpstrFile As String    nMaxFile As Long    lpstrFileTitle As String    nMaxFileTitle As Long    lpstrInitialDir As String    lpstrTitle As String    flags As Long    nFileOffset As Integer    nFileExtension As Integer    lpstrDefExt As String    lCustData As Long    lpfnHook As Long    lpTemplateName As StringEnd Type-------------------------------------------------------------------------------
      

  2.   

    别笑我,我是砖瓦匠人。呵难道是声卡问题?我猜测是不是timer控件时间设置太短,赶明儿我在改改。如果是声卡问题,是什么问题?你能给我多解释解释吗?
      

  3.   

    果然是timer的问题看来要弃用它。那又该怎么办呢?请高手老鸟们指教
      

  4.   

    给你一个"超级解霸":
    Option Explicit
    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As LongPrivate Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As LongDim sname As String
    Dim lstindex As IntegerPrivate Sub Command1_Click()
    Dim s As String
    sname = File1.Path
    If Right(sname, 1) <> "\" Then
        sname = sname + "\" + File1.FileName
    End If
    s = String(LenB(sname), Chr(0))mciSendString "close MEDIA", vbNullString, 0, 0
    mciSendString "open " & sname & " alias MEDIA", vbNullString, 0, 0
    mciSendString "play MEDIA", vbNullString, 0, 0
    Timer1.Enabled = True
    End SubPrivate Sub Command2_Click()
    mciSendString "close MEDIA", vbNullString, 0, 0
    End SubPrivate Sub Command3_Click()
    Unload Me
    End SubPrivate Sub Dir1_Change()
    File1.Path = Dir1.Path
    lstindex = 0
    End SubPrivate Sub Drive1_Change()
    Dir1.Path = Drive1
    End SubPrivate Sub File1_Click()
    lstindex = File1.ListIndex
    End SubPrivate Sub Form_Load()
    Me.Caption = "Mp3播放器"
    Skin1.ApplySkin Me.hWnd
    Drive1.Drive = "e:\"
    Dir1.Path = "e:\media"
    File1.Pattern = "*.mp3;*.mid"
    End SubPrivate Sub Timer1_Timer()
    Dim strmode As String * 256
    mciSendString "status MEDIA mode", strmode, Len(strmode), 0
    lblmode.Caption = strmode
    If Left(strmode, 7) = "stopped" Then
        lstindex = lstindex + 1
            If lstindex >= File1.ListCount Then
                lstindex = 0
            End If
        File1.ListIndex = lstindex
        sname = File1.Path + "\" + File1.List(lstindex)
        mciSendString "close MEDIA", vbNullString, 0, 0
        mciSendString "open " & sname & " alias MEDIA", vbNullString, 0, 0
        mciSendString "play MEDIA", vbNullString, 0, 0
    End If
    End Sub