VB.net 循环播放 mp3 直到选择下一个 IF

Posted

技术标签:

【中文标题】VB.net 循环播放 mp3 直到选择下一个 IF【英文标题】:VB.net loop mp3 until next IF is selected 【发布时间】:2013-11-07 03:55:36 【问题描述】:

大家好,我有以下代码:

Dim totalDistance as Boolean = False

    If totalDistance <= 210 Then
        'red
        If isPlaying = False Then
            isPlaying = True
            WMP.URL = Application.StartupPath + "\red.mp3"
            WMP.controls.stop()
            WMP.controls.play()
            WMP.settings.setMode("loop", True)
        End If

        backupLineRED.Visible = True
        backupLineYELLOW.Visible = False
        backupLineGREEN.Visible = False
    ElseIf totalDistance > 210 And totalDistance <= 670 Then
        'yellow
        WMP.URL = Application.StartupPath + "\yellow.mp3"
        WMP.controls.play()
        backupLineRED.Visible = True
        backupLineYELLOW.Visible = True
        backupLineGREEN.Visible = False
    ElseIf totalDistance > 671 And totalDistance <= 1000 Then
        'green
        WMP.URL = Application.StartupPath + "\green.mp3"
        WMP.controls.play()
        backupLineRED.Visible = True
        backupLineYELLOW.Visible = True
        backupLineGREEN.Visible = True
    End If

我想循环播放声音,直到它到达下一个 IF 语句。但是我想不出一种正确检查它的方法,因为 isPlaying 将始终保持 true 并且当它进入另一个时我需要找到一种方法将其设置回 false IF 语句。

任何帮助都会很棒!谢谢!

【问题讨论】:

【参考方案1】:

知道了......也许这会满足你的需要:

    If totalDistance <= 210 Then
        'red
        If WMP.URL <> Application.StartupPath + "\red.mp3" Then
            WMP.URL = Application.StartupPath + "\red.mp3"
            WMP.controls.stop()
            WMP.controls.play()
            WMP.settings.setMode("loop", True)
        End If

        backupLineRED.Visible = True
        backupLineYELLOW.Visible = False
        backupLineGREEN.Visible = False
    ElseIf totalDistance > 210 And totalDistance <= 670 Then
        'yellow
        If WMP.URL <> Application.StartupPath + "\yellow.mp3" Then
            WMP.URL = Application.StartupPath + "\yellow.mp3"
            WMP.controls.stop()
            WMP.controls.play()
            WMP.settings.setMode("loop", True)
        End If

        backupLineRED.Visible = True
        backupLineYELLOW.Visible = True
        backupLineGREEN.Visible = False
    ElseIf totalDistance > 671 And totalDistance <= 1000 Then
        'green
        If WMP.URL <> Application.StartupPath + "\green.mp3" Then
            WMP.URL = Application.StartupPath + "\green.mp3"
            WMP.controls.stop()
            WMP.controls.play()
            WMP.settings.setMode("loop", True)
        End If

        backupLineRED.Visible = True
        backupLineYELLOW.Visible = True
        backupLineGREEN.Visible = True
    End If

【讨论】:

每个 IF 语句都需要进行检查,因为每个 .mp3 都需要循环,直到它位于不同的 if 语句中。

以上是关于VB.net 循环播放 mp3 直到选择下一个 IF的主要内容,如果未能解决你的问题,请参考以下文章

媒体播放器循环播放:Android

VB.Net - 音频文件专辑艺术

在VB Net中每秒更新文本块的文本

使用 VB.net 进行宣传

在不使用库的情况下播放 MP3/WAV 文件?

vb.net中 AxWindowsMediaPlayer的用法