DirectX AudioVideoPlayback

Cheetah

Well-known member
Joined
Oct 12, 2006
Messages
232
Programming Experience
Beginner
Hi there,

I am using this import (Microsoft.DirectX.AudioVideoPlayback) for my audio media application.

Problem is, when it finishes playing via the [.ending] event I move to the next track and it crashes and i get this error:



Wierd thing is, I can here the next track playing whilst i have this error message open. When I close it, it stops playing.

But I also have a button which goes to the next track aswell (same code) and that works fine without the error.

What am i doing wrong?

Thanks.
 
I have narrowed it down to the the .Dispose event for the audio i created.

Here is the code:

VB.NET:
Public Class Form1
    Public WithEvents MMedia As clsDXaudiovideo
    Dim playlist As New List(Of String)
    Dim cItem As Integer

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim MediaObject As New clsDXaudiovideo
        MMedia = MediaObject

        playlist.Add("C:\Documents and Settings\Ben Barron\Desktop\New Folder\1.mp3")
        playlist.Add("C:\Documents and Settings\Ben Barron\Desktop\New Folder\2.mp3")

        cItem = 0

        MMedia.LoadMedia(playlist(cItem))
        MMedia.PlayMedia()

    End Sub

    Private Sub NextMedia() Handles MMedia.NextMedia

        If cItem = (playlist.Count - 1) Then
            cItem = 0
        Else
            cItem += 1
        End If
        MMedia.LoadMedia(playlist(cItem))
        MMedia.PlayMedia()

    End Sub

End Class

VB.NET:
Imports Microsoft.DirectX.AudioVideoPlayback

Public Class clsDXaudiovideo
    Public WithEvents objAudio As Audio
    Public Event NextMedia()

    Private m_MediaLoaded As Boolean            '// is there a media file loaded ?

    Public Sub New()
        m_MediaLoaded = False
    End Sub

    Public Sub LoadMedia(ByVal FileName As String)
        '//
        '  If media object exists, then get rid of it
        '  Load the file, but don't play automatically
        '\\
        '//  A U D I O  \\

        If Not objAudio Is Nothing Then 
            objAudio.Dispose() '// The problem is with this bit \\
            objAudio = Nothing
        End If

        Try
            objAudio = New Audio(FileName, False)
        Catch ex As Exception
            MessageBox.Show(ex.Message & " -- " & "Audio Meida can not be loaded.")
            m_MediaLoaded = False
            Exit Sub
        End Try
        '//
        '  Set property for a loaded media to be true
        '\\
        m_MediaLoaded = True

    End Sub
    Public Function PlayMedia() As Boolean
        If Not m_MediaLoaded Then Return False

        objAudio.Play()

        Return True

    End Function
    Public Function StopMedia() As Boolean
        If Not m_MediaLoaded Then Return False

        If Not objAudio Is Nothing Then objAudio.Stop()

        Return True

    End Function
    Public Function PauseMedia() As Boolean
        If Not m_MediaLoaded Then Return False

        If Not objAudio Is Nothing Then objAudio.Pause()

        Return True

    End Function

    Private Sub objAudio_Ending(ByVal sender As Object, ByVal e As System.EventArgs) Handles objAudio.Ending

        RaiseEvent NextMedia()

    End Sub


End Class
 
Back
Top