繁体   English   中英

如何使用VB.Net播放下一个音频?

[英]How to play next audio using VB.Net?

我有两个文本框。 我想将音频1播放为音频4,然后它将播放音频1,音频2,音频3和音频4

Sub play()

For i As integer = textbox1.Text To textbox2.Text
My.Computer.Audio.Play("D:\Audio\audio1", AudioPlayMode.Background)

(goo.gl/nHGxMS)

仍然无法解决

  1. For循环是从textbox1.Text中的整数值到textbox2.Text中的整数值。 因此,将文本框中的值从字符串转换为整数。 稍后,您可以为这些值添加验证。 您可能想检查值是否大于0,小于5等。
  2. For循环仅在后台播放4次1个文件。 因此,在for循环中更改文件名,以便它可以在下一次迭代中播放不同的歌曲文件。
  3. 应该使用AudioPlayMode.WaitToComplete(而不是AudioPlayMode.Background)来等待歌曲完成,然后进行下一次迭代。

尝试下面的代码。

Sub play()

    Dim fromValue As Integer
    If Not Integer.TryParse(textbox1.Text, fromValue) Then
        MessageBox.Show("Not an integer")
        Return
    End If

    Dim toValue As Integer
    If Not Integer.TryParse(textbox2.Text, toValue) Then
        MessageBox.Show("Not an integer")
        Return
    End If

    For i As Integer = fromValue To toValue
        My.Computer.Audio.Play("D:\Audio\audio" & i.ToString, AudioPlayMode.WaitToComplete)
    Next

End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM