Forum

Playing a Window Me...
 
Notifications
Clear all

Playing a Window Media Player's playlist in Excel

21 Posts
4 Users
0 Reactions
801 Views
(@julian)
Posts: 82
Estimable Member
Topic starter
 

abc.pngHi Mynda,

I have an Excel file embedded Window Media Player Control using a pivot table slicer to populate the selected files on column A as the snapshot attached. I also wrote a VBA in a hope to play the file in the list one after another.

Sub test()
Range("A2").Select
Do While Not IsEmpty(ActiveCell)
Text1 = ActiveCell.Value
WindowsMediaPlayer2.URL = Text1
WindowsMediaPlayer2.Controls.Play

' how to continue the next until the previous one has been over?

Selection.Offset(1, 0).Select
Loop
End Sub

Unfortunately, after running through the loop WindowMedia Player 1 alway just play the last file only. Could you please spare some time to take a look at this case and help me correct it? I would appreciate it.
Best regards,

Julian Chen

 
Posted : 13/12/2016 4:24 am
(@catalinb)
Posts: 1937
Member Admin
 

Hi Julian,

I think you have to build the playlist first, then you start play.

Try:

Sub test()
Dim NewFile as Variant
Range("A2").Select
Do While Not IsEmpty(ActiveCell)
WindowsMediaPlayer1.playlistCollection.getByName("MyNewPlaylist")
WindowsMediaPlayer1.currentPlaylist.Clear
Text1 = ActiveCell.Value
Set newFile = WindowsMediaPlayer1.newMedia(Text1)
WindowsMediaPlayer1.currentPlaylist.insertItem 0, newMedia
Selection.Offset(1, 0).Select
Loop
'the playlist is created, play it
WindowsMediaPlayer1.Controls.Play

End Sub

 
Posted : 13/12/2016 6:25 am
(@julian)
Posts: 82
Estimable Member
Topic starter
 

Hi Catalin,

 Thanks for your prompt reply. I copied your code into my Sub Worksheet_PivotTableUpdate function as it was triggered by Pivot Table update then changed the initial cell to "A33" as listed below. However, after running the code the program would be stuck on line 8 with a run-time error 424 - 'Object required". Could you please check it out what's missing?

Regards,

Julian 

 Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
 Dim NewFile As Variant
 Range("A33").Select
 Do While Not IsEmpty(ActiveCell)
 WindowsMediaPlayer1.playlistCollection.getByName ("MyNewPlaylist")
 WindowsMediaPlayer1.currentPlaylist.Clear
 Text1 = ActiveCell.Value
 Set NewFile = WindowsMediaPlayer1.newMedia(Text1)
 WindowsMediaPlayer1.currentPlaylist.insertItem 0, newMedia
 Selection.Offset(1, 0).Select
 Loop
 'the playlist is created, play it
 'WindowsMediaPlayer1.Controls.Play
 
End Sub        

 
Posted : 13/12/2016 9:36 pm
(@catalinb)
Posts: 1937
Member Admin
 

Dim NewFile as Object, instead of variant, this should be the problem.

 
Posted : 14/12/2016 12:56 am
(@julian)
Posts: 82
Estimable Member
Topic starter
 

Hi Catalin,

The same problem "Object required" still exists. Does it need to create a playlistarray instead?

Regards,

Julian

 
Posted : 14/12/2016 1:46 am
(@catalinb)
Posts: 1937
Member Admin
 

Can you upload a sample file?

 
Posted : 14/12/2016 2:41 am
(@julian)
Posts: 82
Estimable Member
Topic starter
 

Hi Catalin,

Here you are the attached file. There are 3 Window Media Players embedded in, Please check the tab with name "Media". The rest two works well. Sorry again for bothering you so much.

 

Best regards,

 

Julian

 
Posted : 14/12/2016 9:16 pm
(@catalinb)
Posts: 1937
Member Admin
 

Try changing these 2 lines:

Dim NewFile As Variant
 

NewFile = WindowsMediaPlayer1.newMedia(Text1)

 

Or, you can try this version:

 

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
 Dim NewFile As Variant

Dim Playlist As IWMPPlaylist
Set Playlist = WindowsMediaPlayer1.newPlaylist("MyNewPlayList", "")
 Range("A33").Select

'the following 2 lines were inside the loop, which was wrong... we don't have to clear the list at each loop

 WindowsMediaPlayer1.playlistCollection.getByName ("MyNewPlaylist")
 WindowsMediaPlayer1.currentPlaylist.Clear

 Do While Not IsEmpty(ActiveCell)
 Text1 = ActiveCell.Value
  NewFile = WindowsMediaPlayer1.newMedia(Text1)
 WindowsMediaPlayer1.currentPlaylist.insertItem 0, newMedia
 Selection.Offset(1, 0).Select
 Loop
 'the playlist is created, play it
 'WindowsMediaPlayer1.Controls.Play

 
End Sub      

Or, you can try adding items to the new playlist created, then set the playlist as current, instead of clearing the current playlist and adding new items:

Do while...

Playlist.appendItem WindowsMediaPlayer1.newMedia(Text1)

Loop
WindowsMediaPlayer1.currentPlaylist = Playlist

WindowsMediaPlayer1.Controls.Play

 
Posted : 15/12/2016 12:41 am
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Julian

Try this amended code (original code from Catalin above). Tested and working for me.

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Dim NewFile As Variant
Dim Playlist As IWMPPlaylist
Set Playlist = WindowsMediaPlayer1.newPlaylist("MyNewPlayList", "")
Range("A33").Select
WindowsMediaPlayer1.playlistCollection.getByName ("MyNewPlaylist")
WindowsMediaPlayer1.currentPlaylist.Clear
Do While Not IsEmpty(ActiveCell)
Text1 = ActiveCell.Value
'NewFile = WindowsMediaPlayer1.newMedia(Text1)
Set NewFile = WindowsMediaPlayer1.mediaCollection.Add(Text1)
WindowsMediaPlayer1.currentPlaylist.insertItem (WindowsMediaPlayer1.currentPlaylist.Count), NewFile
Selection.Offset(1, 0).Select
Loop

'the playlist is created, play it
WindowsMediaPlayer1.Controls.Play

End Sub

 
Posted : 15/12/2016 2:13 am
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Julian

Attached is my own sample playlist.

Hope this helps.

Cheers

Sunny

 
Posted : 15/12/2016 2:33 am
(@julian)
Posts: 82
Estimable Member
Topic starter
 

Hi Catalin / SunnyKow's :

Let me report my test results as follows:

I' m sorry to say all the solutions provided below were failed and I'm not sure did it has something with my 64-bit operating sytem. In order to get support memory amounts over 4 GB for Power query and DAX running I've installed my Excel 2013 and PowerBI desk in 64-bit versions. If this is the case, how the VBA script can be modified?

Scripts from Catalin - got the same error message "Object does'nt suppport this property or method" and stuck on the line in bold font type

(1).

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
  Dim NewFile As Variant
  NewFile = WindowsMediaPlayer1.newMedia(Text1)
  Range("A33").Select
  Do While Not IsEmpty(ActiveCell)
  WindowsMediaPlayer1.playlistCollection.getByName ("NewFile")
  WindowsMediaPlayer1.currentPlaylist.Clear
  Text1 = ActiveCell.Value
  Set NewFile = WindowsMediaPlayer1.newMedia(Text1)
  WindowsMediaPlayer1.currentPlaylist.insertItem 0, newMedia
  Selection.Offset(1, 0).Select
  Loop
  'the playlist is created, play it
  'WindowsMediaPlayer1.Controls.Play
End Sub

(2).

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
 Dim NewFile As Variant

Dim Playlist As IWMPPlaylist
Set Playlist = WindowsMediaPlayer1.newPlaylist("MyNewPlayList", "")
 Range("A33").Select

'the following 2 lines were inside the loop, which was wrong... we don't have to clear the list at each loop

 WindowsMediaPlayer1.playlistCollection.getByName ("MyNewPlaylist")
 WindowsMediaPlayer1.currentPlaylist.Clear

 Do While Not IsEmpty(ActiveCell)
 Text1 = ActiveCell.Value
  NewFile = WindowsMediaPlayer1.newMedia(Text1)
 WindowsMediaPlayer1.currentPlaylist.insertItem 0, newMedia
 Selection.Offset(1, 0).Select
 Loop
 'the playlist is created, play it
 'WindowsMediaPlayer1.Controls.Play

Script from SunnyKow's fixed code - got the error message: "Method 'add' of object ' IWMPMedia Collectio2' failed" and stuck on the line in bold font type

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Dim NewFile As Variant
Dim Playlist As IWMPPlaylist
Set Playlist = WindowsMediaPlayer1.newPlaylist("MyNewPlayList", "")
Range("A33").Select
WindowsMediaPlayer1.playlistCollection.getByName ("MyNewPlaylist")
WindowsMediaPlayer1.currentPlaylist.Clear
Do While Not IsEmpty(ActiveCell)
Text1 = ActiveCell.Value
'NewFile = WindowsMediaPlayer1.newMedia(Text1)
Set NewFile = WindowsMediaPlayer1.mediaCollection.Add(Text1)
WindowsMediaPlayer1.currentPlaylist.insertItem (WindowsMediaPlayer1.currentPlaylist.Count), NewFile
Selection.Offset(1, 0).Select
Loop

'the playlist is created, play it
WindowsMediaPlayer1.Controls.Play

End Sub

 
Posted : 15/12/2016 11:53 pm
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Julian

The worksheet I attached earlier (with Catalin's code) works fine with me. No errors at all.

I wonder if any other members encountered the same error as yours.

Anyway, I have attached another version that I have. The codes are different. Hopefully it will work for you this time.

Sunny

 
Posted : 16/12/2016 11:20 am
(@julian)
Posts: 82
Estimable Member
Topic starter
 

Hi SunnyKow,

Just tried run your file on my computer and it worked well. Therefore, I would modify my script based on your version later on. By the way, Just wonder if you have ever tried to play the transcripts files together with the videos synchronously also using VBA script? I think it's worth a trial. Any way, Thanks for your early Christmas gift. You are my this year's Santa Claus.

Best regards,

Julian

 
Posted : 16/12/2016 11:00 pm
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Julian

Happy to know it is working now.

"Just wonder if you have ever tried to play the transcripts files together with the videos synchronously also using VBA script?"

What transcript files are you referring to?

 
Posted : 16/12/2016 11:16 pm
(@julian)
Posts: 82
Estimable Member
Topic starter
 

It's about SubRip file format with (.srt) extension or simply a plain text file showing what was said (ii.e. subtitle or caption) in a video / movie....

 

 

 
Posted : 17/12/2016 12:19 am
Page 1 / 2
Share: