Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]()
Quick question if I may...
I need to play two simultaneous sound files in Excel, and as I cannot have two userforms at the same time, I'm trying to have one play as a userform in mediaplayer and the other play as a windos media player ActiveX object embedded into the sheet (using Office 2007). However when I try to instruct the windows media player to begin playing it's file it hits a bug and refuses to budge. Am I attempting the impossible or just missing the obvious? Many thanks Private Sub UserForm_Activate() Dim Mfile As String Mfile = "c:\video\crowd.wav" MP.Open (Mfile) WindowsMediaPlayer1.URL = "c:\video\crowdup.wav" |
#2
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]()
Put two mediaplayers onto the userform.
HTH. Best wishes Harald "teepee" wrote in message ... Quick question if I may... I need to play two simultaneous sound files in Excel, and as I cannot have two userforms at the same time, I'm trying to have one play as a userform in mediaplayer and the other play as a windos media player ActiveX object embedded into the sheet (using Office 2007). However when I try to instruct the windows media player to begin playing it's file it hits a bug and refuses to budge. Am I attempting the impossible or just missing the obvious? Many thanks Private Sub UserForm_Activate() Dim Mfile As String Mfile = "c:\video\crowd.wav" MP.Open (Mfile) WindowsMediaPlayer1.URL = "c:\video\crowdup.wav" |
#3
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]() "Harald Staff" wrote in message ... Put two mediaplayers onto the userform. Never knew you could do that! Obvious when you don't make stupid assumptions. Many thanks |
#4
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]() "Harald Staff" wrote in message ... Put two mediaplayers onto the userform. I knew it couldn't be that simple. They won't play simultaneously |
#5
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]() "teepee" wrote in message ... "Harald Staff" wrote in message ... Put two mediaplayers onto the userform. I knew it couldn't be that simple. They won't play simultaneously but maybe a media player and a windows media player 8-) |
#6
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]()
I have no problems with two windowsmediaplayers on a userform. Add also a
togglebutton1 and change path to soundfiles: Private Sub UserForm_Initialize() Me.WindowsMediaPlayer1.URL = _ "C:\Users\Harald\Music\adrian belew - bird in a box (remix).mp3" Me.WindowsMediaPlayer2.URL = _ "C:\Users\Harald\Music\adrian belew - man in the moon.mp3" End Sub Private Sub ToggleButton1_Click() If Me.ToggleButton1.Value = True Then Me.WindowsMediaPlayer1.Controls.Play Me.WindowsMediaPlayer2.Controls.Play Else Me.WindowsMediaPlayer1.Controls.pause Me.WindowsMediaPlayer2.Controls.pause End If End Sub HTH. Best wishes Harald |
#7
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]() "Harald Staff" wrote in message ... I have no problems with two windowsmediaplayers on a userform. Add also a togglebutton1 and change path to soundfiles: Yes it works OK with two wmp but not with two mp. But funnily enough I find a media player and a windows media player in the userform keep better sync with each other than two windows media players - especially when the files loop Here is my code for keeping them more or less in sync - cell a1 will show the media player current position and a2 will show the wmp current poistion. If you make cell a3 = a1-a2 then it will work. Any improvements welcomed - if anyone can find a way to put them completely in sync that would be a dream... Private Sub UserForm_Activate() WindowsMediaPlayer1.settings.setMode "loop", True WindowsMediaPlayer1.URL = "c:\video\file1.wav" MP.PlayCount = 1000 Dim Mfile As String Mfile = "c:\video\file2.wav" MP.Open (Mfile) Do DoEvents Dim Oldpos As Long 'Dim oldpos2 As Long If MP.currentPosition = Oldpos + 0.1 Then 'after plus sign number of seconds _ between uppdate of cell A1 Application.Cells(1, 1) = MP.currentPosition Application.Cells(1, 2) = WindowsMediaPlayer1.Controls.currentPosition On Error Resume Next Oldpos = Application.WorksheetFunction.RoundDown(MP.current Position, 0) Calculate UserForm4.Repaint Else End If If MP.currentPosition < Oldpos Then 'this should trigger whenever the audio file loops Application.Cells(1, 1) = MP.currentPosition WindowsMediaPlayer1.Controls.currentPosition = MP.currentPosition - Range("a3") 'a3 is a subtraction of the current position of the media player and the windows media player - so they should be brought into sync, although in practice it's sometimes up to a third of a second out Oldpos = Application.WorksheetFunction.RoundDown(MP.current Position, 0) Calculate UserForm4.Repaint Else End If If MP.PlayState = mpStopped Then Exit Do If MP.PlayState = mpClosed Then Exit Do If MP.PlayState = mpPaused Then Exit Do Loop Until MP.currentPosition = 10 End Sub |
#8
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]()
your initial problem was "I need to play two simultaneous sound files in
Excel," which you now can do. Problem is what? "teepee" wrote in message ... Yes it works OK with two wmp but not with two mp. But funnily enough I find a media player and a windows media player in the userform keep better sync with each other than two windows media players - especially when the files loop |
#9
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]() "Harald Staff" wrote in message ... your initial problem was "I need to play two simultaneous sound files in Excel," which you now can do. Problem is what? Simultaneousness is the problem. They are slightly out of sync with each other. For background, wav file 1 is a looping sound effect, wav file 2 is designed to cover the short gap when file one loops. But of course it only works if you have a high degree of synchronization. |
#10
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]() teepee wrote: "Harald Staff" wrote in message ... your initial problem was "I need to play two simultaneous sound files in Excel," which you now can do. Problem is what? Simultaneousness is the problem. They are slightly out of sync with each other. For background, wav file 1 is a looping sound effect, wav file 2 is designed to cover the short gap when file one loops. But of course it only works if you have a high degree of synchronization. Why not "create" the sound file you need, by patching together the sound files you have into a single one? |
#11
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]() "Bob I" wrote Why not "create" the sound file you need, by patching together the sound files you have into a single one? Because the sound file changes randomly between 10 possible audios depending on the value of a cell and i can't have gaps during the changover. And the second sound file performs the double function of covering the loop gap and also buffering the transition between the two sound files like a cross fade. |
#12
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]()
Forget the loop, simoultaneous playing, and rethink this. All you need imo
is to start Player2 just before Player1 ends. And vice versa. Then you can change tracks on the non-playing player like a DJ. In a standard module, enter code like this: Sub Startone() UserForm1.WindowsMediaPlayer1.Controls.Play End Sub Sub StartTwo() UserForm1.WindowsMediaPlayer2.Controls.Play End Sub and in your userform module: Private Sub WindowsMediaPlayer1_PlayStateChange(ByVal NewState As Long) If NewState = 3 Then Application.OnTime (Now + _ TimeSerial(0, 0, Me.WindowsMediaPlayer1.currentMedia.Duration - 2)), "StartTwo" End If End Sub Private Sub WindowsMediaPlayer2_PlayStateChange(ByVal NewState As Long) If NewState = 3 Then Application.OnTime (Now + _ TimeSerial(0, 0, Me.WindowsMediaPlayer2.currentMedia.Duration - 2)), "StartOne" End If End Sub HTH. Best wishes Harald "teepee" skrev i melding ... "Bob I" wrote Why not "create" the sound file you need, by patching together the sound files you have into a single one? Because the sound file changes randomly between 10 possible audios depending on the value of a cell and i can't have gaps during the changover. And the second sound file performs the double function of covering the loop gap and also buffering the transition between the two sound files like a cross fade. |
#13
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]()
Thanks Harold - shall study this closely
|
#14
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]() "Harald Staff" wrote in message ... Forget the loop, simoultaneous playing, and rethink this. All you need imo is to start Player2 just before Player1 ends. Hmm I don't actually know when player 1 is going to end - the changeovers come at random points. |
#15
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]() "teepee" wrote Hmm I don't actually know when player 1 is going to end - the changeovers come at random points. To amplify on that point, our code works really well (thanks for that) at startup but as soon as the variable changes which requires the audio track to switch, it seems to go out its rhythm. Note that a4 gives me a value which forms part of the URL of the audio file, so I had to adjust your code "UserForm1.WindowsMediaPlayer2.Controls.Play" into "UserForm1.WindowsMediaPlayer1.URL = "c:\video\audio" & Range("a4") & ".wav". Don't know if that's the problem? Any thoughts? In sheet1 Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$A$4" Then 'a4 is where the variable data is switching about randomly Call Startone End If End Sub and in the userform4 Private Sub WindowsMediaPlayer1_PlayStateChange(ByVal NewState As Long) If NewState = 3 Then Application.OnTime (Now + TimeSerial(0, 0, _ Me.WindowsMediaPlayer1.currentMedia.Duration - 2)), "StartTwo" End If End Sub Private Sub WindowsMediaPlayer2_PlayStateChange(ByVal NewState As Long) If NewState = 3 Then Application.OnTime (Now + TimeSerial(0, 0, _ Me.WindowsMediaPlayer2.currentMedia.Duration - 2)), "StartOne" End If End Sub In module Sub Startone() UserForm4.WindowsMediaPlayer1.URL = "c:\video\audio" & Range("a4") & ".wav" End Sub Sub StartTwo() UserForm4.WindowsMediaPlayer2.URL = "c:\video\audio" & Range("a4") & "a.wav" End Sub |
#16
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]()
Thought is that you haven't communicated what you want to build, and
probably still don't. Changeover now comes at "random points" (or, reading between the codelines, when something happens in a cell of some spreadsheet doing unknown functionality), whereas before changeovers were to mask sounddrop at a loop. It is really impossible to help you. Best wishes Harald "teepee" wrote in message ... "teepee" wrote Hmm I don't actually know when player 1 is going to end - the changeovers come at random points. To amplify on that point, our code works really well (thanks for that) at startup but as soon as the variable changes which requires the audio track to switch, it seems to go out its rhythm. Note that a4 gives me a value which forms part of the URL of the audio file, so I had to adjust your code "UserForm1.WindowsMediaPlayer2.Controls.Play" into "UserForm1.WindowsMediaPlayer1.URL = "c:\video\audio" & Range("a4") & ".wav". Don't know if that's the problem? Any thoughts? In sheet1 Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$A$4" Then 'a4 is where the variable data is switching about randomly Call Startone End If End Sub and in the userform4 Private Sub WindowsMediaPlayer1_PlayStateChange(ByVal NewState As Long) If NewState = 3 Then Application.OnTime (Now + TimeSerial(0, 0, _ Me.WindowsMediaPlayer1.currentMedia.Duration - 2)), "StartTwo" End If End Sub Private Sub WindowsMediaPlayer2_PlayStateChange(ByVal NewState As Long) If NewState = 3 Then Application.OnTime (Now + TimeSerial(0, 0, _ Me.WindowsMediaPlayer2.currentMedia.Duration - 2)), "StartOne" End If End Sub In module Sub Startone() UserForm4.WindowsMediaPlayer1.URL = "c:\video\audio" & Range("a4") & ".wav" End Sub Sub StartTwo() UserForm4.WindowsMediaPlayer2.URL = "c:\video\audio" & Range("a4") & "a.wav" End Sub |
#17
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]()
<sigh
thanks anyway |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Controlling media player in VBA question | Excel Discussion (Misc queries) | |||
Close Windows Media Player | Excel Discussion (Misc queries) | |||
Force asx to bring up Windows Media Player - How? | Excel Discussion (Misc queries) | |||
Media player import to excel | Excel Discussion (Misc queries) | |||
Media Player versus Windows Media Player | Excel Discussion (Misc queries) |