Solved

synchronously or asynchronously ?? - playsound problem on large wav files

Posted on 2010-09-05
3
526 Views
Last Modified: 2012-05-10
I have a large vinyl record collection - 18,000 - and am in the process of recording them to computer at very high WAV quality - 32 bit , 48,000 hrz.  In writing the code in VB to play any I have recorded, the search for Artist/Album works great in my SQL database and displays the search in my DatGridview.  Then I select the Artist and/or Album to play and hit my Play button.  Stored with the Artist/Album is the full directory location of the matching WAV file.  
The Play button activates the Playit Sub where i activate MPlayer set on load to make Global.  It plays the large WAV file fine until I click on a different Artist/Album choice and hit play.  The WAV file playing stops immediately, but the new choice only sometimes does it start to play.  How can I solve this problem?  If it doesn't play, it will hang until I close the program and reload.  Thanks Marvin E Marshall

  Dim StopMusic As Boolean = True    ' These Dims are set at top of code under Imports
  Dim WaveFile As String = ""
  Dim Mplayer As New SoundPlayer()

 Public Sub Playit()
        Dim rowSl As Integer = 0
        Dim cell1, cell2, cell3, cell4, cell5 As String

        rowSl = DataGridView2.CurrentRow.Index

        cell1 = DataGridView2.Item(1, rowSl).Value
        cell2 = DataGridView2.Item(2, rowSl).Value
        cell3 = DataGridView2.Item(3, rowSl).Value
        cell4 = DataGridView2.Item(4, rowSl).Value
        cell5 = DataGridView2.Item(5, rowSl).Value

        Dim ln As Integer = 0
        ln = Len(Cell1)
        WaveFile = Cell1

        Mplayer.Stop()
        Application.doevents

        Mplayer.SoundLocation = cell1
         ' Mplayer.Play()
        Mplayer.PlaySync()

        txtPlaying.Text = WaveFile

    End Sub
0
Comment
Question by:MarvinEMarshall
  • 2
3 Comments
 
LVL 3

Expert Comment

by:AndyEastham
ID: 33609674
Hi,

This code contains some ideas to try:

 Mplayer.Stop()
        Application.doevents
        Thread.Sleep(1000) ' Wait a second
       
        Mplayer.SoundLocation = Nothing ' Will force reload
        Mplayer.SoundLocation = cell1
        Mplayer.Load() ' Need to reload if path changed
        Mplayer.Play()
        ' Mplayer.PlaySync()


Andy
0
 

Author Comment

by:MarvinEMarshall
ID: 33612849
AndyEastham

Thanks Andy.    I tried your code suggestion and variations. they seemed logical.  As far as the wait of one second  I changed that to - Threading.Thread.Sleep(1000)  which works without declaring.  However, the Mplayer.SoundLocation = Nothing throws and exception - and "" does the same.  Although, the idea seemed logical, so I created two 5 second wav files called Blank.wav and Blank2.wav.  Then if the Boolean MusicActive is true then I give Mplayer.SoundLocation that address and play it.  That still didn't clear things out enough, so I repeated the idea so I play both Bank stopped it cleared the location and then did the same for Blank2.  Both would play instantly - I made a couple of scratch sounds on them both just to verify they actually played.  Then after both played entirely - just 5 seconds each, I felt surely  the large uncompleted first wav file would be cleaned out of memory.  Nope, when a large file is then selected even after playing the two Blanks.  Even if I wait several minutes after the code executes the Load and Play lines of code and returns me back to my form.
So, there hast to be a way to force the memory block that loads the large wav file to clear or release after forciing a Mplayer.Stop()
I guess we can learn together on this one.  Thanks for your suggestions - Marvin E Marshall
0
 

Accepted Solution

by:
MarvinEMarshall earned 0 total points
ID: 33663515
AndyEastham,
Took a lot of research, but the disappointing fact is that the use of soundplayer is severaly limited and WILL NOT support of large WAV files if you want to move from one to another prior to it completing.

I guess we both learned on this one.
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now