Solved

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

Posted on 2010-09-05
3
534 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

630 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