|
-
Feb 11th, 2009, 05:15 AM
#1
Thread Starter
Addicted Member
Playing audio files.
Dear all,
Hope all in fine tune.
I am creating a media player project. I am taking the list of audio files (.mp3) in a list box. Now I want them to be played one by one starting from the top of the list box.
I am writing the code in a loop where I am taking a loop which runs from the 0th Index to the index=Items.Count-1
But while playing only the last song is played. How can I rectify this problem. Please help me.
Code:
Private Sub PlaySong()
Dim i As Integer
i = 0
Do While i < Playlist.Items.Count
Playlist.GetSelected(i)
PlayerControl.URL = Playlist.Items.Item(i)
If PlayerControl.URL <> "" Then
'PlayerControl.Ctlcontrols.play()
'DurationTimer.Enabled = True
Else
DurationTimer.Enabled = False
End If
i = i + 1
Loop
End Sub
-
Feb 11th, 2009, 09:30 AM
#2
New Member
Re: Playing audio files.
Depending on what version of visual basic you currently own, Rumor has it, version 6.0 and lower supports only ".wav" audio files, so you must convert your .mp3 perhaps?
-
Feb 11th, 2009, 10:53 AM
#3
Re: Playing audio files.
It looks to me that the loop you show does play every song in the list but it does not appear to wait for a song to finish before playing the next one.
-
Feb 11th, 2009, 07:50 PM
#4
Re: Playing audio files.
 Originally Posted by lotlon
Depending on what version of visual basic you currently own, Rumor has it, version 6.0 and lower supports only ".wav" audio files, so you must convert your .mp3 perhaps?
There are several audio controls compatible with Vb6 that support practically all audio formats. I recommend either .mp3 or .wma rather than .wav files that are much larger. Either one of these two audio file formats have no loss in sound quality while saving lots of disk space and memory.
-
Feb 11th, 2009, 08:11 PM
#5
Fanatic Member
Re: Playing audio files.
VB6 as well as 5 can play mp3 because windows can play mp3. Add this code to a module and you can start Jammin':
Code:
Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Public 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
Public Function Play_MM(song As String)
Dim shortpath As String, pathlength As Long
shortpath = Space(250)
pathlength = GetShortPathName(song, shortpath, Len(shortpath))
If pathlength Then
shortpath = Left$(shortpath, pathlength)
End If
mciSendString "Close MM", 0, 0, 0
mciSendString "Open " & shortpath & " Alias MM", 0, 0, 0
mciSendString "Play MM", 0, 0, 0
End Function
Public Function Pause_MM()
If Paused = False Then
mciSendString "Pause MM", 0, 0, 0
Paused = True
Else
mciSendString "Play MM", 0, 0, 0
Paused = False
End If
End Function
Public Function Stop_MM()
mciSendString "Stop MM", 0, 0, 0
mciSendString "Close MM", 0, 0, 0
End Function
You can check if the songs still playing by :
Code:
s = Space(128)
x = mciSendString("status MM mode", s, Len(s), 0)
If Left(s, 7) = "stopped" Then
'do stopped stuff
ElseIf Left(s, 7) = "playing" Then
'do playing stuff
end if
stick that part in a timer
Last edited by technorobbo; Feb 11th, 2009 at 08:19 PM.
-
Feb 11th, 2009, 08:45 PM
#6
Fanatic Member
Re: Playing audio files.
Here let me put it together for you.
This program will read the XP My Music directory and play it:
1 form and 1 listbox
Code:
Option Explicit
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
'Declaration for the winmm dll
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 Sub Form_Load()
Dim env As String, x As String, test As String, i As Integer
Me.Show
env = Environ("USERPROFILE") & "\My Documents\My Music\"
List1.Clear
x = Dir(env & "*.mp3")
Do While x <> ""
List1.AddItem x
x = Dir()
Loop
For i = 0 To List1.ListCount - 1
Play_MM env & List1.List(i)
DoEvents
test = "playing"
While Left(test, 7) = "playing"
test = Space(128)
x = mciSendString("status MM mode", test, Len(test), 0)
DoEvents
Wend
Next
End Sub
Public Function Play_MM(song As String)
Dim shortpath As String, pathlength As Long
shortpath = Space(250)
pathlength = GetShortPathName(song, shortpath, Len(shortpath))
If pathlength Then
shortpath = Left$(shortpath, pathlength)
End If
mciSendString "Close MM", 0, 0, 0
mciSendString "Open " & shortpath & " Alias MM", 0, 0, 0
mciSendString "Play MM", 0, 0, 0
End Function
Private Sub Form_Unload(Cancel As Integer)
mciSendString "Close MM", 0, 0, 0
End
End Sub
Post edited to add the end command
Last edited by technorobbo; Feb 11th, 2009 at 08:52 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|