Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

mp3 player generates error message

$
0
0

Dear smart programmers out there:
In this short mp3 player with 5 buttons  (Open, Play, Pause, Stop,  Close), clicking on the play button returns Error Code 263: Invalid Device Name. The Open button works fine.

Public Class Form1
    Dim BooleanPlaying As Boolean = False
    Dim filename As String
    Public Declare Function mciSendCommand Lib "winmm.dll" Alias "mciSendCommandA" (ByVal wDeviceID As Integer, ByVal uMessage As String, ByVal dw1Param As Integer, ByVal dw2param As Object) As Integer
    Public Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Integer, ByVal lpstrBuffer As String, ByVal uLength As Integer) As Integer
    Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallBack As Integer) As Integer

 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        'Handles Open: uses OpenFileDialog1 to fetch the mp3 file
        Dim ret As Integer
        If BooleanPlaying = True Then
            MessageBox.Show("The Player is busy.")
            Exit Sub
        Else
            OpenFileDialog1.Filter = "mp3 Files|*.mp3"
            OpenFileDialog1.ShowDialog()
            filename = OpenFileDialog1.FileName
            Label1.Text = filename
            Button1.Enabled = False           'disable Play button
            Button2.ForeColor = Color.Lime     'highlight the Play Button
            Button3.Enabled = False           'disable Pause Button
            Button4.Enabled = False           'disable Stop Button
            BooleanPlaying = True
            ret = mciSendString("Open " & Chr(34) & filename & Chr(34) & "alias Audio", CStr(0), 0, 0)
        End If
    End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        'Handles Play Button
        Dim ret As Integer
        ret = mciSendString("play audio", CStr(0), 0, 0)
        If ret <> 0 Then MsgBox(ret & "Error  Playing File")    'this is where I get error 263
    End Sub

Any one's help on this matter is deeply appreciated. Documentation on Windows API is not very verbose. Especially on mp3's.



Philippe de Marchin


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>