Playing multiple mp3 files

pcc

Well-known Member
Joined
Jan 21, 2003
Messages
1,382
Office Version
  1. 2021
Platform
  1. Windows
VBA Code:
Public wmp As Object

Sub aaTest()
    Dim r As Long
    lr = [a1].CurrentRegion.Rows.Count
    For r = 2 To lr
    If Cells(r, 2) = "Y" Then
    Set wmp = CreateObject("new:6BF52A52-394A-11D3-B153-00C04F79FAA6")
    
        With wmp
            .URL = Cells(r, 1)
            .Controls.Play
        End With
        DoEvents
        
      
        End If
    Next r
End Sub

I have the above code. I am trying to get Excel to play several mp3 files in succession. However, all it does is play the last row that has a "Y" in column 2.
How can I get it to play each one, waiting until the song has finished before playing the next one?

Hope someone can help

Regards
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Update: I have found that if I put a Stop statement after "DoEvents", then it will play the first song in the list. If I then click "Continue" in the VB editor, it will then start to play the next song in the list, and each time I click "Continue", the next song plays. So the question is how to get the system to wait. I could possibly use the file size to estimate the duration of the song, and put an
Application.Wait statement into the code, but his seems a bit of a blunt instrument. Anyone have other ideas?
 
Upvote 0
Sorted. I found code on this site to get the file length (in terms of time, not size). Then loading a userform seems to do the trick
VBA Code:
Option Compare Text
Sub aaaaaazz()
Sheets("Control").Activate
lr = [a1].CurrentRegion.Rows.Count
    For r = 2 To lr
    If Cells(r, 5) = "Y" Then
    dur = Cells(r, 6)  ' duration in seconds
    Set wmp = CreateObject("new:6BF52A52-394A-11D3-B153-00C04F79FAA6")
        With wmp
            .URL = Cells(r, 1)
            .Controls.Play
        End With
        DoEvents
        UserForm2.Show False
        newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + dur
waitTime = TimeSerial(newHour, newMinute, newSecond)
DoEvents
Application.Wait waitTime
        Unload UserForm2
        End If
    Next r
  
End Sub
 
Upvote 0
Solution
Further question...it is possible to pause playing? I have buttons on the useform to play next file, previous file, and to stop playing altogether (End statement). However, it would
be really useful if it were possible to pause playing, and then continue from where it left off. Don't think this will be possible but you are a very clever bunch and someone might have
a suggestion. Any offers? Thanks.
 
Upvote 0
VBA Code:
Public wmp As Object

Sub aaTest()
    Dim r As Long
    lr = [a1].CurrentRegion.Rows.Count
    For r = 2 To lr
    If Cells(r, 2) = "Y" Then
    Set wmp = CreateObject("new:6BF52A52-394A-11D3-B153-00C04F79FAA6")
   
        With wmp
            .URL = Cells(r, 1)
            .Controls.Play
        End With
        DoEvents
       
     
        End If
    Next r
End Sub

I have the above code. I am trying to get Excel to play several mp3 files in succession. However, all it does is play the last row that has a "Y" in column 2.
How can I get it to play each one, waiting until the song has finished before playing the next one?

Hope someone can help

Regards
E' necessario intercettare gli eventi PlayStateChange:
- MediaEndend (alla fine di un brano), fissando un boolean bEndend=True
- Stopped (dopo che è finito il brano): if bEndend=True then
.URL=nexttrack
 
Upvote 0
E' necessario intercettare gli eventi PlayStateChange:
- MediaEndend (alla fine di un brano), fissando un boolean bEndend=True
- Stopped (dopo che è finito il brano): if bEndend=True then
.URL=nexttrack
Io no parlo Italiano. Grazie
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top