Sure , anyone has any problem with the project version , he has to get the converter from below link . Winrar is giving you error , get it and unpack the demo and it should all go smooth .
VB Code:
Private Declare Function mciExecute Lib "winmm.dll" (ByVal lpstrCommand As String) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Play Button
Dim OFD As New OpenFileDialog
OFD.Filter = "MP3 Files (*.MP3)|*.MP3"
If OFD.ShowDialog = DialogResult.OK Then
mciExecute("OPEN " & OFD.FileName & " TYPE MPEGVideo ALIAS mp3song ")
mciExecute("PLAY mp3song")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
This uses API which is not specific to any version of VS.NET . I used that in both VB.NET 2002 & 2003 and even before in VB6 days and they're working fine . How did you use anyway ?
ok. i found out the problem. if the filename or path has a space in it, then then i get an error. i made a file c:\test.mp3 and it works.
how do i get around this severe limitation?
That's right . I'll try to look for a fix but not now since I'm busy with something else . Search MSDN for any associated errors with mciExecute API Function , you might come up with a treat .
I've tried this proj in VB6 on the same path and same file and worked fine . I does use GetShortPathName API as <ABX said . It's easy to port it to VB.NET .
sorry can you post the code as text )I dont have vb on the comp i use for internet right now.) and my vb comp dosn't have any removable storage drives.
Private Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private mmOpen As String, sec As Integer, mins As Integer
Dim nFileName As String
Public Function MP3Play(wndHandle As Long, sFileName As String)
Dim cmdToDo As String * 255
Dim dwReturn As Long
Dim ret As String * 128
Dim tmp As String * 255
Dim lenShort As Long
Dim ShortPathAndFie As String, glo_HWND As Long
If Dir(sFileName) = "" Then
mmOpen = "Error with input file"
Exit Function
End If
lenShort = GetShortPathName(sFileName, tmp, 255)
ShortPathAndFie = Left$(tmp, lenShort)
glo_HWND = wndHandle
cmdToDo = "open " & ShortPathAndFie & " type MPEGVideo Alias MP3Play"
dwReturn = mciSendString(cmdToDo, 0&, 0&, 0&)
If dwReturn <> 0 Then 'not success
mciGetErrorString dwReturn, ret, 128
mmOpen = ret
MsgBox ret, vbCritical
Exit Function
End If
mmOpen = "Success"
mciSendString "play MP3Play", 0, 0, 0
End Function
Public Function MP3Pause()
mciSendString "pause MP3Play", 0, 0, 0
End Function
Public Function MP3UnPause()
mciSendString "play MP3Play", 0, 0, 0
End Function
Public Function MP3Stop() As String
mciSendString "stop MP3Play", 0, 0, 0
mciSendString "close MP3Play", 0, 0, 0
End Function
Private Sub Check1_Click()
Timer1 = Not Timer1
If Timer1 Then Check1.Value = 1 Else Check1.Value = 0
I was bored; bored enough to make a binary clock but I also made a class for playing mp3 files in vb .net
VB Code:
Option Strict On
Option Explicit On
Imports System.IO
Public Class cMCI
Private Const MCI_DEFAULT_ALIAS As String = "MP3Play"
Public Enum MCI_STATUS_MODE
Not_Ready = 1
Paused = 2
Playing = 4
Stopped = 8
Open = 16
Parked = 32
Recording = 64
Seeking = 128
Unknown = 0
End Enum
Private strMCIAlias As String
#Region " API DECLARE STATEMENTS "
Private Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Integer, ByVal lpstrBuffer As String, ByVal uLength As Integer) As Integer
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Integer) As Integer
Private 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
#End Region
#Region " Private Class Member Variables "
Private m_strFilePath As String
#End Region
#Region " Public Class Properties "
Public ReadOnly Property MCI_STATUS() As MCI_STATUS_MODE
Get
Return GetStatus()
End Get
End Property
Public Property FilePath() As String
Get
Return m_strFilePath
End Get
Set(ByVal Value As String)
m_strFilePath = Value
End Set
End Property
#End Region
#Region " Private Functions "
Private Function ThrowMCIError(ByVal errCode As Integer) As Boolean
i implemented it all and everything works. that is some sick code. i learned a lot of unrelated stuff too, like overloading functions and stuff. i didn't know vb could do that. you can't overload operators, can you?
stop and pause do the same thing though. i would think that stop would also reset the song, but it dosn't...