【问题标题】:C# trackbar mciSendStringC# 轨迹栏 mciSendString
【发布时间】:2015-03-14 02:50:34
【问题描述】:

我正在使用 MCI 编写 CD 音频播放器程序,但无法在轨迹栏上显示音频文件的进度。

有人知道怎么做吗?

请注意,我必须使用mciSendString 来获取音轨长度。

【问题讨论】:

    标签: c# mci


    【解决方案1】:

    来自Simple MCI Player - CodeProject,略有改动:

    public int GetCurrentPosition()
    {
        String command = "status MediaFile position";
        error = mciSendString(command, returnData, 
                              returnData.Capacity, IntPtr.Zero);
        return error == 0 ? int.Parse(returnData.ToString()) : 0;
    }
    
    public int GetSongLenght()
    {
        if (IsPlaying())
        {
            String command = "status MediaFile length";
            error = mciSendString(command, returnData, returnData.Capacity, IntPtr.Zero);
            return error == 0 ? int.Parse(returnData.ToString()) : 0;
        }
        else
            return 0;
    }
    

    【讨论】:

    • thx 但我的问题是关于轨道栏...我不知道如何在上面显示轨道进度...
    • @user1740616 调用GetCurrentPosition 获取文件的当前位置,然后将轨迹栏的值设置为该位置。
    • 事件处理程序怎么样?我想我也需要那个?
    • @user1740616 是什么让你这么认为? MCI 会引发事件吗?
    • 好的,所以在我获得当前位置后,我将它传递给 trackbars 值,我已经做到了,但它仍然没有随着轨道移动..所以我认为我需要一个事件处理程序......
    【解决方案2】:

    在 VB 中,我在 Timer Tick Sub 中执行了此操作...真的很简单...

    rem 音频是 mcisendstring 的东西 rem TotalLength 是当前曲目的总秒数

        Dim PlayPosition As Long = 0
    
        PlayPosition = audio.SecondsPlayed
        If PlayPosition > 0 And PlayPosition < TotalLength Then
            TrackBar1.Value = (PlayPosition / TotalLength) * TotalLength
        End If
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      • 2016-05-24
      • 1970-01-01
      相关资源
      最近更新 更多