If I have an audio file playing using DirectX.AudioVideoPlayback.Audio and I
click the stop button, using the following code:
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStop.Click
Try
Player.StopWhenReady()
Catch
End Try
End Sub
Private Sub PlayerStopped(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Player.Stopping
While Player.Stopped = False
'do nothing here. we're waiting for it to stop.
End While
Timer1.Stop()
Try
Player.Dispose()
Player = Nothing
Catch ex As Exception
End Try
trkPosition.Value = 0
lblPosition.Text = "0:00"
MsgBox("Made it thru this sub")
End Sub
I get the following exception:
System.AccessViolationException was unhandled
Message="Attempted to read or write protected memory. This is often an
indication that other memory is corrupt."
Source="Microsoft.DirectX.AudioVideoPlayback"
StackTrace:
at AudioWndProc(HWND__* hWnd, UInt32 uMsg, UInt32 wParam, Int32
lParam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager. System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationCo ntext context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsF ormsApplicationBase.Run(String[]
commandLine)
at eDeeJay.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Line 81 referred to in the StackTrace happens to be the "Handles
Player.Stopping" line.
I was using:
Try
Player.Dispose()
Player = Nothing
Catch ex As Exception
End Try
in the btnPlay_Click event to unload the player and reload and it worked
fine. But I need to unload the player when I click the Stop button. If I
move the Try block back up so it is in the Play button event code, it works
fine again. The MsgBox in the Player.Stopping event fires so I know it's
making it all the way through the code there. But as soon as I click the OK
button in the MsgBox, I get the error above. What gives?