Mike Scirocco
3/11/2012 8:59:00 AM
On 3/8/2012 2:31 PM, MikeD wrote:
>
>
> "Mike S" <mscir@yahoo.com> wrote in message
> news:jjb93i$oj$1@dont-email.me...
>> On 3/7/2012 5:35 PM, Larry Serflaten wrote:
>>> Mike S wrote:
>>>> Thanks for the ideas. I'll keep this for future use. Right now the code
>>>> approach is working:
>>>> Player.Open mp3file
>>>> Do Until Player.PlayState = mpStopped
>>>> DoEvents
>>>> Loop
>>>> Player.Stop
>>>> Set Player = Nothing
>>> Isn't that pegging the CPU meter? While the file plays, their
>>> CPU will be running at 100%. You might want to check that.
>>> Adding a Sleep command would greatly reduce the problem....
>>> LFS
>>
>> Larry,
>>
>> It's a countdown timer used for people playing board games, run on a
>> laptop, they have 50 minutes to complete their game, and when it gets
>> down to 10, 5 or 0 minutes a sound file plays. If I use sleep then the
>> countdown stops while the alarm is playing. I had hoped that using an
>> asynchronous player wouldn't cause this problem, although I may be
>> using it incorrectly.
>>
>
>
> And you're using MediaPlayer for THAT? The MCI control included with VB
> would be better, and it's a piece of crap IMO. <g> The biggest problem
> is that you're making your app dependent on something that, yeah, will
> *probably* exist, but by no means is guaranteed to exist. MediaPlayer
> CAN be removed from systems. But besides that, for just simple playback
> of an MP3, it's tremendous overkill and overhead.
>
> Give this a try. Add this code to a new project that just has one form.
> Be sure to fix line breaks and change the path and filename of what you
> want to play.
>
> -----BEGIN CODE
> Option Explicit
>
> Private Declare Function mciSendString Lib "winmm.dll" Alias
> "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString
> As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
>
> Private Declare Function GetShortPathName Lib "kernel32" Alias
> "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath
> As String, ByVal cchBuffer As Long) As Long
> Private Function GetShortFileName(sFile As String) As String
>
> Dim sBuffer As String
> Dim lBytes As Long
>
> sBuffer = String$(255, vbNullChar)
> Call GetShortPathName(sFile, sBuffer, Len(sBuffer))
>
> GetShortFileName = Left$(sBuffer, InStr(1, sBuffer, vbNullChar) - 1)
>
> End Function
>
> Private Sub Form_Click()
>
> Dim sFileName As String
>
> 'Hard coded for example purposes only
> sFileName = "H:\Media\Music\Rock\TED NUGENT - STRANGLEHOLD.MP3"
>
> 'Get the 8.3 form of this file because MCI has problems with
> 'long file names over a certain length, even if you embed
> 'quotation marks.
> sFileName = GetShortFileName(sFileName)
>
> Call mciSendString("play " & sFileName, vbNullString, 0&, 0&)
>
> End Sub
>
> Private Sub Form_Unload(Cancel As Integer)
>
> Call mciSendString("close all", vbNullString, 0&, 0&)
>
> End Sub
>
> -----END CODE
>
> If you want notification when playback stops, it's possible but a tad
> more involved because you need to use subclassing to receive a message
> from MCI (that's what the hwndCallback parameter is for in the
> mciSendString function). Also note that using the above MCI command, the
> MCI device is auto-opened and auto-closed. The only reason to explicitly
> close it in the Unload event is because it will keep playing in the IDE
> until you close VB. In a compiled app, this isn't an issue. But, it
> still shows how to close it if you need to for any other reason (like if
> you have a Stop Playback button).
>
> Mike
Thanks Mike, this will work great.
Mike S