Activex Media Player

speakers_86

Registered User.
Local time
Yesterday, 19:27
Joined
May 17, 2007
Messages
1,919
I am thinking of designing an A2007 music db. I have it mapped out, and it looks doable. The thing I havent figured out yet, is how can I get the que list to know when the activex control is done playing the current song, so that it send a command to play the next song?

What should that command look like?

Also, if random is selected, how could I get the songs in the que list to play in a random order?

If I get this up and running properly, I plan on putting this one up in the samples! Im planning on working on this tonight. These are all problems I am anticipating. If I figure something out, I'll post again.
 
Heres something that semi-works. From Here.

Code:
Private Sub Name_Click()
Dim player As WindowsMediaPlayer
Dim Location As String

Location = Me.Location

Set player = [Forms]![WMP].WindowsMediaPlayer0.Object

DoEvents

player.currentPlaylist.appendItem player.newMedia(Location)

If player.currentPlaylist.Count = 1 Then
player.Controls.play
End If

End Sub



What I want it to do
On click of a song, it should start playing that song, then queue all the other songs.

What it is doing
I have to actually click every song that I want on the playlist. If I click every song in the form, it works great, but obviously thats not very good.
 
I dont really see how that helps.

Heres what I came up with. It gets caught up on the go to next record command. Im not sure why yet. If I can figure that out, then it should work. Only problem is that the code is very slow for large playlists. This probably wont work because of that.


Code:
Private Sub Name_Click()
Dim player As WindowsMediaPlayer
Dim Location As String

DoCmd.Close acForm, "wmp"
DoCmd.OpenForm "wmp"

Location = Me.Location

Set player = [Forms]![WMP].WindowsMediaPlayer0.Object

DoEvents

player.currentPlaylist.appendItem player.newMedia(Location)
player.Controls.play

If player.currentPlaylist.Count = 1 Then
player.Controls.play
End If

DoCmd.GoToRecord , , acFirst
Do Until CurrentRecord = acLast
DoCmd.GoToRecord , , acNext
Loop
End Sub
 
I dont really see how that helps.

I guess I should have been more explicit. Use the code from the page that you see when you click on the link that I provided. Copy it into a new Module and save it. Then revise your code to use the code instead of the ActiveX control, something like this:
Code:
[COLOR="Navy"]Private Sub[/COLOR] Name_Click()

    [COLOR="navy"]Dim[/COLOR] rs [COLOR="navy"]As[/COLOR] Recordset
    [COLOR="navy"]Dim[/COLOR] Location [COLOR="navy"]As String

    Set[/COLOR] rs = Me.RecordsetClone

    rs.MoveFirst

    [COLOR="navy"]Do While Not[/COLOR] rs.EOF
        fPlayStuff rs.Fields("Location"), 0
        rs.MoveNext
    [COLOR="navy"]Loop

    Set[/COLOR] rs = [COLOR="navy"]Nothing

End Sub[/COLOR]
 
So I looked at that code again, and it looks like it doesnt support mp3. I tried what you said. Set the code in the link as a public module. Here is what I tried in the on click event. (The link says I must pass the file location to the function)

Code:
Set rs = Me.location

This gave me a type mismatch error. Then I tried it like this.

Code:
Set rs = Me.RecordsetClone

Nothing happened. I dont know if it is relevant, but I am running Vista and A2007.
 
Does the Location field contain the full file path of the MP3?
 
I figured it out. Copy and paste the following code into your form's code module:
Code:
[COLOR="Navy"]Private Declare Function[/COLOR] mciSendStringA [COLOR="navy"]Lib[/COLOR] "winmm.dll" ( _
    [COLOR="navy"]ByVal[/COLOR] sCommand [COLOR="navy"]As String[/COLOR], _
    [COLOR="navy"]ByVal[/COLOR] sRet [COLOR="navy"]As String[/COLOR], _
    [COLOR="navy"]ByVal[/COLOR] lRet [COLOR="navy"]As Long[/COLOR], _
    [COLOR="navy"]ByVal[/COLOR] HwndBack [COLOR="navy"]As Long[/COLOR]) _
    [COLOR="navy"]As Long

Private Declare Sub[/COLOR] Sleep [COLOR="navy"]Lib[/COLOR] "kernel32" ( _
    [COLOR="navy"]ByVal[/COLOR] dwMilliseconds [COLOR="navy"]As Long[/COLOR])


[COLOR="navy"]Private Function[/COLOR] mciSendString([COLOR="navy"]ByVal[/COLOR] sCommand [COLOR="navy"]As String[/COLOR]) [COLOR="navy"]As String[/COLOR]

    [COLOR="navy"]Dim[/COLOR] retVar [COLOR="navy"]As Variant
    Dim[/COLOR] retStr [COLOR="navy"]As String[/COLOR]

    retStr = String(63, 0)
    retVar = mciSendStringA(sCommand, retStr, 63, 0)

    mciSendString = Left(retStr, InStr(1, retStr, Chr(0)) - 1)

[COLOR="navy"]End Function


Private Function[/COLOR] fPlayTrack([COLOR="navy"]ByVal[/COLOR] sFilePath [COLOR="navy"]As String[/COLOR])

    [COLOR="navy"]If[/COLOR] mciSendString("open """ _
        & sFilePath & """ alias myDev") <> "1" [COLOR="navy"]Then[/COLOR] _
        [COLOR="navy"]Exit Function[/COLOR]

    mciSendString "play myDev"

    [COLOR="navy"]Do While[/COLOR] mciSendString("status myDev mode") = "playing"
        Sleep 1000
    [COLOR="navy"]Loop[/COLOR]

    mciSendString "close myDev"

[COLOR="navy"]End Function


Private Sub[/COLOR] Name_Click()

    [COLOR="navy"]Dim[/COLOR] rs [COLOR="navy"]As[/COLOR] Recordset
    [COLOR="navy"]Dim[/COLOR] Location [COLOR="navy"]As String

    Set[/COLOR] rs = Me.RecordsetClone

    rs.MoveFirst

    [COLOR="navy"]Do While Not[/COLOR] rs.EOF
        fPlayTrack rs.Fields("Location")
        rs.MoveNext
    [COLOR="navy"]Loop

    Set[/COLOR] rs = [COLOR="navy"]Nothing

End Sub[/COLOR]
 
It works fine for me, and I tried it on a combination of WAV and MP3 files.

Could you be more specific as to how Access is crashing? Does it give you an error message? If so, what does the message say?
 
No error message. It just stops responding, and I get the working icon on my mouse.

Maybe I should have said so, but the music does play. But in the meantime, Access is going down. Also, the code doesnt play the song I clicked, it plays the first song in the list, regardless of what I clicked. And since I dont see the player anywhere, would I be able to write code so that I can click next?

Other than that, it appears that the code works. :)


I bet Access is locking for me because of the Loop in the code. Im sure if I sat through all the music, and the code came to an end, Access would un-freeze.
 
Last edited:
A couple of workarounds I would like your opinion on.

Code in the activex where something like on mp3 end, get next url? The place that this code looks for the url would have to be dynamic depending on where the original click was at. (Hope that makes sense)

Another possible method would be on click, start timer where the time equals the track length. At the end of the timer, activate another code that would send next url to player. What I dont like about this, is what if the music is paused? Maybe the timer could monitor the state of the activex player?




EDIT - I made a shorter list of songs, and as soon as the songs finished playing, Access un-froze.
 
Last edited:
I've attached a sample database (A2000 format, which can be easily converted to A2007) which uses the Callback handle to trigger a function which plays the next track. This should give you a workable model from which you can make the appropriate updates to your database. See if this works for you.
 

Attachments

Yes, this looks great. Ive searched google for this for hours, but came up with nothing.

I want to make a next button, any idea on the code for that? Id try to figure it out myself, but your code is above my head!

I'll work on my db tomorrow. Hopefully I can get something posted in the sample forums.
 
You can add a button to the form's header in my sample, and set the button's OnClick property to: =Form_CallBack()

This will start the next track in the sequence playing, but only if you have already started a track playing.
 
Hello Speaker,
Am very new on this forum. Am not a developer or code writer but i kindly request for your assistance.
I need to have a buttom and a windows media player on the same form where the button once clicked it plays a video on the player. All in the same form. Thank you very much. I will be very gratefull.
 

Users who are viewing this thread

Back
Top Bottom