Results 1 to 3 of 3

Thread: Need some help with audio playback

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2011
    Posts
    1

    Need some help with audio playback

    Hey guys and gals, thanks for taking a look.
    Basically my program has a "shuffle" music feature:

    vb Code:
    1. For i = 0 To 26
    2.             num = randomObject.Next(0, 27)
    3.             My.Computer.Audio.Play("C:\Users\Mcturtles\Music\Songs\" & num & ".wav", AudioPlayMode.BackgroundLoop)
    4.         Next

    Which selects a random number 0 - 26 and selects the corresponding song.

    And a straight play feature:

    vb Code:
    1. Dim counter As Integer
    2.         Do Until counter > 26
    3.             My.Computer.Audio.Play("C:\users\mcturtles\music\songs\" & counter & ".wav", AudioPlayMode.WaitToComplete)
    4.             counter += 1
    5.         Loop

    All of these activated by a button(separate for each)

    When I click one, it makes the program stop responding. I'm pretty sure it is the .WaitToComplete mode, but I can't find a way to make it continuously play without it. If you can find my error, it would be greatly appreciated.

    Also if you could tell me a way to make the shuffle never play the same song twice, that would be awesome as well.


    Thanks,
    Mcturtles
    Last edited by gep13; Mar 22nd, 2011 at 02:24 AM. Reason: Added Highlight Tags

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Need some help with audio playback

    Hello Mcturtles,

    Welcome to the Forums!!

    When you are posting code into the forum, can you please remember to surround it in [code][/code] or [HIGHLIGHT=vb][/highlight] tags? It makes it a lot easier to read. I have done this for you in your above post.

    Thanks

    Gary

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Need some help with audio playback

    to play your wavs on a secondary thread (asynchronously) while retaining the WaitToComplete, try this:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         Dim t As New Threading.Thread(AddressOf playWaves)
    5.         t.Start()
    6.     End Sub
    7.  
    8.     Private Sub playWaves()
    9.         Dim counter As Integer
    10.         Do Until counter > 26
    11.             My.Computer.Audio.Play("C:\users\mcturtles\music\songs\" & counter & ".wav", AudioPlayMode.WaitToComplete)
    12.             counter += 1
    13.         Loop
    14.     End Sub
    15.  
    16. End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width