Problem getting WMP to play sound file

JA12

Member
Joined
Jul 2, 2013
Messages
17
Location
Ireland
Programming Experience
10+
Hopefully this will be my last problem to be solved. Here's the relevant snips of the code

I'm dynamically generating a form from an XML file, the controls are a repetitive group of buttons to control the sound file.

VB.NET:
Module General
Imports WMPLib
End Module
VB.NET:
Form Player
Dim WithEvents oWMP As New WMPLib.WindowsMediaPlayer

Private Sub player_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        ' Adds handlers for the generic handling of the buttons
    
   'Start Timer
             StartTimer()
             Timer1.Enabled = True
End Sub

Private Sub StartTimer()
          Me.Timer1.Enabled = True
          Me.Timer1.Interval = 1000
          Me.Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal obj As Object, ByVal e As EventArgs) Handles Timer1.Tick
          updatePlayer()
    End Sub

Private Sub subPlay()
  ' get the values from the active GroupBox so we can open the MP3 sound clip

  ' Initiate the WMP controller
  oWMP.URL = "full file path/file.mp3"
  oWMP.controls.play()

End Sub

Private Sub updatePlayer()
          Static iCountdown As Integer
          Dim iHours As Integer
          Dim iMins As Integer
          Dim iSecs As Integer
          ' Update TrackPostion
          If oWMP IsNot Nothing Then
                If Len(oWMP.URL) > 0 Then
                      With oPosition
                                           .Minimum = 0
                                           .Maximum = CInt(oWMP.currentMedia.duration)
                           .Value = CInt(oWMP.controls.currentPosition())
                     End With
                     'Display current time in label...
                     'Create a Form-level integer variable iCountdown
                     Dim hms As String()

                     hms = Split(oLength.Text, ":", -1, CompareMethod.Text)
                     iCountdown = (CInt(hms(0)) * 60 * 60) + (CInt(hms(1)) * 60) + CInt(hms(2))

                     iCountdown = iCountdown - 1
                     iHours = CInt(iCountdown / 60 / 60)
                     hms(0) = Format(iHours, "00")
                     iMins = CInt((iCountdown - (iHours * 60 * 60)) / 60)
                     hms(1) = Format(iMins, "00")
                     iSecs = (iCountdown - (iHours * 60 * 60) - (iMins * 60))
                     hms(2) = Format(iSecs, "00")
                     oElapsed.Text = Join(hms, ":")
                     If iCountdown = 0 Then
                           Timer1.Enabled = False
                     End If
               End If
         End If
    End Sub
End Form

From everything I've read, and examples. This should start the sound file playing. It seems to only execute the first "Tick" because the oElapsed label is initialized, the trkPosition TrackBar remains at zero, and the sound file doesn't start playing.

I've checked the URL and the file definitely exists. I've played the file using WinAmp and there's no problem with the file.

I've included the resource files:

VB.NET:
AxInterop.WMPLib.dll
Interop.WMPLib.dll

as per the only example I've found that actually works.

Any ideas?
 
OK, I've got it playing the sound clips now. I've no idea what I did, but whatever it was, it's now fixed...

I hate things like that. I don't learn from "magic" solutions!
 
Back
Top