Hi. Ich habe mir eine Klasse aufgebaut, die mit mciSendString in der lage sein soll, musik abzuspielen. Das Abspielen funktioniert auch prima. Jedoch kann ich weder die Länge noch die aktuelle Position auslesen. Ich bekomme stets die Meldung:
ystem.NullReferenceException: Object reference not set to an instance of an object.
at LibaryTester1.SoundFile.mciSendString(String& cmd, String& rsl, Int32 rsl_start, Int32 hwdcallback)
at LibaryTester1.SoundFile.get_Length() in C:\Dokumente und Einstellungen\user\Eigene Dateien\SharpDevelop Projects\LibaryTester1\MainForm.vb:line 16
at LibaryTester1.MainForm.Button1Click(Object sender, EventArgs e) in C:\Dokumente und Einstellungen\user\Eigene Dateien\SharpDevelop Projects\LibaryTester1\MainForm.vb:line 146
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Hier der code:
Public Class SoundFile
Private Declare Function mciSendString Lib "winmm.dll" Alias _
"mciSendStringA" (ByVal cmd As String,ByRef rsl As String,ByVal _
rsl_start As Int32,ByVal hwdcallback As Int32) As Int32
Private str_alias As String
Public ReadOnly Property Length As Long
Get
Dim strBuffer As String = Space(128)
mciSendString("set " & str_alias & " time format" & _
"milliseconds",0,0,0)
mciSendString("status " & str_alias & " length",strBuffer,128,0)
Return(CLng(strBuffer.Trim()))
End Get
End Property
Public ReadOnly Property Position As Long
Get
Dim strBuffer As String = Space(128)
mciSendString("set " & str_alias & " time format" & _
"milliseconds",strBuffer,128,0)
mciSendString("status " & str_alias & "" & _
"position",strBuffer,128,0)
Return(CLng(strBuffer.Trim()))
End Get
End Property
Private Function randomNumber() As String
Dim firstPart,secondPart,lastPart As String
Dim r As New Random()
firstPart = Microsoft.VisualBasic.Conversion.Hex(r.Next( _
100000,999999)).Trim().ToLower()
Return(firstPart)
End Function
Public Sub New(ByVal AudioFile As String,Optional ByVal DefaultVolume As _
Long = 1000)
str_alias = "audiofile" & randomNumber() & "mp3neo"
Try
Dim N As String = Chr(34)
If mciSendString("open " & N & AudioFile & N & " alias " & _
str_alias,0,0,0) = 0 Then
If mciSendString("setaudio " & str_alias & " volume to " & _
DefaultVolume,0,0,0) <> 0 Then
MessageBox.Show("Fehler bei der Initialisierung des" & _
"Songs","Fehler",MessageBoxButtons.Ok,MessageBoxIcon.Error)
mciSendString("close " & str_alias,0,0,0)
End If
Else
MessageBox.Show("Fehler bei der Initialisierung des" & _
"Songs","Fehler",MessageBoxButtons.Ok,MessageBoxIcon.Error)
End If
Catch
End Try
End Sub
Public Overloads Function AudioPlay() As Boolean
If mciSendString("play " & str_alias & " from 0",0,0,0) = 0 Then
Return(True)
Else
Return(False)
End If
End Function
Public Overloads Function AudioPlay(ByVal FromPosition As Long) As Boolean
If FromPosition <= Me.Length - 10 And FromPosition >= 0 Then
If mciSendString("play " & str_alias & " from 0",0,0,0) = 0 Then
Return(True)
Else
Return(False)
End If
End If
End Function
End Class Kann mir bitte jemand helfen?!
PS: Ich nutze SharpDevelop 1.1 unter .NET 1.1!
MFG
Griever |