简体   繁体   English

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

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

I have two textbox. 我有两个文本框。 I want to play audio 1 to audio 4 then it will play audio1, audio2, audio3 and audio4 我想将音频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) (goo.gl/nHGxMS)

still can't resolve 仍然无法解决

  1. For loop is from integer value in textbox1.Text To integer value in textbox2.Text. For循环是从textbox1.Text中的整数值到textbox2.Text中的整数值。 So convert the values in textbox from string to Integer. 因此,将文本框中的值从字符串转换为整数。 Later you can add validations for the values. 稍后,您可以为这些值添加验证。 You may like to check if value is greater than 0, less than 5, etc. 您可能想检查值是否大于0,小于5等。
  2. For loop is playing only 1 file 4 times in background. For循环仅在后台播放4次1个文件。 So, change the file name in the for loop so that it can play different song file in next iteration. 因此,在for循环中更改文件名,以便它可以在下一次迭代中播放不同的歌曲文件。
  3. AudioPlayMode.WaitToComplete (instead of AudioPlayMode.Background) should be used to wait for the song to complete and then proceed with next iteration. 应该使用AudioPlayMode.WaitToComplete(而不是AudioPlayMode.Background)来等待歌曲完成,然后进行下一次迭代。

Try below code. 尝试下面的代码。

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