Kill statement and MediPlayer control

Hi ,
I have a problem that I can't solve myself.

I am using the Adodc control and a DataGrid control.
For each record in the database belongs a wav file.
and when I move from one record to another, the Mediaplayer filename property changes to the correct wave file.

when I delete recored in the Grid, I'd like that the wave file that belongs to that record, will be deleted from the hard disk as well.
so I used the statment Kill ,and gave the path of the file to be deleted.
an error no. 75 was showed.

I guess the problem is because of that I'm trying  to delete a file that the FileName property of the  MediaPlayer control is set to.

I wish you can help me with that .
Thanks
kukiyaAsked:
Who is Participating?
 
mcriderConnect With a Mentor Commented:
Before you kill the file, Do this:

   MediaPlayer1.filename = ""
   Kill "c:\windows\desktop\testme.wav"


Cheers!®©
0
 
GordonpCommented:
you may also need to call a Close function of something similar.

ie

MediaPlayer1.Close

before you can delete the file

Gordon
0
 
mcriderCommented:
Gordonp,

There is no "Close" property for MediaPlayer (MSDXM.OCX)... ;-)

All you have to do is set the filename property to ""


Cheers!®©
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
kukiyaAuthor Commented:
Hi there,
I'm sorry but the error no.75 was still showing even by setting the Filename to "" before the Kill statement.

0
 
GordonpCommented:
I've just tried to recreate it here.

when .Filename was still the name of the file

I got error 70 , permission denied.

what I'd expect really

when .Filename = ""

the file deleted OK

I think something else may be causing your error

Gordon

0
 
mcriderCommented:
This works perfect on my system...

Is the wav still playing when you do this?? If so, stop the wav with:

   MediaPlayer1.Stop
   MediaPlayer1.filename = "" 
   Kill "c:\windows\desktop\testme.wav"


You may also have to do a DoEvents... Like this:


   MediaPlayer1.Stop
   MediaPlayer1.filename = ""
   DoEvents
   Kill "c:\windows\desktop\testme.wav"


You may also want to enforce an error handler... Something like this:
   Dim lRetry As Integer

   MediaPlayer1.Stop
   MediaPlayer1.filename = ""
   On Error Resume Next
   lRetry = 0
   Do
       Err = 0
       DoEvents
       Kill "c:\windows\desktop\testme.wav"
       If Err = 0 Or lRetry = 5 Then Exit Do
       lRetry = lRetry + 1
   Loop



Cheers!®©
0
 
GordonpCommented:
kukiya >
   post the record/file deletion code and we'll see if theres anything obvious in that

Gordon
0
 
kukiyaAuthor Commented:
Here is my code:

Private Sub dgdEvents_BeforeDelete(Cancel As Integer)

Dim response As String
response = MsgBox("Are you sure you want to delete current event?", vbYesNo + vbQuestion, "Confirm Event Delete")

       If response = vbYes Then
          Cancel = False
          DeleteWavPath = txtPath.Text
          Call DeleteWavFile
        End If
           
Private Sub DeleteWavFile()
Dim response As String
   If Dir(DeleteWavPath) <> "" Then the
      response = MsgBox("Do you wish    
      to delete event's audio file  
      too?", vbYesNo +  
      vbQuestion, "Confirm Event    
      Delete")

       If response = vbYes Then
                   
          MediaPlayer1.FileName = ""
          Kill DeleteWavPath
       End If
    End If
End Sub
 
DeleteWavPath is a golbal variable that contains the Path of the wav file to be deleted.The Path is shown in the TextBox txtPath.

I hope that can help more.
Thank you very much!!!!!!!!
           
0
 
mcriderCommented:
I don't see anything wrong with the code except the "End Sub" is missing on the dgdEvents_BeforeDelete subroutine.

What version of VB are you using?? If you are using VB5/VB6 Do you have Service Pack 3 (SP3) installed? If you don't have SP3 installed, Go to this microsoft link:

INFO: Visual Studio 97 Service Packs - What, Where, and Why
http://support.microsoft.com/support/kb/articles/Q170/3/65.ASP 



What version of Media Player are you using??  If you don't have Version 6.4, download it from here:

Windows Media Player
http://www.microsoft.com/windows/mediaplayer/en/default.asp?RLD=58 



Cheers!®©
0
 
mcriderCommented:
By the way, "Call DeleteWavFile" is redundant... You don't need to use the "Call" keyword...

One other question... You haven't opened the wav file as a file someplace else, or have more than 1 MediaPlayer control do you??

Cheers!®©
       
0
 
kukiyaAuthor Commented:
Thank's for you trying to help.

I am using the VB6 and already installed the SP3.
everything seems to be ok with the versions.

I don't know what the problem is.
THANK YOU!!!!!!

0
 
mcriderCommented:
What about your version of Media Player...
0
 
kukiyaAuthor Commented:
I also installed the MediaPlayer Version 6.4, though I don't know how to verify that it was dowloaded correctly.


0
 
mcriderCommented:
Well, this is a stumper, because you seem to have the correct version of everything... and I don't see any problems with the code you posted... SO... Lets go back to basics...


1) Copy a WAV to c:\windows\desktop\testme.wav

2) Start a new project and add 2 Command buttons called "Command1" and "Command2".  Then add MediaPlayer1 control to the form.

3) Add the following code to the declarations section of the form:

    Private Sub Command1_Click()
    MediaPlayer1.filename = "c:\windows\desktop\testme.wav"
    End Sub
    Private Sub Command2_Click()
       MediaPlayer1.Stop
       MediaPlayer1.filename = ""
       Kill "c:\windows\desktop\testme.wav"
    End Sub


4) Run the program and click command1... The mediaplayer should play the sound you copied to the desktop...

5) Click command2... The WAV file you copied to the desktop should be deleted.



If you follow the steps above EXACTLY, everything should work.  If it doesn't work, there is a much bigger problem with your system...


Cheers!®©

0
 
mcriderCommented:
By the way... This is alot of work for 20 points...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.