Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 107
Default Media player in active X

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   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 449
Default Media player in active X

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   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 107
Default Media player in active X


"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   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 107
Default Media player in active X


"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   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 107
Default Media player in active X


"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   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 449
Default Media player in active X

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   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 107
Default Media player in active X


"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   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 449
Default Media player in active X

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   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 107
Default Media player in active X


"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   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 2,819
Default Media player in active X



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   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 107
Default Media player in active X


"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   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 292
Default Media player in active X

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   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 107
Default Media player in active X

Thanks Harold - shall study this closely


  #14   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 107
Default Media player in active X


"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   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 107
Default Media player in active X


"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   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 449
Default Media player in active X

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   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 107
Default Media player in active X

<sigh
thanks anyway


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controlling media player in VBA question teepee Excel Discussion (Misc queries) 3 April 14th 07 04:56 PM
Close Windows Media Player Cordell Excel Discussion (Misc queries) 1 January 30th 07 04:43 AM
Force asx to bring up Windows Media Player - How? chaser7016 Excel Discussion (Misc queries) 1 January 23rd 07 01:09 PM
Media player import to excel David Excel Discussion (Misc queries) 0 September 14th 06 01:39 AM
Media Player versus Windows Media Player teepee Excel Discussion (Misc queries) 1 October 14th 05 02:25 AM


All times are GMT +1. The time now is 01:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"