Problem with midis and TMediaPlayer.

For some reason my way of volume control is not affecting midi music but works perfect for .wav, .mp2, .mp3, .wma and .ogg files....

Also usually when a track is finished in my application it automatically go's to the next one, it has always worked with anything except midi files, nothing happens when track ends....

Here's what I use for changing volume:

  // For Audio.
  MCI_SETAUDIO = $0873;
  MCI_DGV_SETAUDIO_ITEM = $00800000;
Procedure TFrmMain.SetVolume(Var TMP: TCMediaPlayer; Const Volume: SmallInt);
Begin    // Volume: 0 - 1000.
    p.dwCallback := 0;
    p.dwValue := Volume;
    p.dwOver := 0;
    p.lpstrAlgorithm := Nil;
    p.lpstrQuality := Nil;
    mciSendCommand(TMP.DeviceID, MCI_SETAUDIO,

And here's how I test to see if the track has ended:
If (MP.Mode = mpPlaying) And (MP.Position >= MP.TrackLength[1]) Then // If song is finished. Begin ... ... ... etc End;

Anyone have any idea why these issues only arise on playing midi files? I suppose it isn't all that important but I would like to fix these problems.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HiImGlenAuthor Commented:
Guess no one has a clue? Haven't been able to find help anywhere else either hm.
Perhaps this? *untested code*

  MCI_SET_VOLUME = $80000;

  MCI_SET_PARMS2 = record
    dwCallback: DWORD;
    dwTimeFormat: DWORD;
    dwSpeedFormat: DWORD;
    dwAudio: DWORD;
    dwLevel: DWORD;
    dwOver: DWORD;
    dwItem: DWORD;
    dwValue: DWORD;

... // code begins here

  parms: MCI_SET_PARMS2;
  FillChar(parms, SizeOf(MCI_SET_PARMS2), 0);
  parms.dwAudio := MCI_SET_AUDIO_ALL;
  parms.dwLevel := Volume;
  mciSendCommand(TMP.DeviceID, MCI_SET, MCI_WAIT or MCI_SET_AUDIO or MCI_SET_VOLUME, Longint(@parms));

Bear in mind, that this is some *very old code*... not sure if it works anymore. I've defined my own MCI_SET_PARMS because my old code couldn't compile anymore... seems like the current reference to MCI_SET_PARMS only has 3 items in the struct?


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The reason your code works is because it is *only* for Digital Audio.

If my above code doesn't work, your other option is to start using the mixer API.

Or alternatively, use DirectMusic :-)

CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

does the code work for you?
HiImGlenAuthor Commented:
To be honest I haven't been able to test it let alone even fire up Delphi lately, been swamped with study.

I felt it was unfair though to just leave it open.
oh... in that case you could've just left a comment here saying you will be back after your studies (in a couple of days/weeks perhaps)? :-)

otherwise if this question is closed, other experts might not come in to put in their comments.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.